Skip to content

Commit 79557af

Browse files
nshirleytoufali
authored andcommitted
feat(functional-tests): Use direct API to consume recovery codes
Because: - The particular test for getting new recovery codes after consuming enough shouldn't care how the codes are consumed - And, by consuming codes via the UI can be _very_ slow This Commit: - Replaces the manual UI integration to consume recovery codes with a direct API call to the appropriate route - And removes the temporary timeout increase Closes: #FXA-12497
1 parent edf2126 commit 79557af

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

packages/functional-tests/tests/settings/totpRecoveryCode.spec.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,34 @@ test.describe('severity-1 #smoke', () => {
157157
);
158158

159159
await settings.goto();
160+
160161
const { recoveryCodes } = await addTotp(credentials, settings, totp);
161-
await settings.signOut();
162+
const authClient = target.createAuthClient(2);
162163

163164
for (let i = 0; i < recoveryCodes.length - 3; i++) {
164-
await signinWithRecoveryCode(
165-
credentials,
166-
recoveryCodes[i],
167-
page,
168-
signin,
169-
signinRecoveryCode,
170-
signinTotpCode
171-
);
172-
await expect(settings.settingsHeading).toBeVisible();
173-
await settings.signOut();
165+
// We directly use the API here. Different environments will
166+
// use a different number of recovery codes. In Stage & Prod, this results
167+
// in having to consume through ~6 codes before the final code to trigger
168+
// the email. This can be very slow going through the UI, and since
169+
// we are only interested in the fact that the email is sent and has a valid link,
170+
// this lets us get there faster.
171+
try {
172+
await authClient.consumeRecoveryCode(
173+
credentials.sessionToken,
174+
recoveryCodes[i]
175+
);
176+
} catch (error) {
177+
// capture any errors so they're available in the trace.
178+
// eslint-disable-next-line no-console
179+
console.error(
180+
`Error consuming recovery code ${recoveryCodes[i]}:`,
181+
error
182+
);
183+
break;
184+
}
174185
}
175186

187+
await settings.signOut();
176188
await signinWithRecoveryCode(
177189
credentials,
178190
recoveryCodes[recoveryCodes.length - 1],

0 commit comments

Comments
 (0)