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 41bbaae commit c5dabc7
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 97 deletions.
46 changes: 24 additions & 22 deletions examples/for-tests-react-16/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,30 +270,32 @@ if (enabledRecipes.includes("thirdpartypasswordless")) {
if (emailVerificationMode !== "OFF") {
recipeList.push(getEmailVerificationConfigs(testContext));
}
SuperTokens.init({
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
clientType: testContext.clientType,
appInfo: {
appName: "SuperTokens",
websiteDomain: getWebsiteDomain(),
apiDomain: getApiDomain(),
websiteBasePath,
},
languageTranslations: {
translations: {
en: {
PWLESS_SIGN_IN_UP_FOOTER_TOS: "TOS",
},
hu: {
PWLESS_SIGN_IN_UP_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: {
PWLESS_SIGN_IN_UP_FOOTER_TOS: "TOS",
},
hu: {
PWLESS_SIGN_IN_UP_FOOTER_TOS: "ÁSZF",
},
},
},
},
getRedirectionURL: (context) => {
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
},
recipeList,
});
getRedirectionURL: (context) => {
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
},
recipeList,
});
}

/* App */
function App() {
Expand Down
46 changes: 24 additions & 22 deletions examples/for-tests/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,30 +438,32 @@ if (emailVerificationMode !== "OFF") {
recipeList.push(getEmailVerificationConfigs(testContext));
}

SuperTokens.init({
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
clientType: testContext.clientType,
appInfo: {
appName: "SuperTokens",
websiteDomain: getWebsiteDomain(),
apiDomain: getApiDomain(),
websiteBasePath,
},
languageTranslations: {
translations: {
en: {
PWLESS_SIGN_IN_UP_FOOTER_TOS: "TOS",
},
hu: {
PWLESS_SIGN_IN_UP_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: {
PWLESS_SIGN_IN_UP_FOOTER_TOS: "TOS",
},
hu: {
PWLESS_SIGN_IN_UP_FOOTER_TOS: "ÁSZF",
},
},
},
},
getRedirectionURL: (context) => {
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
},
recipeList,
});
getRedirectionURL: (context) => {
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
},
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 @@ -412,7 +412,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 @@ -437,10 +437,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
53 changes: 27 additions & 26 deletions test/end-to-end/thirdparty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import {
assertNoSTComponents,
generateState,
clickOnProviderButton,
loginWithAuth0,
loginWithMockProvider,
getGeneralError,
waitFor,
screenshotOnFailure,
clickOnProviderButtonWithoutWaiting,
backendBeforeEach,
loginWithAuth0,
} from "../helpers";

import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL, SIGN_IN_UP_API, GET_AUTH_URL_API } from "../constants";
Expand Down Expand Up @@ -136,37 +137,37 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa
]);
});

it("Successful sign in with Auth0 with redirectToPath (w/ leading slash) keeping query params", async function () {
it("Successful sign in with redirectToPath (w/ leading slash) keeping query params", async function () {
await Promise.all([
page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=%2Fredirect-here%3Ffoo%3Dbar`),
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 { pathname, search } = await page.evaluate(() => window.location);
assert.deepStrictEqual(pathname + search, "/redirect-here?foo=bar");
});

it("Successful sign in with Auth0 with redirectToPath (w/o leading slash) keeping query params", async function () {
it("Successful sign in with SSO with redirectToPath (w/o leading slash) keeping query params", async function () {
await Promise.all([
page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=%3Ffoo%3Dbar`),
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 { pathname, search } = await page.evaluate(() => window.location);
assert.deepStrictEqual(pathname + search, "/?foo=bar");
});

it("Successful sign in with Auth0 with redirectToPath (query params + fragment)", async function () {
it("Successful sign in with SSO with redirectToPath (query params + fragment)", async function () {
await Promise.all([
page.goto(
`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=${encodeURIComponent(
Expand All @@ -176,39 +177,39 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa
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 { pathname, search, hash } = await page.evaluate(() => window.location);
assert.deepStrictEqual(pathname + search + hash, "/redirect-here?foo=bar#cell=4,1-6,2");
});

it("Successful sign in with Auth0 with redirectToPath (only fragment)", async function () {
it("Successful sign in with SSO with redirectToPath (only fragment)", async function () {
await Promise.all([
page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=${encodeURIComponent("#cell=4,1-6,2")}`),
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 { pathname, search, hash } = await page.evaluate(() => window.location);
assert.deepStrictEqual(pathname + search + hash, "/#cell=4,1-6,2");
});

it("Successful signin with Auth0 and email verification", async function () {
it("Successful signin with SSO and email verification", async function () {
await Promise.all([
page.goto(`${TEST_CLIENT_BASE_URL}/auth?mode=REQUIRED`),
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 pathname = await page.evaluate(() => window.location.pathname);
Expand Down Expand Up @@ -241,30 +242,30 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa
]);
});

it("Successful signin with auth0 and redirectToPath", async function () {
it("Successful signin with SSO and redirectToPath", async function () {
await Promise.all([
page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=/hello`),
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 pathname = await page.evaluate(() => window.location.pathname);
assert.deepStrictEqual(pathname, "/hello");
});

it("Successful signin with auth0 and redirectToPath case sensitive", async function () {
it("Successful signin with SSO and redirectToPath case sensitive", async function () {
await Promise.all([
page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=%2FCasE%2FCase-SensItive1-PAth`),
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 pathname = await page.evaluate(() => window.location.pathname);
Expand Down Expand Up @@ -359,8 +360,8 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa
}
};
page.on("request", requestHandler);
await clickOnProviderButton(page, "Auth0");
await loginWithAuth0(page);
await clickOnProviderButton(page, "Mock Provider");
await loginWithMockProvider(page);
const error = await getGeneralError(page);
assert.deepStrictEqual(error, "Terms of Service");
});
Expand Down Expand Up @@ -395,8 +396,8 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa
};
page.on("request", requestHandler);

await clickOnProviderButton(page, "Auth0");
await loginWithAuth0(page);
await clickOnProviderButton(page, "Mock Provider");
await loginWithMockProvider(page);

const error = await getGeneralError(page);
assert.deepStrictEqual(error, "Test message!!!!");
Expand Down
Loading

0 comments on commit c5dabc7

Please sign in to comment.