Add JSON format support to signup flow for native API clients

The magic link verification endpoint now returns `requires_signup_completion`
to indicate whether the client needs to collect a name and complete signup.
The signup completion endpoint now supports JSON responses with the account ID.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Rosa Gutierrez
2026-01-28 13:24:32 +01:00
committed by Rosa Gutierrez
parent 231fa311c1
commit 614527e9c2
4 changed files with 67 additions and 6 deletions
@@ -80,7 +80,7 @@ class Sessions::MagicLinksControllerTest < ActionDispatch::IntegrationTest
assert MagicLink.exists?(expired_link.id), "Expired magic link should not be consumed"
end
test "create via JSON" do
test "create via JSON for sign in" do
identity = identities(:david)
magic_link = identity.send_magic_link
@@ -89,6 +89,20 @@ class Sessions::MagicLinksControllerTest < ActionDispatch::IntegrationTest
post session_magic_link_path(format: :json), params: { code: magic_link.code }
assert_response :success
assert @response.parsed_body["session_token"].present?
assert_equal false, @response.parsed_body["requires_signup_completion"]
end
end
test "create via JSON for sign up" do
identity = identities(:david)
magic_link = identity.send_magic_link(for: :sign_up)
untenanted do
post session_path(format: :json), params: { email_address: identity.email_address }
post session_magic_link_path(format: :json), params: { code: magic_link.code }
assert_response :success
assert @response.parsed_body["session_token"].present?
assert_equal true, @response.parsed_body["requires_signup_completion"]
end
end
@@ -55,4 +55,30 @@ class Signup::CompletionsControllerTest < ActionDispatch::IntegrationTest
assert_select "li", text: "Full name can't be blank"
end
end
test "create via JSON" do
untenanted do
post signup_completion_path(format: :json), params: {
signup: {
full_name: @signup.full_name
}
}
end
assert_response :created
assert @response.parsed_body["account_id"].present?
end
test "create via JSON with blank name" do
untenanted do
post signup_completion_path(format: :json), params: {
signup: {
full_name: ""
}
}
end
assert_response :unprocessable_entity
assert_includes @response.parsed_body["errors"], "Full name can't be blank"
end
end