* fix: dont check OrganizationSettings.orgAutoAcceptEmail uniqueness for platform teams * feat: display organizationId in OAuthClientCard * feat: ApiAuthStrategy handle oauth credentials * refactor: clean up ApiAuthStrategy test * refactor: use ApiAuthGuard in OauthClientsUsersController and OAuthFlowController * fix: copying org id * refactor: more specific error message when api auth * refactor: auto accept team creator membership * feat: useTeamEventType and useTeamEventTypes hooks * refactor: make team event-types public & searchable by eventSlug * feat: include host name in team event-types hosts response * fix: isFixed=true by default for COLLECTIVE event hosts * fix: useTeamEventType eventSlug access * feat: BookerPlatformWrapper enable team events by exposting orgId and teamId props * refactor: provide orgId in atoms context * refactor: use orgId from context in team event-types hooks * refactor: return teams in useMe * chore: examples app teams setup * Revert "refactor: return teams in useMe" This reverts commit de992ddc9af6ee9a2111938069f5b9c34cc2d8ea. * Revert "chore: examples app teams setup" This reverts commit 0766aa21acc25efa2361d38c3f87ddba773a0245. * feat: useTeams hook * chore: setup examples app with team event-type * fix: small fixes * swagger * Revert "refactor: provide orgId in atoms context" This reverts commit f053a498ee6f8fa8ece5ec8d8630c59eda8873e3. * feat: orgId in atoms context * feat: PlatformBilling guard * chore: delete test of the deleted oauth-client-credentials.guard * refactor: org event-types collective events isFixed always true and priority medium * refactor: org event-types COLLECTIVE response ignore isFixed and priority as they are same * fix: organizations event-types e2e * fix: billing guard * refactor: tests cleanup * fix: platform plan guard spec * refactor: e2e test cleanup * seed error if not team * refactor: rename authenticateApiKey to authenticateBearerToken * refactor: transforming response hosts * refactor: rename findUniqueByMatchingAutoAcceptEmail to findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail * refactor: rename findUniqueByMatchingAutoAcceptEmail to findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail --------- Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
111 lines
3.1 KiB
TypeScript
111 lines
3.1 KiB
TypeScript
import prismock from "../../../../tests/libs/__mocks__/prisma";
|
|
|
|
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
|
|
import { OrganizationRepository } from "./organization";
|
|
|
|
vi.mock("./teamUtils", () => ({
|
|
getParsedTeam: (org: any) => org,
|
|
}));
|
|
|
|
describe("Organization.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail", () => {
|
|
beforeEach(async () => {
|
|
vi.resetAllMocks();
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore
|
|
await prismock.reset();
|
|
});
|
|
|
|
it("should return null if no organization matches the email domain", async () => {
|
|
const result = await OrganizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail({
|
|
email: "test@example.com",
|
|
});
|
|
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it("should throw an error if multiple organizations match the email domain", async () => {
|
|
await createReviewedOrganization({ name: "Test Org 1", orgAutoAcceptEmail: "example.com" });
|
|
await createReviewedOrganization({ name: "Test Org 2", orgAutoAcceptEmail: "example.com" });
|
|
|
|
await expect(
|
|
OrganizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail({ email: "test@example.com" })
|
|
).rejects.toThrow("Multiple organizations found with the same auto accept email domain");
|
|
});
|
|
|
|
it("should return the parsed organization if a single match is found", async () => {
|
|
const organization = await createReviewedOrganization({
|
|
name: "Test Org",
|
|
orgAutoAcceptEmail: "example.com",
|
|
});
|
|
|
|
const result = await OrganizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail({
|
|
email: "test@example.com",
|
|
});
|
|
|
|
expect(result).toEqual(organization);
|
|
});
|
|
|
|
it("should not confuse a team with organization", async () => {
|
|
await createTeam({ name: "Test Team", orgAutoAcceptEmail: "example.com" });
|
|
|
|
const result = await OrganizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail({
|
|
email: "test@example.com",
|
|
});
|
|
|
|
expect(result).toEqual(null);
|
|
});
|
|
|
|
it("should correctly match orgAutoAcceptEmail", async () => {
|
|
await createReviewedOrganization({ name: "Test Org", orgAutoAcceptEmail: "noexample.com" });
|
|
|
|
const result = await OrganizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail({
|
|
email: "test@example.com",
|
|
});
|
|
|
|
expect(result).toEqual(null);
|
|
});
|
|
});
|
|
|
|
async function createReviewedOrganization({
|
|
name = "Test Org",
|
|
orgAutoAcceptEmail,
|
|
}: {
|
|
name: string;
|
|
orgAutoAcceptEmail: string;
|
|
}) {
|
|
return await prismock.team.create({
|
|
data: {
|
|
name,
|
|
isOrganization: true,
|
|
organizationSettings: {
|
|
create: {
|
|
orgAutoAcceptEmail,
|
|
isOrganizationVerified: true,
|
|
isAdminReviewed: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
async function createTeam({
|
|
name = "Test Team",
|
|
orgAutoAcceptEmail,
|
|
}: {
|
|
name: string;
|
|
orgAutoAcceptEmail: string;
|
|
}) {
|
|
return await prismock.team.create({
|
|
data: {
|
|
name,
|
|
isOrganization: false,
|
|
organizationSettings: {
|
|
create: {
|
|
orgAutoAcceptEmail,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|