Skip to content

Commit e2e44bb

Browse files
test(mosaic): keep the sign-up a failed WhatsApp send leaves behind
The fake FAPI dropped the sign-up when the create request could not send the WhatsApp code. clerk_go 8bb8f66dde inserts the sign-up and attaches it to the client before it prepares the code (api/fapi/v1/sign_up/service.go:394-407), prepares it in a later transaction (:529, channel check in pkg/usersettings/clerk/strategies/phone_code.go:352-361), and returns the error with the client (http.go:73-77, wrapper.go:49). clerk-js applies meta.client from an error response (Client.ts getClientResourceFromPayload). The fake now keeps the unverified sign-up with the phone number and sends the client in the error. The test that expected no sign-up now checks that the user stays on the WhatsApp screen with the error and a retry sends the code. A new test goes back to the form and signs up over SMS with the stray sign-up present.
1 parent 224a7f3 commit e2e44bb

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

‎packages/mosaic/src/__tests__/feature/fake-fapi/sign-up.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,15 @@ export function signUpHandlers(
420420
if (applied instanceof HttpResponse) {
421421
return applied;
422422
}
423-
// FAPI creates the sign-up and sends the phone code in one transaction, so a failed send creates nothing.
424-
const prepared = body.get('strategy') === 'phone_code' ? prepare(applied, body) : applied;
425-
return prepared instanceof HttpResponse ? prepared : store(settle(issueProtectCheck(prepared)));
423+
const created = issueProtectCheck(applied);
424+
const prepared = body.get('strategy') === 'phone_code' ? prepare(created, body) : created;
425+
// FAPI attaches the sign-up to the client before it sends the code (clerk_go
426+
// api/fapi/v1/sign_up/service.go:394-407, send at :529), so a failed send keeps the sign-up.
427+
if (prepared instanceof HttpResponse) {
428+
store(settle(created));
429+
return clientError(prepared);
430+
}
431+
return store(settle(prepared));
426432
}),
427433
http.get(fapiUrl('/protect-check/challenge.js'), () =>
428434
HttpResponse.text(state.signUp.protectCheckScript ?? PROTECT_CHECK_SCRIPT, {

‎packages/mosaic/src/features/sign-up/__tests__/sign-up.feature.test.tsx‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,23 +1145,41 @@ export default (container, { setWidgetVisible }) => {
11451145
expect(fapi.signUp.preparations).toEqual(['phone_code:whatsapp']);
11461146
});
11471147

1148-
it('creates no sign-up when the WhatsApp code cannot be sent, so a retry creates the only one', async () => {
1148+
it('keeps the WhatsApp screen and its error after a failed send, then sends the code on retry', async () => {
11491149
const { fapi, user } = await renderSignUp({ environment: phoneEnvironment(), signUp: { whatsAppEnabled: false } });
11501150

11511151
await user.click(await screen.findByRole('button', { name: /WhatsApp/ }));
11521152
await user.type(await screen.findByRole('textbox', { name: 'WhatsApp phone number' }), '5555550123');
11531153
await user.click(continueButton());
11541154

11551155
expect(await screen.findByText("The 'whatsapp' channel is not available for this instance.")).toBeInTheDocument();
1156-
expect(fapi.client.sign_up).toBeNull();
1156+
expect(screen.getByRole('heading', { name: /with WhatsApp/ })).toBeInTheDocument();
1157+
expect(fapi.client.sign_up).toMatchObject({ id: 'sua_1', phone_number: '+15555550123' });
11571158
fapi.signUp.whatsAppEnabled = true;
11581159
await user.click(continueButton());
11591160

11601161
expect(await screen.findByRole('heading', { name: 'Verify your WhatsApp' })).toBeInTheDocument();
11611162
await codeSent();
1162-
expect(fapi.signUp.creations).toHaveLength(2);
11631163
expect(fapi.signUp.preparations).toEqual(['phone_code:whatsapp']);
1164-
expect(fapi.client.sign_up?.id).toBe('sua_2');
1164+
});
1165+
1166+
it('signs up over SMS from the form after a failed WhatsApp send left a sign-up', async () => {
1167+
const { fapi, user } = await renderSignUp({ environment: phoneEnvironment(), signUp: { whatsAppEnabled: false } });
1168+
1169+
await user.click(await screen.findByRole('button', { name: /WhatsApp/ }));
1170+
await user.type(await screen.findByRole('textbox', { name: 'WhatsApp phone number' }), '5555550123');
1171+
await user.click(continueButton());
1172+
await screen.findByText("The 'whatsapp' channel is not available for this instance.");
1173+
await user.click(screen.getByRole('button', { name: 'Use another method' }));
1174+
1175+
expect(await screen.findByRole('heading', { name: 'Create your account' })).toBeInTheDocument();
1176+
await user.clear(screen.getByRole('textbox', { name: 'Phone number' }));
1177+
await user.type(screen.getByRole('textbox', { name: 'Phone number' }), '5555550123');
1178+
await user.click(continueButton());
1179+
1180+
expect(await screen.findByRole('heading', { name: 'Verify your phone' })).toBeInTheDocument();
1181+
await codeSent();
1182+
expect(fapi.signUp.preparations).toEqual(['phone_code:sms']);
11651183
});
11661184

11671185
it('keeps Continue disabled on the WhatsApp phone screen until the phone number is filled', async () => {

0 commit comments

Comments
 (0)