|
| 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