Skip to content

Commit 59724d5

Browse files
Add recovery email related helpers and init test
1 parent 3b100bc commit 59724d5

File tree

4 files changed

+92
-9
lines changed

4 files changed

+92
-9
lines changed

examples/for-tests/src/App.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,11 +1154,6 @@ function setIsNewUserToStorage(recipeName, isNewRecipeUser) {
11541154

11551155
function getWebauthnConfigs({ throwWebauthnError, webauthnErrorStatus }) {
11561156
return Webauthn.init({
1157-
style: `
1158-
[data-supertokens~=container] {
1159-
font-family: cursive;
1160-
}
1161-
`,
11621157
override: {
11631158
functions: (implementation) => {
11641159
const log = logWithPrefix(`ST_LOGS WEBAUTHN OVERRIDE`);

lib/build/webauthnprebuiltui.js

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TEST_CLIENT_BASE_URL } from "../constants";
2-
import { toggleSignInSignUp, setInputValues, submitForm } from "../helpers";
2+
import { toggleSignInSignUp, setInputValues, submitForm, waitForSTElement } from "../helpers";
33

44
export async function tryWebauthnSignUp(page, email) {
55
await Promise.all([
@@ -24,3 +24,16 @@ export async function tryWebauthnSignIn(page) {
2424
await submitForm(page);
2525
await new Promise((res) => setTimeout(res, 1000));
2626
}
27+
28+
export async function openRecoveryAccountPage(page) {
29+
await Promise.all([
30+
page.goto(`${TEST_CLIENT_BASE_URL}/auth?authRecipe=webauthn`),
31+
page.waitForNavigation({ waitUntil: "networkidle0" }),
32+
]);
33+
34+
await toggleSignInSignUp(page);
35+
36+
const recoverAccountLink = await waitForSTElement(page, "[data-supertokens~='recoverAccountTrigger']");
37+
await recoverAccountLink.click();
38+
await new Promise((res) => setTimeout(res, 1000));
39+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import fetch from "isomorphic-fetch";
2+
import { TEST_SERVER_BASE_URL } from "../constants";
3+
import {
4+
backendBeforeEach,
5+
setupBrowser,
6+
screenshotOnFailure,
7+
clearBrowserCookiesWithoutAffectingConsole,
8+
toggleSignInSignUp,
9+
setEnabledRecipes,
10+
waitForSTElement,
11+
submitForm,
12+
} from "../helpers";
13+
import { tryWebauthnSignIn, openRecoveryAccountPage } from "./webauthn.helpers";
14+
import assert from "assert";
15+
16+
describe("SuperTokens Webauthn Recovery Email", () => {
17+
let browser;
18+
let page;
19+
let consoleLogs = [];
20+
21+
before(async function () {
22+
await backendBeforeEach();
23+
24+
await fetch(`${TEST_SERVER_BASE_URL}/startst`, {
25+
method: "POST",
26+
}).catch(console.error);
27+
28+
browser = await setupBrowser();
29+
page = await browser.newPage();
30+
page.on("console", (consoleObj) => {
31+
const log = consoleObj.text();
32+
if (log.startsWith("ST_LOGS")) {
33+
consoleLogs.push(log);
34+
}
35+
});
36+
});
37+
38+
after(async function () {
39+
await browser.close();
40+
await fetch(`${TEST_SERVER_BASE_URL}/after`, {
41+
method: "POST",
42+
}).catch(console.error);
43+
44+
await fetch(`${TEST_SERVER_BASE_URL}/stopst`, {
45+
method: "POST",
46+
}).catch(console.error);
47+
});
48+
49+
afterEach(function () {
50+
return screenshotOnFailure(this, browser);
51+
});
52+
53+
beforeEach(async function () {
54+
consoleLogs = [];
55+
consoleLogs = await clearBrowserCookiesWithoutAffectingConsole(page, consoleLogs);
56+
await toggleSignInSignUp(page);
57+
});
58+
59+
describe("Recovery Email Test", () => {
60+
it("should show the recovery email page", async () => {
61+
await openRecoveryAccountPage(page);
62+
63+
const headerTextContainer = await waitForSTElement(
64+
page,
65+
"[data-supertokens~='passkeyRecoverAccountFormHeader']"
66+
);
67+
const headerText = await headerTextContainer.evaluate((el) => el.textContent);
68+
assert.strictEqual(headerText, "Recover Account");
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+
]);
74+
});
75+
});
76+
});

0 commit comments

Comments
 (0)