From b2ec5e67e4374d5faea842c65cf920a4199e9176 Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Wed, 20 Sep 2023 16:57:43 +0200 Subject: [PATCH] test: update tests to make them pass with the next node version --- test/end-to-end/emailverification.test.js | 33 ++++++++++++++----- ...multitenancy.dynamic_login_methods.test.js | 5 +++ .../multitenancy.tenant_interactions.test.js | 5 ++- test/end-to-end/passwordless.test.js | 6 ++++ test/helpers.js | 9 +++++ 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/test/end-to-end/emailverification.test.js b/test/end-to-end/emailverification.test.js index 551ad4781..2432a4317 100644 --- a/test/end-to-end/emailverification.test.js +++ b/test/end-to-end/emailverification.test.js @@ -52,6 +52,7 @@ import { waitForSTElement, isGeneralErrorSupported, setGeneralErrorToLocalStorage, + isAccountLinkingSupported, } from "../helpers"; // Run the tests in a DOM environment. @@ -61,6 +62,7 @@ describe("SuperTokens Email Verification", function () { let browser; let page; let consoleLogs; + let accountLinkingSupported; before(async function () { await fetch(`${TEST_SERVER_BASE_URL}/beforeeach`, { @@ -73,6 +75,7 @@ describe("SuperTokens Email Verification", function () { args: ["--no-sandbox", "--disable-setuid-sandbox"], headless: true, }); + accountLinkingSupported = await isAccountLinkingSupported(); page = await browser.newPage(); await Promise.all([ page.goto(`${TEST_CLIENT_BASE_URL}/auth?mode=REQUIRED`), @@ -257,9 +260,13 @@ 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", - "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", + ...(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 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", @@ -343,9 +350,13 @@ 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", - "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", + ...(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 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", @@ -489,9 +500,13 @@ 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", - "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", + ...(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 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", diff --git a/test/end-to-end/multitenancy.dynamic_login_methods.test.js b/test/end-to-end/multitenancy.dynamic_login_methods.test.js index ee811fe7d..433a99bac 100644 --- a/test/end-to-end/multitenancy.dynamic_login_methods.test.js +++ b/test/end-to-end/multitenancy.dynamic_login_methods.test.js @@ -38,6 +38,7 @@ import { clickOnProviderButton, loginWithAuth0, isMultitenancySupported, + isAccountLinkingSupported, } from "../helpers"; import { TEST_CLIENT_BASE_URL, @@ -134,6 +135,7 @@ describe("SuperTokens Multitenancy dynamic login methods", function () { "Continue with Google", "Continue with Facebook", "Continue with Auth0", + ...((await isAccountLinkingSupported()) ? ["Continue with Mock Provider"] : []), ]); const inputNames = await getInputNames(page); assert.deepStrictEqual(inputNames, ["email", "password"]); @@ -375,6 +377,7 @@ describe("SuperTokens Multitenancy dynamic login methods", function () { "Continue with Google", "Continue with Facebook", "Continue with Auth0", + ...((await isAccountLinkingSupported()) ? ["Continue with Mock Provider"] : []), ]); assert.strictEqual(await getProviderLogoCount(page), 3); }); @@ -957,6 +960,7 @@ export async function enableDynamicLoginMethods(page, mockLoginMethods, tenantId headers: new Headers([ ["content-type", "application/json"], ["rid", "multitenancy"], + ["cdi-version", "3.0"], ]), body: JSON.stringify({ tenantId, @@ -974,6 +978,7 @@ export async function enableDynamicLoginMethods(page, mockLoginMethods, tenantId headers: new Headers([ ["content-type", "application/json"], ["rid", "multitenancy"], + ["cdi-version", "3.0"], ]), body: JSON.stringify({ skipValidation: true, diff --git a/test/end-to-end/multitenancy.tenant_interactions.test.js b/test/end-to-end/multitenancy.tenant_interactions.test.js index e384e3e70..2105dae3f 100644 --- a/test/end-to-end/multitenancy.tenant_interactions.test.js +++ b/test/end-to-end/multitenancy.tenant_interactions.test.js @@ -1316,6 +1316,7 @@ async function setupTenant(appId, tenantId, mockLoginMethods) { headers: new Headers([ ["content-type", "application/json"], ["rid", "multitenancy"], + ["cdi-version", "3.0"], ]), body: JSON.stringify({ tenantId, @@ -1334,6 +1335,7 @@ async function addUserToTenant(appId, tenantId, userId) { headers: new Headers([ ["content-type", "application/json"], ["rid", "multitenancy"], + ["cdi-version", "3.0"], ]), body: JSON.stringify({ userId, @@ -1350,6 +1352,7 @@ async function removeUserFromTenant(appId, tenantId, userId) { headers: new Headers([ ["content-type", "application/json"], ["rid", "multitenancy"], + ["cdi-version", "3.0"], ]), body: JSON.stringify({ userId, @@ -1362,7 +1365,7 @@ async function removeUserFromTenant(appId, tenantId, userId) { async function removeTenant(appId, tenantId) { let coreResp = await fetch(`http://localhost:9000/appid-${appId}/recipe/multitenancy/tenant/remove`, { method: "POST", - headers: new Headers([["rid", "multitenancy"]]), + headers: new Headers([["rid", "multitenancy"][("cdi-version", "3.0")]]), body: JSON.stringify({ tenantId, }), diff --git a/test/end-to-end/passwordless.test.js b/test/end-to-end/passwordless.test.js index ef7f55efc..2882a83c8 100644 --- a/test/end-to-end/passwordless.test.js +++ b/test/end-to-end/passwordless.test.js @@ -37,6 +37,7 @@ import { isGeneralErrorSupported, setGeneralErrorToLocalStorage, getInputField, + isAccountLinkingSupported, } from "../helpers"; // Run the tests in a DOM environment. @@ -535,10 +536,12 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe }); function getTestCases(contactMethod, inputName, contactInfo) { + let accountLinkingSupported; describe(`UserInputCode`, function () { before(async function () { ({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe)); await setPasswordlessFlowType(contactMethod, "USER_INPUT_CODE"); + accountLinkingSupported = await isAccountLinkingSupported(); }); after(async function () { @@ -1039,6 +1042,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe before(async function () { ({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe)); await setPasswordlessFlowType(contactMethod, "MAGIC_LINK"); + accountLinkingSupported = await isAccountLinkingSupported(); }); after(async function () { @@ -1470,6 +1474,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe `ST_LOGS ${logId} OVERRIDE GET_LOGIN_ATTEMPT_INFO`, `ST_LOGS ${logId} OVERRIDE CONSUME_CODE`, `ST_LOGS ${logId} PRE_API_HOOKS PASSWORDLESS_CONSUME_CODE`, + ...(accountLinkingSupported ? [`ST_LOGS ${logId} ON_HANDLE_EVENT PASSWORDLESS_RESTART_FLOW`] : []), `ST_LOGS SUPERTOKENS GET_REDIRECTION_URL TO_AUTH`, ...signInUpPageLoadLogs, ]); @@ -1545,6 +1550,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe before(async function () { ({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe)); await setPasswordlessFlowType(contactMethod, "USER_INPUT_CODE_AND_MAGIC_LINK"); + accountLinkingSupported = await isAccountLinkingSupported(); }); after(async function () { diff --git a/test/helpers.js b/test/helpers.js index 925b5d4b2..9c9c6a3be 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -807,6 +807,15 @@ export async function isMultitenancySupported() { return true; } +export async function isAccountLinkingSupported() { + const features = await getFeatureFlags(); + if (!features.includes("accountlinking")) { + return false; + } + + return true; +} + /** * For example setGeneralErrorToLocalStorage("EMAIL_PASSWORD", "EMAIL_PASSWORD_SIGN_UP", page) to * set for signUp in email password