Skip to content

Commit

Permalink
test: switch to mock provider (#866)
Browse files Browse the repository at this point in the history
* test: switch most thirdparty test to use mock provider

* test: fix test errors
  • Loading branch information
porcellus committed Nov 25, 2024
1 parent 7501c03 commit bb2252d
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 139 deletions.
84 changes: 43 additions & 41 deletions examples/for-tests-react-16/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,50 +272,52 @@ if (testContext.enableMFA) {
);
}

SuperTokens.init({
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
clientType: testContext.clientType,
appInfo: {
appName: "SuperTokens",
websiteDomain: getWebsiteDomain(),
apiDomain: getApiDomain(),
websiteBasePath,
},
languageTranslations: {
translations: {
en: {
AUTH_PAGE_FOOTER_TOS: "TOS",
},
hu: {
AUTH_PAGE_FOOTER_TOS: "ÁSZF",
if (!window.location.pathname.startsWith("/mockProvider")) {
SuperTokens.init({
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
clientType: testContext.clientType,
appInfo: {
appName: "SuperTokens",
websiteDomain: getWebsiteDomain(),
apiDomain: getApiDomain(),
websiteBasePath,
},
languageTranslations: {
translations: {
en: {
AUTH_PAGE_FOOTER_TOS: "TOS",
},
hu: {
AUTH_PAGE_FOOTER_TOS: "ÁSZF",
},
},
},
},
getRedirectionURL: (context) => {
if (context.action === "SUCCESS") {
let logId = {
emailpassword: "EMAIL_PASSWORD",
thirdparty: "THIRD_PARTY",
passwordless: "PASSWORDLESS",
}[context.recipeId];

console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL SUCCESS ${logId}`);
setIsNewUserToStorage(context.recipeId, context.isNewRecipeUser);
if (testContext.disableRedirectionAfterSuccessfulSignInUp) {
return null;
getRedirectionURL: (context) => {
if (context.action === "SUCCESS") {
let logId = {
emailpassword: "EMAIL_PASSWORD",
thirdparty: "THIRD_PARTY",
passwordless: "PASSWORDLESS",
}[context.recipeId];

console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL SUCCESS ${logId}`);
setIsNewUserToStorage(context.recipeId, context.isNewRecipeUser);
if (testContext.disableRedirectionAfterSuccessfulSignInUp) {
return null;
}
return context.redirectToPath || "/dashboard";
} else {
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
}
return context.redirectToPath || "/dashboard";
} else {
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
}
},
useShadowDom,
privacyPolicyLink: "https://supertokens.com/legal/privacy-policy",
termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions",
defaultToSignUp,
disableAuthRoute: testContext.disableDefaultUI,
recipeList,
});
},
useShadowDom,
privacyPolicyLink: "https://supertokens.com/legal/privacy-policy",
termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions",
defaultToSignUp,
disableAuthRoute: testContext.disableDefaultUI,
recipeList,
});
}

/* App */
function App() {
Expand Down
90 changes: 46 additions & 44 deletions examples/for-tests/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,53 +449,55 @@ if (testContext.enableMFA) {
);
}

SuperTokens.init({
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
clientType: testContext.clientType,
appInfo: {
appName: "SuperTokens",
websiteDomain: getWebsiteDomain(),
apiDomain: getApiDomain(),
websiteBasePath,
},
languageTranslations: {
translations: {
en: {
AUTH_PAGE_FOOTER_TOS: "TOS",
},
hu: {
AUTH_PAGE_FOOTER_TOS: "ÁSZF",
if (!window.location.pathname.startsWith("/mockProvider")) {
SuperTokens.init({
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
clientType: testContext.clientType,
appInfo: {
appName: "SuperTokens",
websiteDomain: getWebsiteDomain(),
apiDomain: getApiDomain(),
websiteBasePath,
},
languageTranslations: {
translations: {
en: {
AUTH_PAGE_FOOTER_TOS: "TOS",
},
hu: {
AUTH_PAGE_FOOTER_TOS: "ÁSZF",
},
},
},
},
getRedirectionURL: (context) => {
if (context.action === "SUCCESS") {
let logId = {
emailpassword: "EMAIL_PASSWORD",
thirdparty: "THIRD_PARTY",
passwordless: "PASSWORDLESS",
thirdpartypasswordless: "THIRDPARTYPASSWORDLESS",
thirdpartyemailpassword: "THIRD_PARTY_EMAIL_PASSWORD",
}[context.recipeId];

console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL SUCCESS ${logId}`);
setIsNewUserToStorage(context.recipeId, context.isNewRecipeUser);
if (testContext.disableRedirectionAfterSuccessfulSignInUp) {
return null;
getRedirectionURL: (context) => {
if (context.action === "SUCCESS") {
let logId = {
emailpassword: "EMAIL_PASSWORD",
thirdparty: "THIRD_PARTY",
passwordless: "PASSWORDLESS",
thirdpartypasswordless: "THIRDPARTYPASSWORDLESS",
thirdpartyemailpassword: "THIRD_PARTY_EMAIL_PASSWORD",
}[context.recipeId];

console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL SUCCESS ${logId}`);
setIsNewUserToStorage(context.recipeId, context.isNewRecipeUser);
if (testContext.disableRedirectionAfterSuccessfulSignInUp) {
return null;
}
console.log(JSON.stringify(context));
return context.redirectToPath || "/dashboard";
} else {
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
}
console.log(JSON.stringify(context));
return context.redirectToPath || "/dashboard";
} else {
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
}
},
useShadowDom,
privacyPolicyLink: "https://supertokens.com/legal/privacy-policy",
termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions",
defaultToSignUp,
disableAuthRoute: testContext.disableDefaultUI,
recipeList,
});
},
useShadowDom,
privacyPolicyLink: "https://supertokens.com/legal/privacy-policy",
termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions",
defaultToSignUp,
disableAuthRoute: testContext.disableDefaultUI,
recipeList,
});
}

/* App */
function App() {
Expand Down
8 changes: 4 additions & 4 deletions test/end-to-end/generalerror.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
assertProviders,
clickOnProviderButton,
clickOnProviderButtonWithoutWaiting,
loginWithAuth0,
loginWithMockProvider,
isGeneralErrorSupported,
setGeneralErrorToLocalStorage,
backendBeforeEach,
Expand Down Expand Up @@ -411,7 +411,7 @@ function getThirdPartyTests(rid, ridForStorage) {
await assertProviders(page);

let [_, response1] = await Promise.all([
clickOnProviderButtonWithoutWaiting(page, "Auth0"),
clickOnProviderButtonWithoutWaiting(page, "Mock Provider"),
page.waitForResponse(
(response) =>
response.url().includes(GET_AUTH_URL_API) &&
Expand All @@ -436,10 +436,10 @@ function getThirdPartyTests(rid, ridForStorage) {

await page.goto(`${TEST_CLIENT_BASE_URL}/auth`);
await assertProviders(page);
await clickOnProviderButton(page, "Auth0");
await clickOnProviderButton(page, "Mock Provider");

let [_, response1] = await Promise.all([
loginWithAuth0(page),
loginWithMockProvider(page),
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
]);

Expand Down
20 changes: 10 additions & 10 deletions test/end-to-end/getRedirectionURL.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
screenshotOnFailure,
assertProviders,
clickOnProviderButton,
loginWithAuth0,
loginWithMockProvider,
setPasswordlessFlowType,
waitForSTElement,
getPasswordlessDevice,
Expand Down Expand Up @@ -119,9 +119,9 @@ describe("getRedirectionURL Tests", function () {
page.waitForNavigation({ waitUntil: "networkidle0" }),
]);
await assertProviders(page);
await clickOnProviderButton(page, "Auth0");
await clickOnProviderButton(page, "Mock Provider");
await Promise.all([
loginWithAuth0(page),
loginWithMockProvider(page),
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
]);
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));
Expand Down Expand Up @@ -178,9 +178,9 @@ describe("getRedirectionURL Tests", function () {

it("Test that isNewRecipeUser works correctly when signing up with auth 0", async function () {
await assertProviders(page);
await clickOnProviderButton(page, "Auth0");
await clickOnProviderButton(page, "Mock Provider");
await Promise.all([
loginWithAuth0(page),
loginWithMockProvider(page),
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
]);
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));
Expand Down Expand Up @@ -368,9 +368,9 @@ describe("getRedirectionURL Tests", function () {
page.waitForNavigation({ waitUntil: "networkidle0" }),
]);
await assertProviders(page);
await clickOnProviderButton(page, "Auth0");
await clickOnProviderButton(page, "Mock Provider");
await Promise.all([
loginWithAuth0(page),
loginWithMockProvider(page),
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
]);
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));
Expand Down Expand Up @@ -668,10 +668,10 @@ describe("getRedirectionURL Tests", function () {
]);

await assertProviders(page);
await clickOnProviderButton(page, "Auth0");
await clickOnProviderButton(page, "Mock Provider");

await Promise.all([
loginWithAuth0(page),
loginWithMockProvider(page),
page.waitForResponse(
(response) => response.url() === SIGN_IN_UP_API && response.status() === 200
),
Expand All @@ -680,7 +680,7 @@ describe("getRedirectionURL Tests", function () {
const urlAfterSignUp = await page.url();
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));
assert.equal(newUserCheck, "thirdparty-true");
assert(urlAfterSignUp.includes("/auth/callback/auth0"));
assert(urlAfterSignUp.includes("/auth/callback/mock-provider"));
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/end-to-end/multitenancy.dynamic_login_methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ import {
loginWithGoogle,
clearBrowserCookiesWithoutAffectingConsole,
clickOnProviderButton,
loginWithAuth0,
loginWithMockProvider,
isMultitenancySupported,
isMultitenancyManagementEndpointsSupported,
setupTenant,
backendBeforeEach,
getTextByDataSupertokens,
loginWithAuth0,
} from "../helpers";
import {
TEST_CLIENT_BASE_URL,
Expand Down
Loading

0 comments on commit bb2252d

Please sign in to comment.