Skip to content

Commit 37eea51

Browse files
Add fixes for the e2e tests
1 parent 4031702 commit 37eea51

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

test/end-to-end/accountlinking.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ async function tryEmailPasswordSignUp(page, email) {
831831
await new Promise((res) => setTimeout(res, 250));
832832
}
833833

834-
async function tryPasswordlessSignInUp(page, email) {
834+
export async function tryPasswordlessSignInUp(page, email) {
835835
await page.evaluate(() => localStorage.removeItem("supertokens-passwordless-loginAttemptInfo"));
836836
await Promise.all([
837837
page.goto(`${TEST_CLIENT_BASE_URL}/auth/?authRecipe=passwordless`),

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ import {
2121
waitForUrl,
2222
changeEmail,
2323
getLatestURLWithToken,
24+
getUserIdWithFetch,
25+
submitFormUnsafe,
2426
} from "../helpers";
2527
import {
2628
openRecoveryAccountPage,
2729
tryWebauthnSignUp,
2830
getTokenFromEmail,
2931
openRecoveryWithToken,
32+
tryWebauthnSignIn,
3033
} from "./webauthn.helpers";
34+
import { tryPasswordlessSignInUp } from "./accountlinking.test";
3135
import assert from "assert";
3236

3337
/*
@@ -41,9 +45,6 @@ describe("SuperTokens WebAuthn Account Linking", function () {
4145
let browser;
4246
let page;
4347
let consoleLogs = [];
44-
let userId1;
45-
let userId2;
46-
const email = getTestEmail();
4748

4849
before(async function () {
4950
await backendBeforeEach();
@@ -61,6 +62,7 @@ describe("SuperTokens WebAuthn Account Linking", function () {
6162
"dashboard",
6263
"userroles",
6364
"multifactorauth",
65+
"accountlinking",
6466
]);
6567

6668
browser = await setupBrowser();
@@ -144,7 +146,7 @@ describe("SuperTokens WebAuthn Account Linking", function () {
144146
);
145147
});
146148

147-
it.only("should handle email updates correctly for user that signed up with webauthn", async () => {
149+
it("should handle email updates correctly for user that signed up with webauthn", async () => {
148150
await page.evaluate(() => window.localStorage.setItem("mode", "REQUIRED"));
149151
await setAccountLinkingConfig(false, false);
150152
const email = await getTestEmail();
@@ -170,7 +172,16 @@ describe("SuperTokens WebAuthn Account Linking", function () {
170172
await page.waitForTimeout(4000);
171173

172174
// Change the email for the webauthn user
173-
const recipeUserId = await page.evaluate(() => document.querySelector(".session-context-userId").textContent);
175+
await Promise.all([page.waitForSelector(".sessionInfo-user-id"), page.waitForNetworkIdle()]);
176+
const recipeUserId = await getUserIdWithFetch(page);
177+
assert.ok(recipeUserId);
178+
179+
// Find the div with classname logoutButton and click it using normal
180+
// puppeteer selector
181+
const logoutButton = await page.waitForSelector("div.logoutButton");
182+
await logoutButton.click();
183+
await new Promise((res) => setTimeout(res, 1000));
184+
174185
const newEmail = getTestEmail("new");
175186
const res = await changeEmail("webauthn", recipeUserId, newEmail, null);
176187

@@ -185,28 +196,18 @@ describe("SuperTokens WebAuthn Account Linking", function () {
185196
});
186197

187198
it("should allow same emails to be linked but requiring verification", async () => {
188-
await setAccountLinkingConfig(true, true, true);
189199
await page.evaluate(() => window.localStorage.setItem("mode", "REQUIRED"));
200+
await setAccountLinkingConfig(true, true, true);
190201
const email = await getTestEmail();
191202

192-
await Promise.all([
193-
page.goto(`${TEST_CLIENT_BASE_URL}/auth?authRecipe=passwordless`),
194-
page.waitForNavigation({ waitUntil: "networkidle0" }),
195-
]);
196-
197-
// Signup using the email
198-
await setInputValues(page, [{ name: "email", value: email }]);
199-
await submitForm(page);
203+
await tryPasswordlessSignInUp(page, email);
204+
await page.waitForTimeout(1000);
200205

201-
await waitForSTElement(page, "[data-supertokens~=input][name=userInputCode]");
206+
await Promise.all([page.waitForSelector(".sessionInfo-user-id"), page.waitForNetworkIdle()]);
207+
const userId1 = await getUserIdWithFetch(page);
208+
assert.ok(userId1);
202209

203-
const loginAttemptInfo = JSON.parse(
204-
await page.evaluate(() => localStorage.getItem("supertokens-passwordless-loginAttemptInfo"))
205-
);
206-
const device = await getPasswordlessDevice(loginAttemptInfo);
207-
await setInputValues(page, [{ name: "userInputCode", value: device.codes[0].userInputCode }]);
208-
await submitForm(page);
209-
await page.waitForTimeout(2000);
210+
await page.waitForTimeout(1000);
210211

211212
// Find the div with classname logoutButton and click it using normal
212213
// puppeteer selector
@@ -215,18 +216,20 @@ describe("SuperTokens WebAuthn Account Linking", function () {
215216
await new Promise((res) => setTimeout(res, 1000));
216217

217218
// Try to signup with the same email through webauthn now
218-
// await tryWebauthnSignUp(page, email);
219+
await tryWebauthnSignUp(page, email);
219220

220-
// // We should be in the confirmation page now.
221-
// await submitForm(page);
221+
// We should be in the confirmation page now.
222+
await submitForm(page);
223+
224+
await page.waitForTimeout(1000);
225+
await waitForSTElement(page, "[data-supertokens~='passkeyRecoverableErrorContainer']");
222226

223227
// Try to recover the webauthn account using the same email
224228
await openRecoveryAccountPage(page, email, true);
225229
await page.waitForTimeout(1000);
226230

227231
// Get the token from the email
228232
const token = await getTokenFromEmail(email);
229-
console.log(token);
230233
assert.ok(token);
231234

232235
// Use the token to recover the account

0 commit comments

Comments
 (0)