Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -0,0 +1,73 @@
import { describe, expect, it } from "vitest";
import {
isEmailSuppressed,
normalizeSuppressionAddress,
recordEmailSuppression,
type EmailSuppressionClient,
type EmailSuppressionRow,
} from "./email-suppression.server.js";
/** Minimal in-memory stand-in for the EmailSuppressionList Prisma delegate. */
function createFakeClient(): EmailSuppressionClient & { rows: EmailSuppressionRow[] } {
const rows: EmailSuppressionRow[] = [];
let seq = 0;
return {
rows,
emailSuppressionList: {
async upsert(args) {
const existing = rows.find((r) => r.tenantId === args.where.tenantId_emailAddress.tenantId && r.emailAddress === args.where.tenantId_emailAddress.emailAddress);
if (existing) {
existing.reason = args.update.reason;
existing.detail = args.update.detail;
return existing;
}
const created: EmailSuppressionRow = { id: `s${++seq}`, ...args.create };
rows.push(created);
return created;
},
async findUnique(args) {
return rows.find((r) => r.tenantId === args.where.tenantId_emailAddress.tenantId && r.emailAddress === args.where.tenantId_emailAddress.emailAddress) ?? null;
},
},
};
}
describe("normalizeSuppressionAddress", () => {
it("trims and lower-cases", () => {
expect(normalizeSuppressionAddress(" Foo@Bar.TEST ")).toBe("foo@bar.test");
});
});
describe("recordEmailSuppression", () => {
it("creates a normalized entry", async () => {
const client = createFakeClient();
await recordEmailSuppression({ tenantId: "t1", emailAddress: "Hard@Bounce.test", reason: "bounce", detail: "550 mailbox unavailable" }, client);
expect(client.rows).toEqual([{ id: "s1", tenantId: "t1", emailAddress: "hard@bounce.test", reason: "bounce", detail: "550 mailbox unavailable" }]);
});
it("is idempotent on (tenantId, emailAddress) and updates the reason/detail", async () => {
const client = createFakeClient();
await recordEmailSuppression({ tenantId: "t1", emailAddress: "a@x.test", reason: "manual" }, client);
await recordEmailSuppression({ tenantId: "t1", emailAddress: "A@X.test", reason: "complaint", detail: "spam report" }, client);
expect(client.rows).toHaveLength(1);
expect(client.rows[0]).toMatchObject({ reason: "complaint", detail: "spam report" });
});
it("scopes entries per tenant", async () => {
const client = createFakeClient();
await recordEmailSuppression({ tenantId: "t1", emailAddress: "a@x.test", reason: "bounce" }, client);
await recordEmailSuppression({ tenantId: "t2", emailAddress: "a@x.test", reason: "bounce" }, client);
expect(client.rows).toHaveLength(2);
});
});
describe("isEmailSuppressed", () => {
it("returns true only for a suppressed address in the same tenant", async () => {
const client = createFakeClient();
await recordEmailSuppression({ tenantId: "t1", emailAddress: "blocked@x.test", reason: "bounce" }, client);
await expect(isEmailSuppressed({ tenantId: "t1", emailAddress: "Blocked@X.test" }, client)).resolves.toBe(true);
await expect(isEmailSuppressed({ tenantId: "t1", emailAddress: "other@x.test" }, client)).resolves.toBe(false);
await expect(isEmailSuppressed({ tenantId: "t2", emailAddress: "blocked@x.test" }, client)).resolves.toBe(false);
});
});