Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 120 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@babel/preset-env": "^7.16.11",
"@babel/register": "^7.17.7",
"@size-limit/preset-small-lib": "^8.1.0",
"isomorphic-fetch": "^3.0.0",
"madge": "^5.0.1",
"mocha": "^9.2.2",
"mocha-jsdom": "^2.0.0",
Expand Down
21 changes: 21 additions & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

/*
* Consts.
*/
export const TEST_SERVER_BASE_URL = "http://localhost:8082";
export const TEST_APPLICATION_SERVER_BASE_URL =
"http://localhost:" + (process.env.APP_SERVER === undefined ? "8082" : process.env.APP_SERVER);
80 changes: 80 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

/*
* Imports.
*/
import fetch from "isomorphic-fetch";
import { TEST_APPLICATION_SERVER_BASE_URL, TEST_SERVER_BASE_URL } from "./constants";

export function getTestEmail(post) {
return `john.doe+${Date.now()}-${post ?? "0"}@supertokens.io`;
}

export async function backendHook(hookType) {
const serverUrls = Array.from(new Set([TEST_SERVER_BASE_URL, TEST_APPLICATION_SERVER_BASE_URL]));

await Promise.all(
serverUrls.map((url) => fetch(`${url}/test/${hookType}`, { method: "POST" }).catch(console.error))
);
}

export async function setupCoreApp({ appId, coreConfig } = {}) {
const response = await fetch(`${TEST_SERVER_BASE_URL}/test/setup/app`, {
method: "POST",
headers: new Headers([["content-type", "application/json"]]),
body: JSON.stringify({
appId,
coreConfig,
}),
});

return await response.text();
}

export async function setupST({
coreUrl,
accountLinkingConfig = {},
enabledRecipes,
enabledProviders,
passwordlessFlowType,
passwordlessContactMethod,
mfaInfo = {},
} = {}) {
await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/test/setup/st`, {
method: "POST",
headers: new Headers([["content-type", "application/json"]]),
body: JSON.stringify({
coreUrl,
accountLinkingConfig,
enabledRecipes,
enabledProviders,
passwordlessFlowType,
passwordlessContactMethod,
mfaInfo,
}),
});
}

export async function backendBeforeEach() {
await fetch(`${TEST_SERVER_BASE_URL}/beforeeach`, {
method: "POST",
}).catch(console.error);
if (TEST_SERVER_BASE_URL !== TEST_APPLICATION_SERVER_BASE_URL) {
await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/beforeeach`, {
method: "POST",
}).catch(console.error);
}
}
Loading
Loading