fix: auto accept (#15975)

* fix: auto accept

* Update packages/lib/server/repository/organization.ts

Co-authored-by: Hariom Balhara <[email protected]>

---------

Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
sean-brydonandHariom Balhara authored and GitHub committed 2024-07-29 14:18:55 +00:00
1 parent 4d0b417925
commit 92d0fc6eb4
2 files changed
+16 -5

No files matched your search

@@ -25,8 +25,8 @@ describe("Organization.findUniqueByMatchingAutoAcceptEmail", () => {
});
it("should throw an error if multiple organizations match the email domain", async () => {
await createOrganization({ name: "Test Org 1", orgAutoAcceptEmail: "example.com" });
await createOrganization({ name: "Test Org 2", orgAutoAcceptEmail: "example.com" });
await createReviewedOrganization({ name: "Test Org 1", orgAutoAcceptEmail: "example.com" });
await createReviewedOrganization({ name: "Test Org 2", orgAutoAcceptEmail: "example.com" });
await expect(
OrganizationRepository.findUniqueByMatchingAutoAcceptEmail({ email: "[email protected]" })
@@ -34,7 +34,10 @@ describe("Organization.findUniqueByMatchingAutoAcceptEmail", () => {
});
it("should return the parsed organization if a single match is found", async () => {
const organization = await createOrganization({ name: "Test Org", orgAutoAcceptEmail: "example.com" });
const organization = await createReviewedOrganization({
name: "Test Org",
orgAutoAcceptEmail: "example.com",
});
const result = await OrganizationRepository.findUniqueByMatchingAutoAcceptEmail({
email: "[email protected]",
@@ -54,7 +57,7 @@ describe("Organization.findUniqueByMatchingAutoAcceptEmail", () => {
});
it("should correctly match orgAutoAcceptEmail", async () => {
await createOrganization({ name: "Test Org", orgAutoAcceptEmail: "noexample.com" });
await createReviewedOrganization({ name: "Test Org", orgAutoAcceptEmail: "noexample.com" });
const result = await OrganizationRepository.findUniqueByMatchingAutoAcceptEmail({
email: "[email protected]",
@@ -64,7 +67,7 @@ describe("Organization.findUniqueByMatchingAutoAcceptEmail", () => {
});
});
async function createOrganization({
async function createReviewedOrganization({
name = "Test Org",
orgAutoAcceptEmail,
}: {
@@ -78,6 +81,8 @@ async function createOrganization({
organizationSettings: {
create: {
orgAutoAcceptEmail,
isOrganizationVerified: true,
isAdminReviewed: true,
},
},
},
@@ -172,10 +172,16 @@ export class OrganizationRepository {
isOrganization: true,
organizationSettings: {
orgAutoAcceptEmail: emailDomain,
isOrganizationVerified: true,
isAdminReviewed: true,
},
},
});
if (orgs.length > 1) {
logger.error(
"Multiple organizations found with the same auto accept email domain",
safeStringify({ orgs, emailDomain })
);
// Detect and fail just in case this situation arises. We should really identify the problem in this case and fix the data.
throw new Error("Multiple organizations found with the same auto accept email domain");
}