Skip to content

Commit a8c67a6

Browse files
Add more tests for recovery email sending flow
1 parent 03608e3 commit a8c67a6

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

examples/for-tests/src/App.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,9 @@ function getWebauthnConfigs({ throwWebauthnError, webauthnErrorStatus }) {
12711271
};
12721272
}
12731273

1274-
return implementation.generateRecoverAccountToken(...args);
1274+
return {
1275+
status: "OK",
1276+
};
12751277
},
12761278
};
12771279
},

test/end-to-end/webauthn.recovery_email.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,45 @@ describe("SuperTokens Webauthn Recovery Email", () => {
5656
});
5757

5858
describe("Recovery Email Test", () => {
59+
it("should show the success page when the email is sent", async () => {
60+
const email = await getTestEmail();
61+
await openRecoveryAccountPage(page, email, true);
62+
await new Promise((res) => setTimeout(res, 1000));
63+
64+
// It should be successful and the user should see the success page
65+
const emailSentTextContainer = await waitForSTElement(page, "[data-supertokens~='headerTitle']");
66+
const emailSentText = await emailSentTextContainer.evaluate((el) => el.textContent);
67+
assert.strictEqual(emailSentText, "Email sent");
68+
69+
assert.deepStrictEqual(consoleLogs, [
70+
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
71+
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
72+
"ST_LOGS WEBAUTHN GET_REDIRECTION_URL SEND_RECOVERY_EMAIL",
73+
"ST_LOGS WEBAUTHN OVERRIDE GENERATE RECOVER ACCOUNT TOKEN",
74+
]);
75+
});
76+
it("change email button should take the user back to the recovery view", async () => {
77+
const email = await getTestEmail();
78+
await openRecoveryAccountPage(page, email, true);
79+
await new Promise((res) => setTimeout(res, 1000));
80+
81+
// Find the change email button and click it
82+
const changeEmailButton = await waitForSTElement(page, "[data-supertokens~='changeEmailBtn']");
83+
await changeEmailButton.click();
84+
85+
assert.deepStrictEqual(consoleLogs, [
86+
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
87+
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
88+
"ST_LOGS WEBAUTHN GET_REDIRECTION_URL SEND_RECOVERY_EMAIL",
89+
"ST_LOGS WEBAUTHN OVERRIDE GENERATE RECOVER ACCOUNT TOKEN",
90+
]);
91+
const headerTextContainer = await waitForSTElement(
92+
page,
93+
"[data-supertokens~='passkeyRecoverAccountFormHeader']"
94+
);
95+
const headerText = await headerTextContainer.evaluate((el) => el.textContent);
96+
assert.strictEqual(headerText, "Recover Account");
97+
});
5998
it("should show the recovery email page", async () => {
6099
await openRecoveryAccountPage(page, null, false);
61100

@@ -85,6 +124,10 @@ describe("SuperTokens Webauthn Recovery Email", () => {
85124
);
86125
const errorText = await errorTextContainer.evaluate((el) => el.textContent);
87126
assert.strictEqual(errorText, "Account Recovery is not allowed, please contact support.");
127+
128+
await page.evaluateOnNewDocument(() => {
129+
localStorage.setItem("webauthnErrorStatus", undefined);
130+
});
88131
});
89132
it("should show general error if error is thrown", async () => {
90133
// Set the error to be thrown
@@ -102,6 +145,22 @@ describe("SuperTokens Webauthn Recovery Email", () => {
102145
errorText,
103146
"Something went wrong while trying to send recover account token, please try again."
104147
);
148+
149+
await page.evaluateOnNewDocument(() => {
150+
localStorage.setItem("throwWebauthnError", undefined);
151+
});
152+
});
153+
it("should take the user back when the back button is clicked", async () => {
154+
await openRecoveryAccountPage(page, null, false);
155+
const backButton = await waitForSTElement(page, "[data-supertokens~='backButton']");
156+
await backButton.click();
157+
158+
assert.deepStrictEqual(consoleLogs, [
159+
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
160+
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
161+
"ST_LOGS WEBAUTHN GET_REDIRECTION_URL SEND_RECOVERY_EMAIL",
162+
"ST_LOGS SUPERTOKENS GET_REDIRECTION_URL TO_AUTH",
163+
]);
105164
});
106165
});
107166
});

0 commit comments

Comments
 (0)