Skip to content

Commit

Permalink
test: add tests checking if clientType is applied in tp, tpep and tpp…
Browse files Browse the repository at this point in the history
…wless recipes (#727)
  • Loading branch information
porcellus authored Aug 21, 2023
1 parent d0e7de8 commit 1f5c5dd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/for-tests-react-16/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ if (emailVerificationMode !== "OFF") {
}
SuperTokens.init({
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
clientType: testContext.clientType,
appInfo: {
appName: "SuperTokens",
websiteDomain: getWebsiteDomain(),
Expand Down
1 change: 1 addition & 0 deletions examples/for-tests-react-16/src/testContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions examples/for-tests/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ if (emailVerificationMode !== "OFF") {

SuperTokens.init({
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
clientType: testContext.clientType,
appInfo: {
appName: "SuperTokens",
websiteDomain: getWebsiteDomain(),
Expand Down
1 change: 1 addition & 0 deletions examples/for-tests/src/testContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 22 additions & 1 deletion test/end-to-end/thirdparty.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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 () {
Expand Down
25 changes: 25 additions & 0 deletions test/end-to-end/thirdpartyemailpassword.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
waitForSTElement,
waitFor,
getFieldErrors,
clickOnProviderButtonWithoutWaiting,
} from "../helpers";
import {
TEST_CLIENT_BASE_URL,
Expand All @@ -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.
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 1f5c5dd

Please sign in to comment.