Skip to content

Commit 0c336f7

Browse files
feat: add emailpassword integration tests
1 parent e6622ab commit 0c336f7

File tree

14 files changed

+4206
-6
lines changed

14 files changed

+4206
-6
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@babel/preset-env": "^7.16.11",
5252
"@babel/register": "^7.17.7",
5353
"@size-limit/preset-small-lib": "^8.1.0",
54+
"isomorphic-fetch": "^3.0.0",
5455
"madge": "^5.0.1",
5556
"mocha": "^9.2.2",
5657
"mocha-jsdom": "^2.0.0",

test/constants.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
2+
*
3+
* This software is licensed under the Apache License, Version 2.0 (the
4+
* "License") as published by the Apache Software Foundation.
5+
*
6+
* You may not use this file except in compliance with the License. You may
7+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations
13+
* under the License.
14+
*/
15+
16+
/*
17+
* Consts.
18+
*/
19+
export const TEST_SERVER_BASE_URL = "http://localhost:8082";
20+
export const TEST_APPLICATION_SERVER_BASE_URL =
21+
"http://localhost:" + (process.env.APP_SERVER === undefined ? "8082" : process.env.APP_SERVER);

test/helpers.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
2+
*
3+
* This software is licensed under the Apache License, Version 2.0 (the
4+
* "License") as published by the Apache Software Foundation.
5+
*
6+
* You may not use this file except in compliance with the License. You may
7+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations
13+
* under the License.
14+
*/
15+
16+
/*
17+
* Imports.
18+
*/
19+
import fetch from "isomorphic-fetch";
20+
import { TEST_APPLICATION_SERVER_BASE_URL, TEST_SERVER_BASE_URL } from "./constants";
21+
22+
export function getTestEmail(post) {
23+
return `john.doe+${Date.now()}-${post ?? "0"}@supertokens.io`;
24+
}
25+
26+
export async function backendHook(hookType) {
27+
const serverUrls = Array.from(new Set([TEST_SERVER_BASE_URL, TEST_APPLICATION_SERVER_BASE_URL]));
28+
29+
await Promise.all(
30+
serverUrls.map((url) => fetch(`${url}/test/${hookType}`, { method: "POST" }).catch(console.error))
31+
);
32+
}
33+
34+
export async function setupCoreApp({ appId, coreConfig } = {}) {
35+
const response = await fetch(`${TEST_SERVER_BASE_URL}/test/setup/app`, {
36+
method: "POST",
37+
headers: new Headers([["content-type", "application/json"]]),
38+
body: JSON.stringify({
39+
appId,
40+
coreConfig,
41+
}),
42+
});
43+
44+
return await response.text();
45+
}
46+
47+
export async function setupST({
48+
coreUrl,
49+
accountLinkingConfig = {},
50+
enabledRecipes,
51+
enabledProviders,
52+
passwordlessFlowType,
53+
passwordlessContactMethod,
54+
mfaInfo = {},
55+
} = {}) {
56+
await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/test/setup/st`, {
57+
method: "POST",
58+
headers: new Headers([["content-type", "application/json"]]),
59+
body: JSON.stringify({
60+
coreUrl,
61+
accountLinkingConfig,
62+
enabledRecipes,
63+
enabledProviders,
64+
passwordlessFlowType,
65+
passwordlessContactMethod,
66+
mfaInfo,
67+
}),
68+
});
69+
}
70+
71+
export async function backendBeforeEach() {
72+
await fetch(`${TEST_SERVER_BASE_URL}/beforeeach`, {
73+
method: "POST",
74+
}).catch(console.error);
75+
if (TEST_SERVER_BASE_URL !== TEST_APPLICATION_SERVER_BASE_URL) {
76+
await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/beforeeach`, {
77+
method: "POST",
78+
}).catch(console.error);
79+
}
80+
}

0 commit comments

Comments
 (0)