Skip to content

Commit

Permalink
Add more tests for recovery email sending flow
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30-st committed Feb 3, 2025
1 parent 03608e3 commit a8c67a6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion examples/for-tests/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,9 @@ function getWebauthnConfigs({ throwWebauthnError, webauthnErrorStatus }) {
};
}

return implementation.generateRecoverAccountToken(...args);
return {
status: "OK",
};
},
};
},
Expand Down
59 changes: 59 additions & 0 deletions test/end-to-end/webauthn.recovery_email.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,45 @@ describe("SuperTokens Webauthn Recovery Email", () => {
});

describe("Recovery Email Test", () => {
it("should show the success page when the email is sent", async () => {
const email = await getTestEmail();
await openRecoveryAccountPage(page, email, true);
await new Promise((res) => setTimeout(res, 1000));

// It should be successful and the user should see the success page
const emailSentTextContainer = await waitForSTElement(page, "[data-supertokens~='headerTitle']");
const emailSentText = await emailSentTextContainer.evaluate((el) => el.textContent);
assert.strictEqual(emailSentText, "Email sent");

assert.deepStrictEqual(consoleLogs, [
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
"ST_LOGS WEBAUTHN GET_REDIRECTION_URL SEND_RECOVERY_EMAIL",
"ST_LOGS WEBAUTHN OVERRIDE GENERATE RECOVER ACCOUNT TOKEN",
]);
});
it("change email button should take the user back to the recovery view", async () => {
const email = await getTestEmail();
await openRecoveryAccountPage(page, email, true);
await new Promise((res) => setTimeout(res, 1000));

// Find the change email button and click it
const changeEmailButton = await waitForSTElement(page, "[data-supertokens~='changeEmailBtn']");
await changeEmailButton.click();

assert.deepStrictEqual(consoleLogs, [
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
"ST_LOGS WEBAUTHN GET_REDIRECTION_URL SEND_RECOVERY_EMAIL",
"ST_LOGS WEBAUTHN OVERRIDE GENERATE RECOVER ACCOUNT TOKEN",
]);
const headerTextContainer = await waitForSTElement(
page,
"[data-supertokens~='passkeyRecoverAccountFormHeader']"
);
const headerText = await headerTextContainer.evaluate((el) => el.textContent);
assert.strictEqual(headerText, "Recover Account");
});
it("should show the recovery email page", async () => {
await openRecoveryAccountPage(page, null, false);

Expand Down Expand Up @@ -85,6 +124,10 @@ describe("SuperTokens Webauthn Recovery Email", () => {
);
const errorText = await errorTextContainer.evaluate((el) => el.textContent);
assert.strictEqual(errorText, "Account Recovery is not allowed, please contact support.");

await page.evaluateOnNewDocument(() => {
localStorage.setItem("webauthnErrorStatus", undefined);
});
});
it("should show general error if error is thrown", async () => {
// Set the error to be thrown
Expand All @@ -102,6 +145,22 @@ describe("SuperTokens Webauthn Recovery Email", () => {
errorText,
"Something went wrong while trying to send recover account token, please try again."
);

await page.evaluateOnNewDocument(() => {
localStorage.setItem("throwWebauthnError", undefined);
});
});
it("should take the user back when the back button is clicked", async () => {
await openRecoveryAccountPage(page, null, false);
const backButton = await waitForSTElement(page, "[data-supertokens~='backButton']");
await backButton.click();

assert.deepStrictEqual(consoleLogs, [
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
"ST_LOGS WEBAUTHN GET_REDIRECTION_URL SEND_RECOVERY_EMAIL",
"ST_LOGS SUPERTOKENS GET_REDIRECTION_URL TO_AUTH",
]);
});
});
});

0 comments on commit a8c67a6

Please sign in to comment.