Skip to content

Commit c43e03c

Browse files
Fix all tests and ensure they pass
1 parent 6ce9986 commit c43e03c

File tree

11 files changed

+10764
-33941
lines changed

11 files changed

+10764
-33941
lines changed

package-lock.json

Lines changed: 10303 additions & 33395 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/end-to-end/emailverification.test.js

Lines changed: 43 additions & 132 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
backendHook,
1818
setupCoreApp,
1919
setupST,
20+
loginWithAuth0,
2021
} from "../helpers";
2122

2223
import { TEST_CLIENT_BASE_URL, SIGN_IN_UP_API } from "../constants";
@@ -301,20 +302,11 @@ describe("getRedirectionURL Tests", function () {
301302
await page?.close();
302303
});
303304

304-
it("should not do any redirection after successful sign up", async function () {
305-
await Promise.all([
306-
page.goto(`${TEST_CLIENT_BASE_URL}/auth?authRecipe=emailpassword`),
307-
page.waitForNavigation({ waitUntil: "networkidle0" }),
308-
]);
309-
305+
it("Test that isNewUser is true when signing up", async function () {
310306
await toggleSignInSignUp(page);
311-
const urlBeforeSignUp = await page.url();
312307
await defaultSignUp(page);
313-
const urlAfterSignUp = await page.url();
314-
315308
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));
316309
assert.equal(newUserCheck, "emailpassword-true");
317-
assert.equal(urlBeforeSignUp, urlAfterSignUp);
318310
});
319311
});
320312

@@ -358,7 +350,7 @@ describe("getRedirectionURL Tests", function () {
358350
await page?.close();
359351
});
360352

361-
it("should not do any redirection after successful sign up", async function () {
353+
it("Test that isNewUser is passed correctly", async function () {
362354
await Promise.all([
363355
page.goto(`${TEST_CLIENT_BASE_URL}/auth`),
364356
page.waitForNavigation({ waitUntil: "networkidle0" }),
@@ -367,130 +359,16 @@ describe("getRedirectionURL Tests", function () {
367359
await submitForm(page);
368360
await waitForSTElement(page, "[data-supertokens~=input][name=userInputCode]");
369361

370-
const urlBeforeSignUp = await page.url();
371-
372362
const loginAttemptInfo = JSON.parse(
373363
await page.evaluate(() => localStorage.getItem("supertokens-passwordless-loginAttemptInfo"))
374364
);
375365
const device = await getPasswordlessDevice(loginAttemptInfo);
376366
await setInputValues(page, [{ name: "userInputCode", value: device.codes[0].userInputCode }]);
377367
await submitForm(page);
378-
// wait until network idle to ensure that the page has not been redirected
379-
await page.waitForNetworkIdle();
368+
await page.waitForSelector(".sessionInfo-user-id");
380369

381-
const urlAfterSignUp = await page.url();
382370
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));
383371
assert.equal(newUserCheck, "passwordless-true");
384-
assert.equal(urlBeforeSignUp, urlAfterSignUp);
385-
});
386-
});
387-
388-
describe("ThirdPartyPasswordless recipe: Magic Link", function () {
389-
const exampleEmail = "[email protected]";
390-
391-
before(async function () {
392-
let _isThirdPartyPasswordlessSupported = await isThirdPartyPasswordlessSupported();
393-
if (!_isThirdPartyPasswordlessSupported) {
394-
this.skip();
395-
}
396-
397-
const coreUrl = await setupCoreApp({
398-
coreConfig: {
399-
passwordless_code_lifetime: 4000,
400-
passwordless_max_code_input_attempts: 3,
401-
},
402-
});
403-
await setupST({
404-
coreUrl,
405-
passwordlessFlowType: "MAGIC_LINK",
406-
passwordlessContactMethod: "EMAIL",
407-
});
408-
409-
page = await browser.newPage();
410-
await clearBrowserCookiesWithoutAffectingConsole(page, []);
411-
// We need to set the localStorage value before the page loads to ensure ST initialises with the correct value
412-
await page.evaluateOnNewDocument(() => {
413-
localStorage.setItem("disableRedirectionAfterSuccessfulSignInUp", "true");
414-
localStorage.removeItem("isNewUserCheck");
415-
});
416-
417-
await Promise.all([
418-
page.goto(
419-
`${TEST_CLIENT_BASE_URL}/auth?authRecipe=thirdpartypasswordless&passwordlessContactMethodType=EMAIL`
420-
),
421-
page.waitForNavigation({ waitUntil: "networkidle0" }),
422-
]);
423-
});
424-
425-
after(async function () {
426-
await page?.close();
427-
});
428-
429-
it("should not do any redirection after successful sign up", async function () {
430-
await Promise.all([
431-
page.goto(`${TEST_CLIENT_BASE_URL}/auth`),
432-
page.waitForNavigation({ waitUntil: "networkidle0" }),
433-
]);
434-
await setInputValues(page, [{ name: "email", value: exampleEmail }]);
435-
await submitForm(page);
436-
await waitForSTElement(page, "[data-supertokens~=sendCodeIcon]");
437-
438-
const loginAttemptInfo = JSON.parse(
439-
await page.evaluate(() => localStorage.getItem("supertokens-passwordless-loginAttemptInfo"))
440-
);
441-
const device = await getPasswordlessDevice(loginAttemptInfo);
442-
443-
const magicLink = device.codes[0].urlWithLinkCode;
444-
445-
await page.goto(magicLink);
446-
await page.waitForNetworkIdle();
447-
448-
const urlAfterSignUp = await page.url();
449-
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));
450-
assert.equal(newUserCheck, "thirdpartypasswordless-true");
451-
assert.equal(magicLink, urlAfterSignUp);
452-
});
453-
});
454-
455-
describe("ThirdParty Recipe", function () {
456-
before(async function () {
457-
const coreUrl = await setupCoreApp();
458-
await setupST({ coreUrl });
459-
460-
page = await browser.newPage();
461-
// We need to set the localStorage value before the page loads to ensure ST initialises with the correct value
462-
await page.evaluateOnNewDocument(() => {
463-
localStorage.setItem("disableRedirectionAfterSuccessfulSignInUp", "true");
464-
localStorage.removeItem("isNewUserCheck");
465-
});
466-
467-
await clearBrowserCookiesWithoutAffectingConsole(page, []);
468-
});
469-
470-
after(async function () {
471-
await page?.close();
472-
});
473-
474-
it("should not do any redirection after successful sign up", async function () {
475-
await Promise.all([
476-
page.goto(`${TEST_CLIENT_BASE_URL}/auth?authRecipe=thirdparty`),
477-
page.waitForNavigation({ waitUntil: "networkidle0" }),
478-
]);
479-
480-
await assertProviders(page);
481-
await clickOnProviderButton(page, "Mock Provider");
482-
483-
await Promise.all([
484-
loginWithMockProvider(page),
485-
page.waitForResponse(
486-
(response) => response.url() === SIGN_IN_UP_API && response.status() === 200
487-
),
488-
]);
489-
490-
const urlAfterSignUp = await page.url();
491-
const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck"));
492-
assert.equal(newUserCheck, "thirdparty-true");
493-
assert(urlAfterSignUp.includes("/auth/callback/mock-provider"));
494372
});
495373
});
496374
});

test/end-to-end/passwordless.test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ import {
3131
isGeneralErrorSupported,
3232
setGeneralErrorToLocalStorage,
3333
getInputField,
34-
isAccountLinkingSupported,
3534
waitForUrl,
3635
setupBrowser,
3736
clickForgotPasswordLink,
3837
backendHook,
3938
setupCoreApp,
4039
setupST,
4140
clickOnPasswordlessResendButton,
41+
waitForText,
4242
} from "../helpers";
4343

4444
import { TEST_CLIENT_BASE_URL, SOMETHING_WENT_WRONG_ERROR } from "../constants";
@@ -537,7 +537,6 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
537537
});
538538

539539
function getTestCases(contactMethod, inputName, contactInfo) {
540-
let accountLinkingSupported;
541540
let coreUrl;
542541
const appId = randomUUID();
543542
const coreConfig = {
@@ -563,7 +562,6 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
563562
passwordlessContactMethod: contactMethod,
564563
});
565564
({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe, undefined));
566-
accountLinkingSupported = await isAccountLinkingSupported();
567565
});
568566

569567
after(async function () {
@@ -572,6 +570,7 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
572570
});
573571

574572
beforeEach(async function () {
573+
await backendHook("beforeEach");
575574
await clearBrowserCookiesWithoutAffectingConsole(page, consoleLogs);
576575
await page.evaluate(() => localStorage.removeItem("supertokens-passwordless-loginAttemptInfo"));
577576
await page.evaluate(() => localStorage.removeItem("SHOW_GENERAL_ERROR"));
@@ -1040,7 +1039,6 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
10401039
before(async function () {
10411040
await backendHook("before");
10421041
({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe, undefined));
1043-
accountLinkingSupported = await isAccountLinkingSupported();
10441042
await setupST({
10451043
coreUrl,
10461044
passwordlessFlowType: "MAGIC_LINK",
@@ -1546,7 +1544,6 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
15461544
passwordlessContactMethod: contactMethod,
15471545
});
15481546
({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe, undefined));
1549-
accountLinkingSupported = await isAccountLinkingSupported();
15501547
});
15511548

15521549
after(async function () {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ import {
3030
screenshotOnFailure,
3131
clickOnProviderButtonWithoutWaiting,
3232
waitForUrl,
33-
loginWithAuth0,
3433
backendHook,
3534
setupCoreApp,
3635
setupST,
3736
setupBrowser,
37+
assertNoSTComponents,
3838
} from "../helpers";
3939
import { TEST_CLIENT_BASE_URL, SIGN_IN_UP_API, GET_AUTH_URL_API } from "../constants";
4040

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -348,45 +348,6 @@ describe("SuperTokens Third Party Email Password", function () {
348348
// 3. Compare userIds
349349
assert.notDeepStrictEqual(thirdPartyUserId, emailPasswordUserId);
350350
});
351-
352-
it("clientType should be included when getting the auth url", async function () {
353-
await page.evaluate(() => {
354-
localStorage.setItem("clientType", `test-web`);
355-
});
356-
357-
await Promise.all([
358-
page.goto(`${TEST_CLIENT_BASE_URL}/auth`),
359-
page.waitForNavigation({ waitUntil: "networkidle0" }),
360-
]);
361-
362-
const res = await Promise.all([
363-
page.waitForRequest((request) => request.url().startsWith(GET_AUTH_URL_API)),
364-
clickOnProviderButtonWithoutWaiting(page, "Auth0"),
365-
]);
366-
367-
const url = new URL(res[0].url());
368-
assert.strictEqual(url.searchParams.get("clientType"), "test-web");
369-
});
370-
371-
it("should handle no providers enabled on the backend", async function () {
372-
if (!(await getFeatureFlags()).includes("recipeConfig")) {
373-
this.skip();
374-
}
375-
await assertProviders(page);
376-
await setupST({
377-
...appConfig,
378-
enabledRecipes: ["thirdpartyemailpassword"],
379-
enabledProviders: [],
380-
});
381-
382-
await Promise.all([
383-
page.waitForResponse(
384-
(response) => response.url().startsWith(GET_AUTH_URL_API) && response.status() === 400
385-
),
386-
clickOnProviderButtonWithoutWaiting(page, "Auth0"),
387-
]);
388-
assert.strictEqual(await getGeneralError(page), "Something went wrong. Please try again.");
389-
});
390351
});
391352

392353
describe("Third Party callback error tests", function () {

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import {
4242
screenshotOnFailure,
4343
isReact16,
4444
} from "../helpers";
45+
import { getThirdPartyTestCases } from "./thirdparty.test";
46+
import { getPasswordlessTestCases } from "./passwordless.test";
4547
import { TEST_CLIENT_BASE_URL, SIGN_IN_UP_API, GET_AUTH_URL_API } from "../constants";
4648

4749
// Run the tests in a DOM environment.
@@ -221,16 +223,15 @@ describe("SuperTokens Third Party Passwordless", function () {
221223
});
222224
});
223225

224-
it("should handle no providers enabled on the backend", async function () {
225-
if (!(await getFeatureFlags()).includes("recipeConfig")) {
226-
this.skip();
227-
}
228-
await assertProviders(page);
229-
await setupST({
230-
...appConfig,
231-
enabledRecipes: ["thirdpartypasswordless"],
232-
enabledProviders: [],
233-
});
226+
describe("Third Party specific", function () {
227+
getThirdPartyTestCases({
228+
authRecipe: "thirdpartypasswordless",
229+
rid: "thirdpartypasswordless",
230+
logId: "THIRDPARTYPASSWORDLESS",
231+
signInUpPageLoadLogs,
232+
thirdPartySignInUpLog: "THIRD_PARTY_SIGN_IN_AND_UP",
233+
});
234+
});
234235

235236
describe("Passwordless specific", function () {
236237
getPasswordlessTestCases({

test/helpers.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
SIGN_UP_API,
2323
EMAIL_EXISTS_API,
2424
TEST_CLIENT_BASE_URL,
25+
TEST_SERVER_BASE_URL,
2526
} from "./constants";
2627

2728
import path from "path";
@@ -837,6 +838,23 @@ export async function getPasswordlessDevice(loginAttemptInfo) {
837838
return await deviceResp.json();
838839
}
839840

841+
export function getDefaultSignUpFieldValues({
842+
name = "John Doe",
843+
email = "[email protected]",
844+
password = "Str0ngP@ssw0rd",
845+
age = "20",
846+
} = {}) {
847+
const fieldValues = [
848+
{ name: "email", value: email },
849+
{ name: "password", value: password },
850+
{ name: "name", value: name },
851+
{ name: "age", value: age },
852+
];
853+
const postValues = `{"formFields":[{"id":"email","value":"${email}"},{"id":"password","value":"${password}"},{"id":"name","value":"${name}"},{"id":"age","value":"${age}"},{"id":"country","value":""}]}`;
854+
855+
return { fieldValues, postValues };
856+
}
857+
840858
export function changeEmail(rid, recipeUserId, email, phoneNumber) {
841859
return fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/changeEmail`, {
842860
method: "POST",

0 commit comments

Comments
 (0)