Skip to content

Commit

Permalink
fix: thirdparty mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Aug 16, 2024
1 parent 7b92185 commit 74fd3eb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const recipe_1 = __importDefault(require("../../../multitenancy/recipe"));
const normalisedURLDomain_1 = __importDefault(require("../../../../normalisedURLDomain"));
const normalisedURLPath_1 = __importDefault(require("../../../../normalisedURLPath"));
const utils_1 = require("../../../thirdparty/providers/utils");
const constants_1 = require("../../../multitenancy/constants");
async function createOrUpdateThirdPartyConfig(_, tenantId, options, userContext) {
var _a;
const requestBody = await options.req.getJSONBody();
Expand All @@ -29,7 +30,8 @@ async function createOrUpdateThirdPartyConfig(_, tenantId, options, userContext)
? _a
: [];
for (const provider of staticProviders.filter(
(provider) => provider.includeInNonPublicTenantsByDefault === true
(provider) =>
provider.includeInNonPublicTenantsByDefault === true || tenantId === constants_1.DEFAULT_TENANT_ID
)) {
await multitenancy_1.default.createOrUpdateThirdPartyConfig(
tenantId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { UserContext } from "../../../../types";
import NormalisedURLDomain from "../../../../normalisedURLDomain";
import NormalisedURLPath from "../../../../normalisedURLPath";
import { doPostRequest } from "../../../thirdparty/providers/utils";
import { DEFAULT_TENANT_ID } from "../../../multitenancy/constants";

export type Response =
| {
Expand Down Expand Up @@ -50,7 +51,7 @@ export default async function createOrUpdateThirdPartyConfig(
const mtRecipe = MultitenancyRecipe.getInstance();
const staticProviders = mtRecipe?.staticThirdPartyProviders ?? [];
for (const provider of staticProviders.filter(
(provider) => provider.includeInNonPublicTenantsByDefault === true
(provider) => provider.includeInNonPublicTenantsByDefault === true || tenantId === DEFAULT_TENANT_ID
)) {
await Multitenancy.createOrUpdateThirdPartyConfig(
tenantId,
Expand Down
48 changes: 34 additions & 14 deletions test/test-server/src/thirdparty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,43 @@ import { logger } from "./logger";
const namespace = "com.supertokens:node-test-server:thirdparty";
const { logDebugMessage } = logger(namespace);

const router = Router().post("/manuallycreateorupdateuser", async (req, res, next) => {
try {
logDebugMessage("ThirdParty:manuallyCreateOrUpdateUser %j", req.body);
let session = req.body.session && (await convertRequestSessionToSessionObject(req.body.session));
const response = await ThirdParty.manuallyCreateOrUpdateUser(
const router = Router()
.post("/manuallycreateorupdateuser", async (req, res, next) => {
try {
logDebugMessage("ThirdParty:manuallyCreateOrUpdateUser %j", req.body);
let session = req.body.session && (await convertRequestSessionToSessionObject(req.body.session));
const response = await ThirdParty.manuallyCreateOrUpdateUser(
req.body.tenantId || "public",
req.body.thirdPartyId,
req.body.thirdPartyUserId,
req.body.email,
req.body.isVerified,
session,
req.body.userContext
);
await serializeResponse(req, res, response);
} catch (e) {
next(e);
}
})
.post("/getprovider", async (req, res, next) => {
logDebugMessage("ThirdParty:getProvider %j", req.body);
let provider = await ThirdParty.getProvider(
req.body.tenantId || "public",
req.body.thirdPartyId,
req.body.thirdPartyUserId,
req.body.email,
req.body.isVerified,
session,
req.body.clientType,
req.body.userContext
);
await serializeResponse(req, res, response);
} catch (e) {
next(e);
}
});

if (provider === undefined) {
await serializeResponse(req, res, {});
return;
}

await serializeResponse(req, res, {
id: provider.id,
config: provider.config,
});
});

export default router;

0 comments on commit 74fd3eb

Please sign in to comment.