Skip to content

Commit

Permalink
test: update tests to make them pass with the next node version
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Sep 20, 2023
1 parent 5818082 commit b2ec5e6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
33 changes: 24 additions & 9 deletions test/end-to-end/emailverification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
waitForSTElement,
isGeneralErrorSupported,
setGeneralErrorToLocalStorage,
isAccountLinkingSupported,
} from "../helpers";

// Run the tests in a DOM environment.
Expand All @@ -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`, {
Expand All @@ -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`),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions test/end-to-end/multitenancy.dynamic_login_methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
clickOnProviderButton,
loginWithAuth0,
isMultitenancySupported,
isAccountLinkingSupported,
} from "../helpers";
import {
TEST_CLIENT_BASE_URL,
Expand Down Expand Up @@ -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"]);
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion test/end-to-end/multitenancy.tenant_interactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
}),
Expand Down
6 changes: 6 additions & 0 deletions test/end-to-end/passwordless.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
isGeneralErrorSupported,
setGeneralErrorToLocalStorage,
getInputField,
isAccountLinkingSupported,
} from "../helpers";

// Run the tests in a DOM environment.
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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,
]);
Expand Down Expand Up @@ -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 () {
Expand Down
9 changes: 9 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b2ec5e6

Please sign in to comment.