From 1f5c5dd8279e6df3264f991b1b51fc1ba549015a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mih=C3=A1ly=20Lengyel?= Date: Mon, 21 Aug 2023 11:13:11 +0200 Subject: [PATCH] test: add tests checking if clientType is applied in tp, tpep and tppwless recipes (#727) --- examples/for-tests-react-16/src/App.js | 1 + .../for-tests-react-16/src/testContext.js | 1 + examples/for-tests/src/App.js | 1 + examples/for-tests/src/testContext.js | 1 + test/end-to-end/thirdparty.test.js | 23 ++++++++++++++++- .../thirdpartyemailpassword.test.js | 25 +++++++++++++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) diff --git a/examples/for-tests-react-16/src/App.js b/examples/for-tests-react-16/src/App.js index 41b4c24e7..e69a5154e 100644 --- a/examples/for-tests-react-16/src/App.js +++ b/examples/for-tests-react-16/src/App.js @@ -272,6 +272,7 @@ if (emailVerificationMode !== "OFF") { } SuperTokens.init({ usesDynamicLoginMethods: testContext.usesDynamicLoginMethods, + clientType: testContext.clientType, appInfo: { appName: "SuperTokens", websiteDomain: getWebsiteDomain(), diff --git a/examples/for-tests-react-16/src/testContext.js b/examples/for-tests-react-16/src/testContext.js index 4955fe020..e5b2f8be9 100644 --- a/examples/for-tests-react-16/src/testContext.js +++ b/examples/for-tests-react-16/src/testContext.js @@ -13,6 +13,7 @@ export function getTestContext() { mockLoginMethodsForDynamicLogin: localStorage.getItem("mockLoginMethodsForDynamicLogin"), staticProviderList: localStorage.getItem("staticProviderList"), mockTenantId: localStorage.getItem("mockTenantId"), + clientType: localStorage.getItem("clientType"), }; return ret; } diff --git a/examples/for-tests/src/App.js b/examples/for-tests/src/App.js index 41aef0e21..a453227fe 100644 --- a/examples/for-tests/src/App.js +++ b/examples/for-tests/src/App.js @@ -279,6 +279,7 @@ if (emailVerificationMode !== "OFF") { SuperTokens.init({ usesDynamicLoginMethods: testContext.usesDynamicLoginMethods, + clientType: testContext.clientType, appInfo: { appName: "SuperTokens", websiteDomain: getWebsiteDomain(), diff --git a/examples/for-tests/src/testContext.js b/examples/for-tests/src/testContext.js index 4955fe020..e5b2f8be9 100644 --- a/examples/for-tests/src/testContext.js +++ b/examples/for-tests/src/testContext.js @@ -13,6 +13,7 @@ export function getTestContext() { mockLoginMethodsForDynamicLogin: localStorage.getItem("mockLoginMethodsForDynamicLogin"), staticProviderList: localStorage.getItem("staticProviderList"), mockTenantId: localStorage.getItem("mockTenantId"), + clientType: localStorage.getItem("clientType"), }; return ret; } diff --git a/test/end-to-end/thirdparty.test.js b/test/end-to-end/thirdparty.test.js index 9c5ef5952..5489a04e4 100644 --- a/test/end-to-end/thirdparty.test.js +++ b/test/end-to-end/thirdparty.test.js @@ -32,11 +32,12 @@ import { getGeneralError, waitFor, screenshotOnFailure, + clickOnProviderButtonWithoutWaiting, } from "../helpers"; // Run the tests in a DOM environment. require("jsdom-global")(); -import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL, SIGN_IN_UP_API } from "../constants"; +import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL, SIGN_IN_UP_API, GET_AUTH_URL_API } from "../constants"; describe("SuperTokens Third Party", function () { getThirdPartyTestCases({ @@ -90,6 +91,7 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa afterEach(async function () { await page.evaluate(() => { localStorage.removeItem("thirdPartyRedirectURL"); + localStorage.removeItem("clientType"); }); return screenshotOnFailure(this, browser); }); @@ -355,6 +357,25 @@ export function getThirdPartyTestCases({ authRecipe, rid, logId, signInUpPageLoa const error = await getGeneralError(page); assert.deepStrictEqual(error, "Test message!!!!"); }); + + it("clientType should be included when getting the auth url", async function () { + await page.evaluate(() => { + localStorage.setItem("clientType", `test-web`); + }); + + await Promise.all([ + page.goto(`${TEST_CLIENT_BASE_URL}/auth`), + page.waitForNavigation({ waitUntil: "networkidle0" }), + ]); + + const res = await Promise.all([ + page.waitForRequest((request) => request.url().startsWith(GET_AUTH_URL_API)), + clickOnProviderButtonWithoutWaiting(page, "Auth0"), + ]); + + const url = new URL(res[0].url()); + assert.strictEqual(url.searchParams.get("clientType"), "test-web"); + }); }); describe("Third Party callback error tests", function () { diff --git a/test/end-to-end/thirdpartyemailpassword.test.js b/test/end-to-end/thirdpartyemailpassword.test.js index fbc9b5b1e..2411fba07 100644 --- a/test/end-to-end/thirdpartyemailpassword.test.js +++ b/test/end-to-end/thirdpartyemailpassword.test.js @@ -42,6 +42,7 @@ import { waitForSTElement, waitFor, getFieldErrors, + clickOnProviderButtonWithoutWaiting, } from "../helpers"; import { TEST_CLIENT_BASE_URL, @@ -50,6 +51,7 @@ import { SIGN_UP_API, SOMETHING_WENT_WRONG_ERROR, EMAIL_EXISTS_API, + GET_AUTH_URL_API, } from "../constants"; // Run the tests in a DOM environment. @@ -136,6 +138,10 @@ describe("SuperTokens Third Party Email Password", function () { }); describe("Third Party Email Password test", function () { + afterEach(async function () { + await page.evaluate(() => window.localStorage.removeItem("clientType")); + }); + it("Successful signup with credentials", async function () { await toggleSignInSignUp(page); await defaultSignUp(page, "thirdpartyemailpassword"); @@ -346,6 +352,25 @@ describe("SuperTokens Third Party Email Password", function () { // 3. Compare userIds assert.notDeepStrictEqual(thirdPartyUserId, emailPasswordUserId); }); + + it("clientType should be included when getting the auth url", async function () { + await page.evaluate(() => { + localStorage.setItem("clientType", `test-web`); + }); + + await Promise.all([ + page.goto(`${TEST_CLIENT_BASE_URL}/auth`), + page.waitForNavigation({ waitUntil: "networkidle0" }), + ]); + + const res = await Promise.all([ + page.waitForRequest((request) => request.url().startsWith(GET_AUTH_URL_API)), + clickOnProviderButtonWithoutWaiting(page, "Auth0"), + ]); + + const url = new URL(res[0].url()); + assert.strictEqual(url.searchParams.get("clientType"), "test-web"); + }); }); describe("Third Party callback error tests", function () {