Skip to content

Commit ef0c66b

Browse files
Add test to test recovery of account using token
1 parent d81b685 commit ef0c66b

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
clearBrowserCookiesWithoutAffectingConsole,
88
getTestEmail,
99
waitForSTElement,
10+
submitForm,
1011
} from "../helpers";
1112
import { openRecoveryWithToken, signUpAndSendRecoveryEmail, getTokenFromEmail } from "./webauthn.helpers";
1213
import assert from "assert";
@@ -104,5 +105,64 @@ describe("SuperTokens Webauthn Recover Account", () => {
104105
"ST_LOGS WEBAUTHN PRE_API_HOOKS REGISTER_OPTIONS",
105106
]);
106107
});
108+
it("should recover the account successfully", async () => {
109+
// Get the token from the email
110+
const token = await getTokenFromEmail(email);
111+
assert.ok(token);
112+
assert.strictEqual(token.length, 128);
113+
114+
// Use the token to recover the account
115+
await openRecoveryWithToken(page, token);
116+
117+
// We should be in the recovery page now, click the continue button
118+
await submitForm(page);
119+
120+
await new Promise((res) => setTimeout(res, 2000));
121+
122+
const successContainer = await waitForSTElement(page, "[data-supertokens~='headerText']");
123+
const headerText = await successContainer.evaluate((el) => el.textContent);
124+
125+
// Assert the text contains "Account recovered successfully!"
126+
assert.deepStrictEqual(headerText, "Account recovered successfully!");
127+
128+
// Click on the continue button
129+
await submitForm(page);
130+
131+
await new Promise((res) => setTimeout(res, 2000));
132+
133+
assert.deepStrictEqual(consoleLogs, [
134+
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
135+
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
136+
"ST_LOGS WEBAUTHN OVERRIDE GET REGISTER OPTIONS WITH SIGN UP",
137+
"ST_LOGS WEBAUTHN OVERRIDE GET REGISTER OPTIONS",
138+
"ST_LOGS WEBAUTHN PRE_API_HOOKS REGISTER_OPTIONS",
139+
"ST_LOGS WEBAUTHN OVERRIDE REGISTER CREDENTIAL",
140+
"ST_LOGS WEBAUTHN OVERRIDE SIGN UP",
141+
"ST_LOGS WEBAUTHN PRE_API_HOOKS SIGN_UP",
142+
"ST_LOGS SESSION ON_HANDLE_EVENT SESSION_CREATED",
143+
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
144+
"ST_LOGS SUPERTOKENS GET_REDIRECTION_URL SUCCESS undefined",
145+
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
146+
"ST_LOGS SESSION OVERRIDE SIGN_OUT",
147+
"ST_LOGS SESSION PRE_API_HOOKS SIGN_OUT",
148+
"ST_LOGS SESSION ON_HANDLE_EVENT SIGN_OUT",
149+
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
150+
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
151+
"ST_LOGS WEBAUTHN GET_REDIRECTION_URL SEND_RECOVERY_EMAIL",
152+
"ST_LOGS WEBAUTHN OVERRIDE GENERATE RECOVER ACCOUNT TOKEN",
153+
"ST_LOGS WEBAUTHN PRE_API_HOOKS GENERATE_RECOVER_ACCOUNT_TOKEN",
154+
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
155+
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
156+
"ST_LOGS WEBAUTHN OVERRIDE GET REGISTER OPTIONS",
157+
"ST_LOGS WEBAUTHN OVERRIDE GET REGISTER OPTIONS",
158+
"ST_LOGS WEBAUTHN PRE_API_HOOKS REGISTER_OPTIONS",
159+
"ST_LOGS WEBAUTHN PRE_API_HOOKS REGISTER_OPTIONS",
160+
"ST_LOGS WEBAUTHN OVERRIDE REGISTER CREDENTIAL",
161+
"ST_LOGS WEBAUTHN PRE_API_HOOKS RECOVER_ACCOUNT",
162+
"ST_LOGS SUPERTOKENS GET_REDIRECTION_URL TO_AUTH",
163+
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
164+
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
165+
]);
166+
});
107167
});
108168
});

0 commit comments

Comments
 (0)