Skip to content

Commit 28c149c

Browse files
committed
test: switch to mock provider (#866)
* test: switch most thirdparty test to use mock provider * test: fix test errors
1 parent 49878ad commit 28c149c

File tree

9 files changed

+106
-83
lines changed

9 files changed

+106
-83
lines changed

examples/for-tests-react-16/src/App.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -270,30 +270,32 @@ if (enabledRecipes.includes("thirdpartypasswordless")) {
270270
if (emailVerificationMode !== "OFF") {
271271
recipeList.push(getEmailVerificationConfigs(testContext));
272272
}
273-
SuperTokens.init({
274-
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
275-
clientType: testContext.clientType,
276-
appInfo: {
277-
appName: "SuperTokens",
278-
websiteDomain: getWebsiteDomain(),
279-
apiDomain: getApiDomain(),
280-
websiteBasePath,
281-
},
282-
languageTranslations: {
283-
translations: {
284-
en: {
285-
PWLESS_SIGN_IN_UP_FOOTER_TOS: "TOS",
286-
},
287-
hu: {
288-
PWLESS_SIGN_IN_UP_FOOTER_TOS: "ÁSZF",
273+
if (!window.location.pathname.startsWith("/mockProvider")) {
274+
SuperTokens.init({
275+
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
276+
clientType: testContext.clientType,
277+
appInfo: {
278+
appName: "SuperTokens",
279+
websiteDomain: getWebsiteDomain(),
280+
apiDomain: getApiDomain(),
281+
websiteBasePath,
282+
},
283+
languageTranslations: {
284+
translations: {
285+
en: {
286+
PWLESS_SIGN_IN_UP_FOOTER_TOS: "TOS",
287+
},
288+
hu: {
289+
PWLESS_SIGN_IN_UP_FOOTER_TOS: "ÁSZF",
290+
},
289291
},
290292
},
291-
},
292-
getRedirectionURL: (context) => {
293-
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
294-
},
295-
recipeList,
296-
});
293+
getRedirectionURL: (context) => {
294+
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
295+
},
296+
recipeList,
297+
});
298+
}
297299

298300
/* App */
299301
function App() {

examples/for-tests/src/App.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -277,30 +277,32 @@ if (emailVerificationMode !== "OFF") {
277277
recipeList.push(getEmailVerificationConfigs(testContext));
278278
}
279279

280-
SuperTokens.init({
281-
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
282-
clientType: testContext.clientType,
283-
appInfo: {
284-
appName: "SuperTokens",
285-
websiteDomain: getWebsiteDomain(),
286-
apiDomain: getApiDomain(),
287-
websiteBasePath,
288-
},
289-
languageTranslations: {
290-
translations: {
291-
en: {
292-
PWLESS_SIGN_IN_UP_FOOTER_TOS: "TOS",
293-
},
294-
hu: {
295-
PWLESS_SIGN_IN_UP_FOOTER_TOS: "ÁSZF",
280+
if (!window.location.pathname.startsWith("/mockProvider")) {
281+
SuperTokens.init({
282+
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
283+
clientType: testContext.clientType,
284+
appInfo: {
285+
appName: "SuperTokens",
286+
websiteDomain: getWebsiteDomain(),
287+
apiDomain: getApiDomain(),
288+
websiteBasePath,
289+
},
290+
languageTranslations: {
291+
translations: {
292+
en: {
293+
PWLESS_SIGN_IN_UP_FOOTER_TOS: "TOS",
294+
},
295+
hu: {
296+
PWLESS_SIGN_IN_UP_FOOTER_TOS: "ÁSZF",
297+
},
296298
},
297299
},
298-
},
299-
getRedirectionURL: (context) => {
300-
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
301-
},
302-
recipeList,
303-
});
300+
getRedirectionURL: (context) => {
301+
console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`);
302+
},
303+
recipeList,
304+
});
305+
}
304306

305307
/* App */
306308
function App() {

test/end-to-end/generalerror.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
assertProviders,
3838
clickOnProviderButton,
3939
clickOnProviderButtonWithoutWaiting,
40-
loginWithAuth0,
40+
loginWithMockProvider,
4141
isGeneralErrorSupported,
4242
setGeneralErrorToLocalStorage,
4343
} from "../helpers";
@@ -419,7 +419,7 @@ function getThirdPartyTests(rid, ridForStorage) {
419419
await assertProviders(page);
420420

421421
let [_, response1] = await Promise.all([
422-
clickOnProviderButtonWithoutWaiting(page, "Auth0"),
422+
clickOnProviderButtonWithoutWaiting(page, "Mock Provider"),
423423
page.waitForResponse(
424424
(response) =>
425425
response.url().includes(GET_AUTH_URL_API) &&
@@ -444,10 +444,10 @@ function getThirdPartyTests(rid, ridForStorage) {
444444

445445
await page.goto(`${TEST_CLIENT_BASE_URL}/auth`);
446446
await assertProviders(page);
447-
await clickOnProviderButton(page, "Auth0");
447+
await clickOnProviderButton(page, "Mock Provider");
448448

449449
let [_, response1] = await Promise.all([
450-
loginWithAuth0(page),
450+
loginWithMockProvider(page),
451451
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
452452
]);
453453

test/end-to-end/getRedirectionURL.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
screenshotOnFailure,
88
assertProviders,
99
clickOnProviderButton,
10-
loginWithAuth0,
10+
loginWithMockProvider,
1111
setPasswordlessFlowType,
1212
waitForSTElement,
1313
getPasswordlessDevice,
@@ -123,9 +123,9 @@ describe("getRedirectionURL Tests", function () {
123123
page.waitForNavigation({ waitUntil: "networkidle0" }),
124124
]);
125125
await assertProviders(page);
126-
await clickOnProviderButton(page, "Auth0");
126+
await clickOnProviderButton(page, "Mock Provider");
127127
await Promise.all([
128-
loginWithAuth0(page),
128+
loginWithMockProvider(page),
129129
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
130130
]);
131131
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));
@@ -184,9 +184,9 @@ describe("getRedirectionURL Tests", function () {
184184

185185
it("Test that isNewUser works correctly when signing up with auth 0", async function () {
186186
await assertProviders(page);
187-
await clickOnProviderButton(page, "Auth0");
187+
await clickOnProviderButton(page, "Mock Provider");
188188
await Promise.all([
189-
loginWithAuth0(page),
189+
loginWithMockProvider(page),
190190
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
191191
]);
192192
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));
@@ -381,9 +381,9 @@ describe("getRedirectionURL Tests", function () {
381381
page.waitForNavigation({ waitUntil: "networkidle0" }),
382382
]);
383383
await assertProviders(page);
384-
await clickOnProviderButton(page, "Auth0");
384+
await clickOnProviderButton(page, "Mock Provider");
385385
await Promise.all([
386-
loginWithAuth0(page),
386+
loginWithMockProvider(page),
387387
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
388388
]);
389389
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));

test/end-to-end/multitenancy.dynamic_login_methods.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ import {
3636
loginWithGoogle,
3737
clearBrowserCookiesWithoutAffectingConsole,
3838
clickOnProviderButton,
39-
loginWithAuth0,
39+
loginWithMockProvider,
4040
isMultitenancySupported,
4141
isAccountLinkingSupported,
42+
loginWithAuth0,
4243
} from "../helpers";
4344
import {
4445
TEST_CLIENT_BASE_URL,

test/end-to-end/thirdparty.test.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import {
2828
assertNoSTComponents,
2929
generateState,
3030
clickOnProviderButton,
31-
loginWithAuth0,
31+
loginWithMockProvider,
3232
getGeneralError,
3333
waitFor,
3434
screenshotOnFailure,
3535
clickOnProviderButtonWithoutWaiting,
36+
loginWithAuth0,
3637
} from "../helpers";
3738

3839
// Run the tests in a DOM environment.
@@ -141,30 +142,30 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa
141142
]);
142143
});
143144

144-
it("Successful sign in with Auth0 with query params kept", async function () {
145+
it("Successful sign in with SSO with query params kept", async function () {
145146
await Promise.all([
146147
page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=%2Fredirect-here%3Ffoo%3Dbar`),
147148
page.waitForNavigation({ waitUntil: "networkidle0" }),
148149
]);
149150
await assertProviders(page);
150-
await clickOnProviderButton(page, "Auth0");
151+
await clickOnProviderButton(page, "Mock Provider");
151152
await Promise.all([
152-
loginWithAuth0(page),
153+
loginWithMockProvider(page),
153154
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
154155
]);
155156
const { pathname, search } = await page.evaluate(() => window.location);
156157
assert.deepStrictEqual(pathname + search, "/redirect-here?foo=bar");
157158
});
158159

159-
it("Successful signin with Auth0 and email verification", async function () {
160+
it("Successful signin with SSO and email verification", async function () {
160161
await Promise.all([
161162
page.goto(`${TEST_CLIENT_BASE_URL}/auth?mode=REQUIRED`),
162163
page.waitForNavigation({ waitUntil: "networkidle0" }),
163164
]);
164165
await assertProviders(page);
165-
await clickOnProviderButton(page, "Auth0");
166+
await clickOnProviderButton(page, "Mock Provider");
166167
await Promise.all([
167-
loginWithAuth0(page),
168+
loginWithMockProvider(page),
168169
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
169170
]);
170171
const pathname = await page.evaluate(() => window.location.pathname);
@@ -197,30 +198,30 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa
197198
]);
198199
});
199200

200-
it("Successful signin with auth0 and redirectToPath", async function () {
201+
it("Successful signin with SSO and redirectToPath", async function () {
201202
await Promise.all([
202203
page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=/hello`),
203204
page.waitForNavigation({ waitUntil: "networkidle0" }),
204205
]);
205206
await assertProviders(page);
206-
await clickOnProviderButton(page, "Auth0");
207+
await clickOnProviderButton(page, "Mock Provider");
207208
await Promise.all([
208-
loginWithAuth0(page),
209+
loginWithMockProvider(page),
209210
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
210211
]);
211212
const pathname = await page.evaluate(() => window.location.pathname);
212213
assert.deepStrictEqual(pathname, "/hello");
213214
});
214215

215-
it("Successful signin with auth0 and redirectToPath case sensitive", async function () {
216+
it("Successful signin with SSO and redirectToPath case sensitive", async function () {
216217
await Promise.all([
217218
page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=%2FCasE%2FCase-SensItive1-PAth`),
218219
page.waitForNavigation({ waitUntil: "networkidle0" }),
219220
]);
220221
await assertProviders(page);
221-
await clickOnProviderButton(page, "Auth0");
222+
await clickOnProviderButton(page, "Mock Provider");
222223
await Promise.all([
223-
loginWithAuth0(page),
224+
loginWithMockProvider(page),
224225
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
225226
]);
226227
const pathname = await page.evaluate(() => window.location.pathname);
@@ -315,8 +316,8 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa
315316
}
316317
};
317318
page.on("request", requestHandler);
318-
await clickOnProviderButton(page, "Auth0");
319-
await loginWithAuth0(page);
319+
await clickOnProviderButton(page, "Mock Provider");
320+
await loginWithMockProvider(page);
320321
const error = await getGeneralError(page);
321322
assert.deepStrictEqual(error, "Terms of Service");
322323
});
@@ -351,8 +352,8 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa
351352
};
352353
page.on("request", requestHandler);
353354

354-
await clickOnProviderButton(page, "Auth0");
355-
await loginWithAuth0(page);
355+
await clickOnProviderButton(page, "Mock Provider");
356+
await loginWithMockProvider(page);
356357

357358
const error = await getGeneralError(page);
358359
assert.deepStrictEqual(error, "Test message!!!!");

test/end-to-end/thirdpartyemailpassword.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
getLogoutButton,
3232
signUp,
3333
toggleSignInSignUp,
34-
loginWithAuth0,
34+
loginWithMockProvider,
3535
getLoginWithRedirectToSignIn,
3636
getLoginWithRedirectToSignUp,
3737
getAuthPageHeaderText,
@@ -283,11 +283,11 @@ describe("SuperTokens Third Party Email Password", function () {
283283
await waitForSTElement(page, "[data-supertokens~=generalError]", true);
284284
});
285285

286-
it("Successful signin/up with auth0", async function () {
286+
it("Successful signin/up", async function () {
287287
await assertProviders(page);
288-
await clickOnProviderButton(page, "Auth0");
288+
await clickOnProviderButton(page, "Mock Provider");
289289
await Promise.all([
290-
loginWithAuth0(page),
290+
loginWithMockProvider(page),
291291
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
292292
]);
293293
const pathname = await page.evaluate(() => window.location.pathname);
@@ -340,9 +340,9 @@ describe("SuperTokens Third Party Email Password", function () {
340340
pathname = await page.evaluate(() => window.location.pathname);
341341
assert.deepStrictEqual(pathname, "/auth");
342342
// 2. Sign in with auth0 with same address.
343-
await clickOnProviderButton(page, "Auth0");
343+
await clickOnProviderButton(page, "Mock Provider");
344344
await Promise.all([
345-
loginWithAuth0(page),
345+
loginWithMockProvider(page),
346346
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
347347
]);
348348
pathname = await page.evaluate(() => window.location.pathname);

test/end-to-end/thirdpartypasswordless.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
clickOnProviderButton,
2727
getUserIdWithFetch,
2828
getLogoutButton,
29-
loginWithAuth0,
29+
loginWithMockProvider,
3030
setInputValues,
3131
submitForm,
3232
waitForSTElement,
@@ -146,10 +146,10 @@ describe("SuperTokens Third Party Passwordless", function () {
146146

147147
await waitForSTElement(page, `input[name=emailOrPhone]`);
148148

149-
// 3. Sign in with auth0 with same address.
150-
await clickOnProviderButton(page, "Auth0");
149+
// 3. Sign in with SSO with same address.
150+
await clickOnProviderButton(page, "Mock Provider");
151151
await Promise.all([
152-
loginWithAuth0(page),
152+
loginWithMockProvider(page),
153153
page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200),
154154
]);
155155
await Promise.all([page.waitForSelector(".sessionInfo-user-id"), page.waitForNetworkIdle()]);

test/helpers.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,23 @@ export async function loginWithFacebook(page) {
562562
await Promise.all([page.keyboard.press("Enter"), page.waitForNavigation({ waitUntil: "networkidle0" })]);
563563
}
564564

565+
export async function loginWithMockProvider(
566+
page,
567+
email = "[email protected]",
568+
userId = "123",
569+
isVerified = true
570+
) {
571+
const url = new URL(page.url());
572+
await Promise.all([
573+
page.goto(
574+
`${TEST_CLIENT_BASE_URL}/auth/callback/mock-provider?code=asdf&email=${encodeURIComponent(
575+
email
576+
)}&userId=${encodeURIComponent(userId)}&isVerified=${isVerified}&state=${url.searchParams.get("state")}`
577+
),
578+
page.waitForNavigation({ waitUntil: "networkidle0" }),
579+
]);
580+
}
581+
565582
export async function loginWithAuth0(page) {
566583
await page.focus("input[type=email]");
567584
await page.keyboard.type(process.env.AUTH0_EMAIL);

0 commit comments

Comments
 (0)