Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMayankThakur committed Oct 31, 2023
1 parent 1492467 commit 41afe16
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/ts/supertokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ import NormalisedURLPath from "./normalisedURLPath";
import type { BaseRequest, BaseResponse } from "./framework";
import type { TypeFramework } from "./framework/types";
import STError from "./error";
import { logDebugMessage } from "./logger";
import { enableDebugLogs, logDebugMessage } from "./logger";
import { PostSuperTokensInitCallbacks } from "./postSuperTokensInitCallbacks";
import { DEFAULT_TENANT_ID } from "./recipe/multitenancy/constants";
import debug from "debug";

export default class SuperTokens {
private static instance: SuperTokens | undefined;
Expand All @@ -49,10 +48,16 @@ export default class SuperTokens {

telemetryEnabled: boolean;

debugEnabled: boolean;

constructor(config: TypeInput) {
if (config.debug) {
debug.enable("com.supertokens");
if (config.debug === true) {
this.debugEnabled = true;
enableDebugLogs();
} else {
this.debugEnabled = false;
}

logDebugMessage("Started SuperTokens with debug logging (supertokens.init called)");
const originToPrint =
config.appInfo.origin === undefined
Expand Down
60 changes: 60 additions & 0 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
} = require("./utils");
const request = require("supertest");
const express = require("express");
const debug = require("debug");
let STExpress = require("../");
let Session = require("../recipe/session");
let SessionRecipe = require("../lib/build/recipe/session/recipe").default;
Expand All @@ -41,6 +42,7 @@ let EmailPassword = require("../lib/build/recipe/emailpassword");
let EmailPasswordRecipe = require("../lib/build/recipe/emailpassword/recipe").default;
const { getTopLevelDomainForSameSiteResolution } = require("../lib/build/utils");
const { middleware } = require("../framework/express");
const { SUPERTOKENS_DEBUG_NAMESPACE } = require("../lib/build/logger");

describe(`configTest: ${printPath("[test/config.test.js]")}`, function () {
beforeEach(async function () {
Expand Down Expand Up @@ -1192,6 +1194,64 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () {
}
});

it("testing that the debug mode is set", async function () {
const connectionURI = await startST();
{
STExpress.init({
supertokens: {
connectionURI,
},
appInfo: {
apiDomain: "api.supertokens.io",
appName: "SuperTokens",
websiteDomain: "supertokens.io",
},
recipeList: [Session.init({ getTokenTransferMethod: () => "cookie" })],
debug: true,
});
assert(SuperTokens.getInstanceOrThrowError().debugEnabled === true);
assert(debug.enabled(SUPERTOKENS_DEBUG_NAMESPACE) === true);
resetAll();
}

{
debug.disable();
STExpress.init({
supertokens: {
connectionURI,
},
appInfo: {
apiDomain: "api.supertokens.io",
appName: "SuperTokens",
websiteDomain: "supertokens.io",
},
recipeList: [Session.init({ getTokenTransferMethod: () => "cookie" })],
debug: false,
});
assert(SuperTokens.getInstanceOrThrowError().debugEnabled === false);
assert(debug.enabled(SUPERTOKENS_DEBUG_NAMESPACE) === false);
resetAll();
}

{
debug.disable();
STExpress.init({
supertokens: {
connectionURI,
},
appInfo: {
apiDomain: "api.supertokens.io",
appName: "SuperTokens",
websiteDomain: "supertokens.io",
},
recipeList: [Session.init({ getTokenTransferMethod: () => "cookie" })],
});
assert(SuperTokens.getInstanceOrThrowError().debugEnabled === false);
assert(debug.enabled(SUPERTOKENS_DEBUG_NAMESPACE) === false);
resetAll();
}
});

it("checking for default cookie config", async function () {
const connectionURI = await startST();
STExpress.init({
Expand Down

0 comments on commit 41afe16

Please sign in to comment.