Skip to content

Commit

Permalink
test: switch most thirdparty test to use mock provider
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Nov 25, 2024
1 parent bfe9f61 commit 2ee063c
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 58 deletions.
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 @@ -403,7 +403,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 @@ -428,10 +428,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 @@ -114,9 +114,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 @@ -170,9 +170,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 @@ -354,9 +354,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 @@ -642,10 +642,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 @@ -654,7 +654,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,13 +34,14 @@ import {
loginWithGoogle,
clearBrowserCookiesWithoutAffectingConsole,
clickOnProviderButton,
loginWithAuth0,
loginWithMockProvider,
isMultitenancySupported,
isMultitenancyManagementEndpointsSupported,
setupTenant,
backendBeforeEach,
getTextByDataSupertokens,
setupBrowser,
loginWithAuth0,
} from "../helpers";
import {
TEST_CLIENT_BASE_URL,
Expand Down
64 changes: 34 additions & 30 deletions test/end-to-end/thirdparty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import {
assertNoSTComponents,
generateState,
clickOnProviderButton,
loginWithAuth0,
loginWithMockProvider,
getGeneralError,
waitFor,
screenshotOnFailure,
clickOnProviderButtonWithoutWaiting,
backendBeforeEach,
waitForUrl,
setupBrowser,
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 @@ -137,37 +138,37 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs,
]);
});

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 @@ -177,39 +178,39 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs,
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),
]);
await page.waitForSelector(".sessionInfo-user-id");
Expand Down Expand Up @@ -241,48 +242,51 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs,
]);
});

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),
]);
await waitForUrl(page, "/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),
]);
await waitForUrl(page, "/CasE/Case-SensItive1-PAth");
});

it("should work with custom getRedirectUrl", async function () {
await page.evaluate((TEST_CLIENT_BASE_URL) => {
localStorage.setItem("thirdPartyRedirectURL", `${TEST_CLIENT_BASE_URL}/auth/auth0-custom-redirect`);
localStorage.setItem(
"thirdPartyRedirectURL",
`${TEST_CLIENT_BASE_URL}/auth/mock-provider-custom-redirect`
);
}, TEST_CLIENT_BASE_URL);

await Promise.all([
page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=/hello`),
page.waitForNavigation({ waitUntil: "networkidle0" }),
]);
await assertProviders(page);
await clickOnProviderButton(page, "Auth0");
await loginWithAuth0(page);
await clickOnProviderButton(page, "Mock Provider");
await loginWithMockProvider(page);

await waitForUrl(page, "/auth/auth0-custom-redirect");
await waitForUrl(page, "/auth/mock-provider-custom-redirect");
});

// it("Successful signin with facebook", async function () {
Expand Down Expand Up @@ -354,8 +358,8 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs,
}
};
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, "TOS");
});
Expand Down Expand Up @@ -390,8 +394,8 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs,
};
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
14 changes: 7 additions & 7 deletions test/end-to-end/thirdpartyemailpassword.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
getLogoutButton,
signUp,
toggleSignInSignUp,
loginWithAuth0,
loginWithMockProvider,
getLoginWithRedirectToSignIn,
getLoginWithRedirectToSignUp,
getAuthPageHeaderText,
Expand Down Expand Up @@ -284,11 +284,11 @@ describe("SuperTokens Third Party Email Password", function () {
await waitForSTElement(page, "[data-supertokens~=generalError]", true);
});

it("Successful signin/up with auth0", async function () {
it("Successful signin/up", 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),
]);
await page.waitForSelector(".sessionInfo-user-id");
Expand Down Expand Up @@ -339,10 +339,10 @@ describe("SuperTokens Third Party Email Password", function () {
await Promise.all([await logoutButton.click(), page.waitForNavigation({ waitUntil: "networkidle0" })]);

await waitForUrl(page, "/auth");
// 2. Sign in with auth0 with same address.
await clickOnProviderButton(page, "Auth0");
// 2. Sign in with SSO with same address.
await clickOnProviderButton(page, "Mock Provider");
await Promise.all([
loginWithAuth0(page),
loginWithMockProvider(page),
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
]);
await waitForUrl(page, "/dashboard");
Expand Down
8 changes: 4 additions & 4 deletions test/end-to-end/thirdpartypasswordless.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
clickOnProviderButton,
getUserIdWithFetch,
getLogoutButton,
loginWithAuth0,
loginWithMockProvider,
setInputValues,
submitForm,
waitForSTElement,
Expand Down Expand Up @@ -139,10 +139,10 @@ describe("SuperTokens Third Party Passwordless", function () {

await waitForSTElement(page, `input[name=email]`);

// 3. Sign in with auth0 with same address.
await clickOnProviderButton(page, "Auth0");
// 3. Sign in with SSO with same address.
await clickOnProviderButton(page, "Mock Provider");
await Promise.all([
loginWithAuth0(page),
loginWithMockProvider(page),
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
]);
await Promise.all([page.waitForSelector(".sessionInfo-user-id"), page.waitForNetworkIdle()]);
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/thirdpartypasswordless.tp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
clickOnProviderButton,
getUserIdWithFetch,
getLogoutButton,
loginWithAuth0,
loginWithMockProvider,
setInputValues,
submitForm,
waitForSTElement,
Expand Down
3 changes: 2 additions & 1 deletion test/end-to-end/userContext.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import {
submitFormReturnRequestAndResponse,
assertProviders,
clickOnProviderButton,
loginWithAuth0,
loginWithMockProvider,
backendBeforeEach,
waitForUrl,
setupBrowser,
loginWithAuth0,
} from "../helpers";
import {
TEST_CLIENT_BASE_URL,
Expand Down
Loading

0 comments on commit 2ee063c

Please sign in to comment.