Skip to content

Commit

Permalink
test: update e2e test to work with an actual BE
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Nov 27, 2023
1 parent 405c419 commit 9040500
Show file tree
Hide file tree
Showing 23 changed files with 451 additions and 307 deletions.
3 changes: 2 additions & 1 deletion test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ export const SEND_VERIFY_EMAIL_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/u
export const VERIFY_EMAIL_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/user/email/verify`;
export const SIGN_IN_UP_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/signinup`;
export const CREATE_CODE_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/signinup/code`;
export const CREATE_DEVICE_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/signinup/code`;
export const CREATE_TOTP_DEVICE_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/totp/device`;
export const GET_AUTH_URL_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/authorisationurl`;
export const LOGIN_METHODS_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/loginmethods`;
export const MFA_INFO_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/mfa/info`;
export const ST_ROOT_SELECTOR = `#${ST_ROOT_ID}`;

export const SOMETHING_WENT_WRONG_ERROR = "Something went wrong. Please try again.";
33 changes: 9 additions & 24 deletions test/end-to-end/emailverification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ import {
waitForSTElement,
isGeneralErrorSupported,
setGeneralErrorToLocalStorage,
isAccountLinkingSupported,
backendBeforeEach,
} from "../helpers";

describe("SuperTokens Email Verification", function () {
let browser;
let page;
let consoleLogs;
let accountLinkingSupported;

before(async function () {
await backendBeforeEach();
Expand All @@ -69,7 +67,6 @@ describe("SuperTokens Email Verification", function () {
args: ["--no-sandbox", "--disable-setuid-sandbox"],
headless: true,
});
accountLinkingSupported = await isAccountLinkingSupported();

page = await browser.newPage();
await Promise.all([
Expand Down Expand Up @@ -255,13 +252,9 @@ describe("SuperTokens Email Verification", function () {
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
"ST_LOGS EMAIL_VERIFICATION OVERRIDE IS_EMAIL_VERIFIED",
"ST_LOGS EMAIL_VERIFICATION PRE_API_HOOKS IS_EMAIL_VERIFIED",
...(accountLinkingSupported
? []
: [
"ST_LOGS SESSION ON_HANDLE_EVENT ACCESS_TOKEN_PAYLOAD_UPDATED",
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
"ST_LOGS SESSION OVERRIDE GET_JWT_PAYLOAD_SECURELY",
]),
"ST_LOGS SESSION ON_HANDLE_EVENT ACCESS_TOKEN_PAYLOAD_UPDATED",
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
"ST_LOGS SESSION OVERRIDE GET_JWT_PAYLOAD_SECURELY",
"ST_LOGS EMAIL_VERIFICATION OVERRIDE SEND_VERIFICATION_EMAIL",
"ST_LOGS EMAIL_VERIFICATION PRE_API_HOOKS SEND_VERIFY_EMAIL",
"ST_LOGS EMAIL_VERIFICATION ON_HANDLE_EVENT VERIFY_EMAIL_SENT",
Expand Down Expand Up @@ -345,13 +338,9 @@ describe("SuperTokens Email Verification", function () {
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
"ST_LOGS EMAIL_VERIFICATION OVERRIDE IS_EMAIL_VERIFIED",
"ST_LOGS EMAIL_VERIFICATION PRE_API_HOOKS IS_EMAIL_VERIFIED",
...(accountLinkingSupported
? []
: [
"ST_LOGS SESSION ON_HANDLE_EVENT ACCESS_TOKEN_PAYLOAD_UPDATED",
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
"ST_LOGS SESSION OVERRIDE GET_JWT_PAYLOAD_SECURELY",
]),
"ST_LOGS SESSION ON_HANDLE_EVENT ACCESS_TOKEN_PAYLOAD_UPDATED",
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
"ST_LOGS SESSION OVERRIDE GET_JWT_PAYLOAD_SECURELY",
"ST_LOGS EMAIL_VERIFICATION OVERRIDE SEND_VERIFICATION_EMAIL",
"ST_LOGS EMAIL_VERIFICATION PRE_API_HOOKS SEND_VERIFY_EMAIL",
"ST_LOGS EMAIL_VERIFICATION ON_HANDLE_EVENT VERIFY_EMAIL_SENT",
Expand Down Expand Up @@ -495,13 +484,9 @@ describe("SuperTokens Email Verification", function () {
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
"ST_LOGS EMAIL_VERIFICATION OVERRIDE IS_EMAIL_VERIFIED",
"ST_LOGS EMAIL_VERIFICATION PRE_API_HOOKS IS_EMAIL_VERIFIED",
...(accountLinkingSupported
? []
: [
"ST_LOGS SESSION ON_HANDLE_EVENT ACCESS_TOKEN_PAYLOAD_UPDATED",
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
"ST_LOGS SESSION OVERRIDE GET_JWT_PAYLOAD_SECURELY",
]),
"ST_LOGS SESSION ON_HANDLE_EVENT ACCESS_TOKEN_PAYLOAD_UPDATED",
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
"ST_LOGS SESSION OVERRIDE GET_JWT_PAYLOAD_SECURELY",
"ST_LOGS EMAIL_VERIFICATION OVERRIDE SEND_VERIFICATION_EMAIL",
"ST_LOGS EMAIL_VERIFICATION PRE_API_HOOKS SEND_VERIFY_EMAIL",
"ST_LOGS EMAIL_VERIFICATION ON_HANDLE_EVENT VERIFY_EMAIL_SENT",
Expand Down
41 changes: 35 additions & 6 deletions test/end-to-end/mfa.firstFactors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import {
screenshotOnFailure,
backendBeforeEach,
waitFor,
submitForm,
} from "../helpers";
import fetch from "isomorphic-fetch";

import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL } from "../constants";
import { getTestPhoneNumber } from "../exampleTestHelpers";

/*
* Tests.
Expand Down Expand Up @@ -75,12 +77,14 @@ describe("SuperTokens MFA firstFactors support", function () {
page = await browser.newPage();
page.on("console", (consoleObj) => {
const log = consoleObj.text();
// console.log(log);
if (log.startsWith("ST_LOGS")) {
consoleLogs.push(log);
}
});
consoleLogs = await clearBrowserCookiesWithoutAffectingConsole(page, []);
await page.evaluate(() => {
window.localStorage.removeItem("supertokens-passwordless-loginAttemptInfo");
window.localStorage.setItem("enableAllRecipes", "true");
});
});
Expand Down Expand Up @@ -120,6 +124,34 @@ describe("SuperTokens MFA firstFactors support", function () {
await checkPasswordlessLoginUI(page, "EMAIL_OR_PHONE");
});

it("should clear pwless login attempt if it doesn't match the current first factors - contact method mismatch", async () => {
await page.evaluate(() => {
window.localStorage.setItem("firstFactors", "otp-phone");
});

await Promise.all([
page.goto(`${TEST_CLIENT_BASE_URL}/auth`),
page.waitForNavigation({ waitUntil: "networkidle0" }),
]);
const inp = await checkPasswordlessLoginUI(page, "PHONE");
await inp.type(getTestPhoneNumber());
await submitForm(page);
await waitForSTElement(page, "[data-supertokens~=input][name=userInputCode]");
await Promise.all([
page.goto(`${TEST_CLIENT_BASE_URL}/auth`),
page.waitForNavigation({ waitUntil: "networkidle0" }),
]);
await waitForSTElement(page, "[data-supertokens~=input][name=userInputCode]");
await page.evaluate(() => {
window.localStorage.setItem("firstFactors", "otp-email");
});
await Promise.all([
page.goto(`${TEST_CLIENT_BASE_URL}/auth`),
page.waitForNavigation({ waitUntil: "networkidle0" }),
]);
await checkPasswordlessLoginUI(page, "EMAIL");
});

it("should display tp-pwless w/ email for [thirdparty, otp-email]", async () => {
await page.evaluate(() => {
window.localStorage.setItem("firstFactors", "thirdparty, otp-email");
Expand Down Expand Up @@ -282,14 +314,11 @@ function getDynLoginMethods(firstFactors) {
async function checkPasswordlessLoginUI(page, contactMethod) {
switch (contactMethod) {
case "EMAIL_OR_PHONE":
await waitForSTElement(page, "[data-supertokens~=input][name=emailOrPhone]");
break;
return await waitForSTElement(page, "[data-supertokens~=input][name=emailOrPhone]");
case "EMAIL":
await waitForSTElement(page, "[data-supertokens~=input][name=email]");
break;
return await waitForSTElement(page, "[data-supertokens~=input][name=email]");
case "PHONE":
await waitForSTElement(page, "[data-supertokens~=input][name=phoneNumber_text]");
break;
return await waitForSTElement(page, "[data-supertokens~=input][name=phoneNumber_text]");
default:
throw new Error("Unknown contact method " + contactMethod);
}
Expand Down
Loading

0 comments on commit 9040500

Please sign in to comment.