Skip to content

Commit a4f9d8f

Browse files
committed
update: mfa.signin tests use core apps
1 parent f07a3d2 commit a4f9d8f

File tree

1 file changed

+56
-61
lines changed

1 file changed

+56
-61
lines changed

test/end-to-end/mfa.signin.test.js

Lines changed: 56 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,25 @@
1717
* Imports
1818
*/
1919

20-
import assert from "assert";
21-
import puppeteer from "puppeteer";
2220
import {
2321
clearBrowserCookiesWithoutAffectingConsole,
2422
setInputValues,
2523
submitForm,
2624
waitForSTElement,
2725
screenshotOnFailure,
28-
backendBeforeEach,
2926
getTestEmail,
3027
getPasswordlessDevice,
3128
waitFor,
3229
isMFASupported,
33-
setAccountLinkingConfig,
3430
expectErrorThrown,
3531
waitForUrl,
3632
setupBrowser,
33+
backendHook,
34+
setupCoreApp,
35+
setupST,
3736
} from "../helpers";
38-
import fetch from "isomorphic-fetch";
39-
import { CREATE_CODE_API, CREATE_TOTP_DEVICE_API, MFA_INFO_API } from "../constants";
40-
41-
import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL } from "../constants";
4237
import { getTestPhoneNumber } from "../exampleTestHelpers";
4338
import {
44-
setMFAInfo,
4539
tryEmailPasswordSignUp,
4640
waitForDashboard,
4741
completeOTP,
@@ -52,11 +46,7 @@ import {
5246
tryPasswordlessSignInUp,
5347
setupTOTP,
5448
completeTOTP,
55-
setupUserWithAllFactors,
56-
goToFactorChooser,
5749
waitForAccessDenied,
58-
waitForLoadingScreen,
59-
waitForBlockedScreen,
6050
} from "./mfa.helpers";
6151

6252
/*
@@ -66,55 +56,40 @@ describe("SuperTokens SignIn w/ MFA", function () {
6656
let browser;
6757
let page;
6858
let consoleLogs = [];
69-
let skipped = false;
59+
60+
const appConfig = {
61+
accountLinkingConfig: {
62+
enabled: true,
63+
shouldAutoLink: {
64+
shouldAutomaticallyLink: true,
65+
shouldRequireVerification: false,
66+
},
67+
},
68+
};
7069

7170
before(async function () {
7271
if (!(await isMFASupported())) {
73-
skipped = true;
7472
this.skip();
75-
return;
7673
}
77-
await backendBeforeEach();
78-
79-
await fetch(`${TEST_SERVER_BASE_URL}/startst`, {
80-
method: "POST",
81-
}).catch(console.error);
82-
83-
await setAccountLinkingConfig(true, true, false);
84-
74+
await backendHook("before");
8575
browser = await setupBrowser();
86-
});
8776

88-
after(async function () {
89-
if (skipped) {
90-
return;
91-
}
92-
await browser.close();
93-
94-
await fetch(`${TEST_SERVER_BASE_URL}/after`, {
95-
method: "POST",
96-
}).catch(console.error);
97-
98-
await fetch(`${TEST_SERVER_BASE_URL}/stopst`, {
99-
method: "POST",
100-
}).catch(console.error);
101-
});
102-
103-
afterEach(async function () {
104-
await screenshotOnFailure(this, browser);
105-
if (page) {
106-
await page.close();
107-
}
77+
const coreUrl = await setupCoreApp();
78+
appConfig.coreUrl = coreUrl;
79+
await setupST(appConfig);
10880
});
10981

11082
beforeEach(async function () {
83+
await backendHook("beforeEach");
11184
page = await browser.newPage();
11285
page.on("console", (consoleObj) => {
11386
const log = consoleObj.text();
87+
// console.log(log);
11488
if (log.startsWith("ST_LOGS")) {
11589
consoleLogs.push(log);
11690
}
11791
});
92+
11893
consoleLogs = await clearBrowserCookiesWithoutAffectingConsole(page, []);
11994

12095
await page.evaluate(() => window.localStorage.removeItem("supertokens-passwordless-loginAttemptInfo"));
@@ -123,12 +98,25 @@ describe("SuperTokens SignIn w/ MFA", function () {
12398
await page.evaluate(() => window.localStorage.setItem("enableAllRecipes", "true"));
12499
});
125100

101+
afterEach(async function () {
102+
await screenshotOnFailure(this, browser);
103+
page?.evaluate(() => window.localStorage.removeItem("firstFactors"));
104+
await page?.close();
105+
await backendHook("afterEach");
106+
});
107+
108+
after(async function () {
109+
await browser?.close();
110+
await backendHook("after");
111+
});
112+
126113
it("sign in with email-otp (auto-setup)", async function () {
127114
const email = await getTestEmail();
128115

129-
await setMFAInfo({
116+
appConfig.mfaInfo = {
130117
requirements: ["otp-email"],
131-
});
118+
};
119+
setupST(appConfig);
132120

133121
await tryEmailPasswordSignUp(page, email);
134122

@@ -149,9 +137,10 @@ describe("SuperTokens SignIn w/ MFA", function () {
149137
const email = await getTestEmail();
150138
const phoneNumber = getTestPhoneNumber();
151139

152-
await setMFAInfo({
140+
appConfig.mfaInfo = {
153141
requirements: [{ oneOf: ["otp-email", "otp-phone"] }],
154-
});
142+
};
143+
setupST(appConfig);
155144

156145
await tryEmailPasswordSignUp(page, email);
157146
await chooseFactor(page, "otp-phone");
@@ -170,9 +159,10 @@ describe("SuperTokens SignIn w/ MFA", function () {
170159
});
171160

172161
it("set up otp-email and sign-in", async function () {
173-
await setMFAInfo({
162+
appConfig.mfaInfo = {
174163
requirements: [],
175-
});
164+
};
165+
setupST(appConfig);
176166
const email = await getTestEmail();
177167
const phoneNumber = getTestPhoneNumber();
178168

@@ -183,9 +173,10 @@ describe("SuperTokens SignIn w/ MFA", function () {
183173

184174
await logout(page);
185175

186-
await setMFAInfo({
176+
appConfig.mfaInfo = {
187177
requirements: [{ oneOf: ["otp-email"] }],
188-
});
178+
};
179+
setupST(appConfig);
189180

190181
await tryPasswordlessSignInUp(page, phoneNumber, undefined, true);
191182

@@ -204,14 +195,16 @@ describe("SuperTokens SignIn w/ MFA", function () {
204195
});
205196

206197
it("set up totp and sign-in", async function () {
207-
await setMFAInfo({
198+
appConfig.mfaInfo = {
208199
requirements: [],
209-
});
200+
};
201+
setupST(appConfig);
210202
const email = await getTestEmail();
211203

212-
await setMFAInfo({
204+
appConfig.mfaInfo = {
213205
requirements: [{ oneOf: ["otp-email", "totp"] }],
214-
});
206+
};
207+
setupST(appConfig);
215208

216209
await tryEmailPasswordSignUp(page, email);
217210
await chooseFactor(page, "otp-email");
@@ -240,19 +233,21 @@ describe("SuperTokens SignIn w/ MFA", function () {
240233

241234
it("should show access denied if the only next option is an unknown factor id", async () => {
242235
const email = await getTestEmail();
243-
await setMFAInfo({
236+
appConfig.mfaInfo = {
244237
requirements: ["unknown"],
245238
alreadySetup: ["unknown"],
246-
});
239+
};
240+
setupST(appConfig);
247241

248242
await tryEmailPasswordSignUp(page, email);
249243
await waitForAccessDenied(page);
250244
});
251245

252246
it("should throw error if there are no valid next options", async () => {
253-
await setMFAInfo({
247+
appConfig.mfaInfo = {
254248
requirements: ["unknown"],
255-
});
249+
};
250+
setupST(appConfig);
256251

257252
const email = await getTestEmail();
258253
await expectErrorThrown(page, () => tryEmailPasswordSignUp(page, email));

0 commit comments

Comments
 (0)