test: add tests for join mail confirmation
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Simon 2026-03-09 17:02:30 +01:00
parent ad6ef169ac
commit 3672ef0d03
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2
5 changed files with 177 additions and 0 deletions

View file

@ -0,0 +1,34 @@
defmodule Mv.Membership.JoinRequestSubmitEmailTest do
@moduledoc """
Unit tests for join request confirmation email on submit (Subtask 2).
Asserts that submit_join_request triggers sending exactly one confirmation email
(to the request email, with confirm link). Uses Swoosh.Adapters.Test; no integration.
Sender is wired in implementation; test fails until then (TDD).
"""
use Mv.DataCase, async: true
import Swoosh.TestAssertions
alias Mv.Membership
@valid_submit_attrs %{
email: "join#{System.unique_integer([:positive])}@example.com"
}
describe "submit_join_request/2 sends confirmation email" do
test "sends exactly one email to the request email with confirm link" do
token = "email-test-token-#{System.unique_integer([:positive])}"
attrs = Map.put(@valid_submit_attrs, :confirmation_token, token)
email = attrs.email
assert {:ok, _request} = Membership.submit_join_request(attrs, actor: nil)
assert_email_sent(fn email_sent ->
to_addresses = Enum.map(email_sent.to, &elem(&1, 1))
to_string(email) in to_addresses and
(email_sent.html_body =~ "/confirm_join/" or email_sent.text_body =~ "/confirm_join/")
end)
end
end
end