|
7 | 7 | clearBrowserCookiesWithoutAffectingConsole, |
8 | 8 | getTestEmail, |
9 | 9 | waitForSTElement, |
| 10 | + submitForm, |
10 | 11 | } from "../helpers"; |
11 | 12 | import { openRecoveryWithToken, signUpAndSendRecoveryEmail, getTokenFromEmail } from "./webauthn.helpers"; |
12 | 13 | import assert from "assert"; |
@@ -104,5 +105,64 @@ describe("SuperTokens Webauthn Recover Account", () => { |
104 | 105 | "ST_LOGS WEBAUTHN PRE_API_HOOKS REGISTER_OPTIONS", |
105 | 106 | ]); |
106 | 107 | }); |
| 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 | + }); |
107 | 167 | }); |
108 | 168 | }); |
0 commit comments