From 052d9a13cc6db51fbcee4fb37803a7665b43bd05 Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Tue, 14 May 2024 22:44:56 +0800 Subject: [PATCH] test: fixing combo tests --- examples/for-tests-react-16/src/App.js | 3 +- .../for-tests-react-16/src/testContext.js | 3 +- examples/for-tests/src/App.js | 3 +- examples/for-tests/src/testContext.js | 3 +- test/end-to-end/passwordless.test.js | 306 +++++++++--------- 5 files changed, 154 insertions(+), 164 deletions(-) diff --git a/examples/for-tests-react-16/src/App.js b/examples/for-tests-react-16/src/App.js index 2c39208c7..9f52949d9 100644 --- a/examples/for-tests-react-16/src/App.js +++ b/examples/for-tests-react-16/src/App.js @@ -771,7 +771,7 @@ function getThirdPartyPasswordlessConfigs({ staticProviderList, disableDefaultUI }); } -function getPasswordlessConfigs({ disableDefaultUI }) { +function getPasswordlessConfigs({ disableDefaultUI, defautToEmail }) { return Passwordless.init({ override: { functions: (implementation) => { @@ -830,6 +830,7 @@ function getPasswordlessConfigs({ disableDefaultUI }) { resendEmailOrSMSGapInSeconds: 2, disableDefaultUI, style: theme.style, + defautToEmail, }, linkClickedScreenFeature: { disableDefaultUI, diff --git a/examples/for-tests-react-16/src/testContext.js b/examples/for-tests-react-16/src/testContext.js index cbfe55cec..aacb7f3e1 100644 --- a/examples/for-tests-react-16/src/testContext.js +++ b/examples/for-tests-react-16/src/testContext.js @@ -20,6 +20,7 @@ export function getTestContext() { ? localStorage.getItem("firstFactors").split(", ") : undefined, enableMFA: localStorage.getItem("enableMFA") === "true", + defaultToEmail: localStorage.getItem("defaultToEmail") === "true", disableRedirectionAfterSuccessfulSignInUp: localStorage.getItem("disableRedirectionAfterSuccessfulSignInUp") === "true", }; @@ -31,7 +32,7 @@ export function getEnabledRecipes() { let enabledRecipes = []; - if (testContext.enableAllRecipes) { + if (testContext.enableAllRecipes || testContext.authRecipe === "all") { enabledRecipes = [ "emailpassword", "thirdparty", diff --git a/examples/for-tests/src/App.js b/examples/for-tests/src/App.js index d1e910fb4..cfb95bae7 100644 --- a/examples/for-tests/src/App.js +++ b/examples/for-tests/src/App.js @@ -903,7 +903,7 @@ function getEmailPasswordConfigs({ disableDefaultUI, formFieldType }) { }); } -function getPasswordlessConfigs({ disableDefaultUI }) { +function getPasswordlessConfigs({ disableDefaultUI, defaultToEmail }) { return Passwordless.init({ override: { functions: (implementation) => { @@ -968,6 +968,7 @@ function getPasswordlessConfigs({ disableDefaultUI }) { contactMethod: passwordlessContactMethodType, signInUpFeature: { defaultCountry: passwordlessDefaultCountry, + defaultToEmail, resendEmailOrSMSGapInSeconds: 2, disableDefaultUI, style: theme, diff --git a/examples/for-tests/src/testContext.js b/examples/for-tests/src/testContext.js index 04a3e6b6e..30d027280 100644 --- a/examples/for-tests/src/testContext.js +++ b/examples/for-tests/src/testContext.js @@ -21,6 +21,7 @@ export function getTestContext() { signUp: localStorage.getItem("SIGNUP_SETTING_TYPE"), }, enableMFA: localStorage.getItem("enableMFA") === "true", + defaultToEmail: localStorage.getItem("defaultToEmail") === "true", disableRedirectionAfterSuccessfulSignInUp: localStorage.getItem("disableRedirectionAfterSuccessfulSignInUp") === "true", }; @@ -32,7 +33,7 @@ export function getEnabledRecipes() { let enabledRecipes = []; - if (testContext.enableAllRecipes) { + if (testContext.enableAllRecipes || testContext.authRecipe === "all") { enabledRecipes = [ "emailpassword", "thirdparty", diff --git a/test/end-to-end/passwordless.test.js b/test/end-to-end/passwordless.test.js index 040c4038a..d754ed908 100644 --- a/test/end-to-end/passwordless.test.js +++ b/test/end-to-end/passwordless.test.js @@ -31,7 +31,6 @@ import { screenshotOnFailure, setPasswordlessFlowType, isReact16, - clickOnPasswordlessResendButton, isGeneralErrorSupported, setGeneralErrorToLocalStorage, getInputField, @@ -42,14 +41,19 @@ import { import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL, - TEST_APPLICATION_SERVER_BASE_URL, SOMETHING_WENT_WRONG_ERROR, } from "../constants"; +import { tryPasswordlessSignInUp } from "./mfa.helpers"; + +const examplePhoneNumber = "+36701231212"; +const exampleEmail = "test@example.com"; +const unregPhoneNumber = "+36701231000"; +const unregEmail = "test-unknown@example.com"; /* * Tests. */ -describe("SuperTokens Passwordless", function () { +describe.only("SuperTokens Passwordless", function () { getPasswordlessTestCases({ authRecipe: "passwordless", logId: "PASSWORDLESS", @@ -57,7 +61,33 @@ describe("SuperTokens Passwordless", function () { }); }); +describe.only("SuperTokens Passwordless w/ all recipes enabled", function () { + getPasswordlessTestCases({ + authRecipe: "all", + logId: "PASSWORDLESS", + generalErrorRecipeName: "PASSWORDLESS", + }); +}); + export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipeName }) { + +const contactInfoSubmitLogsWithoutEmailChecks = [ + `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, + `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, + `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, + `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, +]; +const contactInfoSubmitLogsWithEmailChecks = [ + "ST_LOGS EMAIL_PASSWORD OVERRIDE DOES_EMAIL_EXIST", + "ST_LOGS PASSWORDLESS OVERRIDE DOES_EMAIL_EXIST", + "ST_LOGS EMAIL_PASSWORD PRE_API_HOOKS EMAIL_EXISTS", + "ST_LOGS PASSWORDLESS PRE_API_HOOKS EMAIL_EXISTS", + `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, + `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, + `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, + `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, +]; + let browser; let page; let consoleLogs = []; @@ -83,10 +113,9 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE GET_USER_ID", ]; - const examplePhoneNumber = "+36701231212"; - const exampleEmail = "test@example.com"; afterEach(function () { + page.evaluate(() => localStorage.removeItem("defaultToEmail")); return screenshotOnFailure(this, browser); }); @@ -100,19 +129,24 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe describe("with EMAIL_OR_PHONE", () => { describe("using an email", () => { - getTestCases("EMAIL_OR_PHONE", "emailOrPhone", exampleEmail); + getTestCases("EMAIL_OR_PHONE", "email", exampleEmail); }); describe("using a phone number", () => { - getTestCases("EMAIL_OR_PHONE", "emailOrPhone", examplePhoneNumber); + getTestCases("EMAIL_OR_PHONE", "phoneNumber_text", examplePhoneNumber); }); describe("switching input type", () => { - const inputName = "emailOrPhone"; + let contactInfoSubmitLogs = authRecipe === "all" ? contactInfoSubmitLogsWithEmailChecks : contactInfoSubmitLogsWithoutEmailChecks; + const inputNameEmail = "email"; + const inputNamePhone = "phoneNumber_text"; const contactMethod = "EMAIL_OR_PHONE"; before(async function () { ({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe)); await setPasswordlessFlowType(contactMethod, "USER_INPUT_CODE"); + await page.evaluate( + () => localStorage.setItem("defaultToEmail", true), + ); }); after(async function () { @@ -139,11 +173,22 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe page.waitForNavigation({ waitUntil: "networkidle0" }), ]); - await setInputValues(page, [{ name: inputName, value: exampleEmail }]); + await setInputValues(page, [{ name: inputNameEmail, value: unregEmail }]); await submitForm(page); - const changeButton = await waitForSTElement(page, "[data-supertokens~=secondaryLinkWithLeftArrow]"); + + console.log("a") + if (authRecipe === "all") { + await waitForSTElement(page, "[data-supertokens~=input-password]"); + } else { + await waitForSTElement(page, "[data-supertokens~=input][name=userInputCode]"); + + const backButton = await waitForSTElement(page, "[data-supertokens~=secondaryLinkWithLeftArrow]"); + await backButton.click(); + } + + const changeButton = await waitForSTElement(page, "[data-supertokens~=contactMethodSwitcher]"); await changeButton.click(); - await setInputValues(page, [{ name: inputName, value: exampleEmail }]); + await setInputValues(page, [{ name: inputNamePhone, value: examplePhoneNumber }]); await submitForm(page); await waitForSTElement(page, "[data-supertokens~=input][name=userInputCode]"); @@ -161,19 +206,15 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE CLEAR_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -183,65 +224,33 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe ]); }); - it("Successful signin when clicking on resend code", async function () { - await Promise.all([ - page.goto(`${TEST_CLIENT_BASE_URL}/auth`), - page.waitForNavigation({ waitUntil: "networkidle0" }), - ]); - - await setInputValues(page, [{ name: inputName, value: exampleEmail }]); - await submitForm(page); - - await waitForSTElement(page, "[data-supertokens~=input][name=userInputCode]"); - - const ogLoginAttemptInfo = JSON.parse( - await page.evaluate(() => localStorage.getItem("supertokens-passwordless-loginAttemptInfo")) - ); - const ogDevice = await getPasswordlessDevice(ogLoginAttemptInfo); - assert.deepStrictEqual(ogDevice.codes.length, 1); - - // we wait for the resend button to show - await new Promise((r) => setTimeout(r, 2500)); - await clickOnPasswordlessResendButton(page); - - // we wait for API to complete - await new Promise((r) => setTimeout(r, 1000)); - const newLoginAttemptInfo = JSON.parse( - await page.evaluate(() => localStorage.getItem("supertokens-passwordless-loginAttemptInfo")) - ); - const newDevice = await getPasswordlessDevice(newLoginAttemptInfo); - assert.deepStrictEqual(newDevice.codes.length, 2); - assert.notDeepEqual(newDevice.codes[0].userInputCode, newDevice.codes[1].userInputCode); - - await setInputValues(page, [{ name: "userInputCode", value: newDevice.codes[1].userInputCode }]); - await submitForm(page); - - await page.waitForSelector(".sessionInfo-user-id"); - - assert.deepStrictEqual(consoleLogs, [ - "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", - "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", - ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, - `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, - `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, - `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, - `ST_LOGS ${logId} OVERRIDE RESEND_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_RESEND_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, - `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, - `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, - `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, - `ST_LOGS ${logId} OVERRIDE CONSUME_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CONSUME_CODE`, - ...signinSuccessLogsOTP, - ]); - }); + if (authRecipe === "all") { + it("switching input methods after password input shows up", async function () { + await Promise.all([ + page.goto(`${TEST_CLIENT_BASE_URL}/auth`), + page.waitForNavigation({ waitUntil: "networkidle0" }), + ]); + + await setInputValues(page, [{ name: inputNameEmail, value: unregEmail }]); + await submitForm(page); + await waitForSTElement(page, "[data-supertokens~=input-password]"); + const changeButton = await waitForSTElement(page, "[data-supertokens~=contactMethodSwitcher]"); + await changeButton.click(); + await setInputValues(page, [{ name: inputNamePhone, value: examplePhoneNumber }]); + await submitForm(page); + + await waitForSTElement(page, "[data-supertokens~=input][name=userInputCode]"); + + const loginAttemptInfo = JSON.parse( + await page.evaluate(() => localStorage.getItem("supertokens-passwordless-loginAttemptInfo")) + ); + const device = await getPasswordlessDevice(loginAttemptInfo); + await setInputValues(page, [{ name: "userInputCode", value: device.codes[0].userInputCode }]); + await submitForm(page); + + await page.waitForSelector(".sessionInfo-user-id"); + }) + } }); }); @@ -253,6 +262,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe }); function getTestCases(contactMethod, inputName, contactInfo) { + let contactInfoSubmitLogs = authRecipe === "all" && inputName == "email" ? contactInfoSubmitLogsWithEmailChecks : contactInfoSubmitLogsWithoutEmailChecks; let accountLinkingSupported; describe(`UserInputCode`, function () { before(async function () { @@ -274,6 +284,10 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe beforeEach(async function () { await clearBrowserCookiesWithoutAffectingConsole(page, consoleLogs); + await page.evaluate( + (inputName) => localStorage.setItem("defaultToEmail", inputName === "email"), + inputName + ); await page.evaluate(() => localStorage.removeItem("supertokens-passwordless-loginAttemptInfo")); await page.evaluate(() => localStorage.removeItem("SHOW_GENERAL_ERROR")); await page.evaluate(() => localStorage.removeItem("mode")); @@ -305,10 +319,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -342,10 +354,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -379,10 +388,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -418,10 +425,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -463,10 +468,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -570,9 +573,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe assert.strictEqual( await error.evaluate((e) => e.textContent), `${ - contactMethod === "EMAIL_OR_PHONE" - ? "Email or Phone number" - : contactMethod === "EMAIL" + inputName === "email" ? "Email" : "Phone number" } is invalid` @@ -594,9 +595,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe assert.strictEqual( await error.evaluate((e) => e.textContent), `${ - contactMethod === "EMAIL_OR_PHONE" - ? "Email or Phone number" - : contactMethod === "EMAIL" + inputName === "email" ? "Email" : "Phone number" } is invalid` @@ -639,10 +638,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -708,10 +705,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -839,6 +834,10 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe beforeEach(async function () { await clearBrowserCookiesWithoutAffectingConsole(page, consoleLogs); page.evaluate(() => localStorage.removeItem("supertokens-passwordless-loginAttemptInfo")); + await page.evaluate( + (inputName) => localStorage.setItem("defaultToEmail", inputName === "email"), + inputName + ); await page.evaluate(() => localStorage.removeItem("SHOW_GENERAL_ERROR")); await page.evaluate(() => localStorage.removeItem("mode")); @@ -867,10 +866,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -903,10 +899,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -946,10 +940,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -983,10 +975,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1027,10 +1017,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", @@ -1341,6 +1329,10 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe beforeEach(async function () { await clearBrowserCookiesWithoutAffectingConsole(page, consoleLogs); + await page.evaluate( + (inputName) => localStorage.setItem("defaultToEmail", inputName === "email"), + inputName + ); await page.evaluate(() => localStorage.removeItem("supertokens-passwordless-loginAttemptInfo")); await page.evaluate(() => localStorage.removeItem("SHOW_GENERAL_ERROR")); @@ -1369,10 +1361,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", @@ -1411,10 +1401,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", @@ -1453,10 +1441,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -1492,10 +1478,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -1545,10 +1529,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", @@ -1595,10 +1577,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, @@ -1669,10 +1649,8 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", ...signInUpPageLoadLogs, - `ST_LOGS ${logId} OVERRIDE CREATE_CODE`, - `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CREATE_CODE`, - `ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_CODE_SENT`, - `ST_LOGS ${logId} OVERRIDE SET_LOGIN_ATTEMPT_INFO`, + + ...contactInfoSubmitLogs, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", @@ -1910,6 +1888,14 @@ async function initBrowser(contactMethod, consoleLogs, authRecipe, { defaultCoun page.waitForNavigation({ waitUntil: "networkidle0" }), ]); + await new Promise(res => setTimeout(res, 500)); + + await tryPasswordlessSignInUp(page, exampleEmail, undefined, false); + await clearBrowserCookiesWithoutAffectingConsole(page, []); + + await tryPasswordlessSignInUp(page, examplePhoneNumber, undefined, true); + await clearBrowserCookiesWithoutAffectingConsole(page, []); + return { browser, page }; }