diff --git a/backend/src/app/email.clj b/backend/src/app/email.clj index ede5d54bb6..828f1c7531 100644 --- a/backend/src/app/email.clj +++ b/backend/src/app/email.clj @@ -475,7 +475,7 @@ (def ^:private schema:invite-to-organization [:map [:invited-by ::sm/text] - [:user-name [:maybe ::sm/text]] + [:user-name {:optional true} [:maybe ::sm/text]] [:token ::sm/text] [:organization schema:organization-data]]) @@ -497,7 +497,7 @@ (def ^:private schema:renewal-notice [:map - [:user-name [:maybe :string]] + [:user-name {:optional true} [:maybe :string]] [:renewal-date ::sm/text] [:estimated-amount ::sm/text] [:organizations [:vector schema:organization-data]]]) diff --git a/backend/test/backend_tests/email_sending_test.clj b/backend/test/backend_tests/email_sending_test.clj index 2eaff545c8..6d0b6f157b 100644 --- a/backend/test/backend_tests/email_sending_test.clj +++ b/backend/test/backend_tests/email_sending_test.clj @@ -300,6 +300,32 @@ ((::jobs/handler job-def) nil params) (t/is (= (emails/render factory recipe) @sent)))))) +;; `send-template` drops nil values before enqueuing, so a nil +;; `:user-name` (e.g. inviting an unregistered email) must still render. +(t/deftest send-template-renders-with-nil-user-name + (doseq [[template factory recipe] + [["invite-to-organization" emails/invite-to-organization + {:to "invitee@example.com" + :public-uri (cf/get :public-uri) + :invited-by "Owner User" + :user-name nil + :organization {:name "Acme Inc"} + :token "test-token"}] + ["renewal-notice" emails/renewal-notice + {:to "billing@example.com" + :public-uri (cf/get :public-uri) + :user-name nil + :renewal-date "2026-12-01" + :estimated-amount "$10.00" + :organizations [{:name "Acme"}]}]]] + (t/testing template + (let [sent (atom nil) + job-def (templated-job-def (fn [_ email] (reset! sent email))) + job-id (submit-templated job-def (assoc recipe ::emails/template template)) + params (jobs/decode-params job-def (:params (th/db-get :job {:id job-id})))] + ((::jobs/handler job-def) nil params) + (t/is (= (emails/render factory recipe) @sent)))))) + (t/deftest send-templated-mail-handler-rejects-unknown-template (let [job-def (templated-job-def (fn [_] nil)) code (try