Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,19 +1,23 @@
import { describe, expect, it } from "vitest";
import {
EMAIL_SUPPRESSION_QUERY_BATCH_SIZE,
isEmailSuppressed,
listSuppressedEmailAddresses,
normalizeSuppressionAddress,
recordEmailSuppression,
type EmailSuppressionBatchClient,
type EmailSuppressionClient,
type EmailSuppressionRow,
} from "./email-suppression.server.js";
/** Minimal in-memory stand-in for the EmailSuppressionList Prisma delegate. */
function createFakeClient(): EmailSuppressionClient & { rows: EmailSuppressionRow[] } {
function createFakeClient(): EmailSuppressionClient & EmailSuppressionBatchClient & { rows: EmailSuppressionRow[]; findManyCalls: number } {
const rows: EmailSuppressionRow[] = [];
let seq = 0;
return {
const client: EmailSuppressionClient & EmailSuppressionBatchClient & { rows: EmailSuppressionRow[]; findManyCalls: number } = {
rows,
findManyCalls: 0,
emailSuppressionList: {
async upsert(args) {
const existing = rows.find((r) => r.tenantId === args.where.tenantId_emailAddress.tenantId && r.emailAddress === args.where.tenantId_emailAddress.emailAddress);
@@ -29,8 +33,15 @@ function createFakeClient(): EmailSuppressionClient & { rows: EmailSuppressionRo
async findUnique(args) {
return rows.find((r) => r.tenantId === args.where.tenantId_emailAddress.tenantId && r.emailAddress === args.where.tenantId_emailAddress.emailAddress) ?? null;
},
async findMany(args) {
client.findManyCalls += 1;
return rows
.filter((row) => row.tenantId === args.where.tenantId && args.where.emailAddress.in.includes(row.emailAddress))
.map(({ emailAddress }) => ({ emailAddress }));
},
},
};
return client;
}
describe("normalizeSuppressionAddress", () => {
@@ -71,3 +82,33 @@ describe("isEmailSuppressed", () => {
await expect(isEmailSuppressed({ tenantId: "t2", emailAddress: "blocked@x.test" }, client)).resolves.toBe(false);
});
});
describe("listSuppressedEmailAddresses", () => {
it("normalizes, deduplicates, tenant-scopes, and resolves a batch with one query", async () => {
const client = createFakeClient();
await recordEmailSuppression({ tenantId: "t1", emailAddress: "blocked@x.test", reason: "bounce" }, client);
await recordEmailSuppression({ tenantId: "t2", emailAddress: "other@x.test", reason: "bounce" }, client);
await expect(
listSuppressedEmailAddresses(
{ tenantId: "t1", emailAddresses: [" Blocked@X.test ", "blocked@x.test", "other@x.test"] },
client,
),
).resolves.toEqual(new Set(["blocked@x.test"]));
expect(client.findManyCalls).toBe(1);
});
it("does not query for an empty batch", async () => {
const client = createFakeClient();
await expect(listSuppressedEmailAddresses({ tenantId: "t1", emailAddresses: [] }, client)).resolves.toEqual(new Set());
expect(client.findManyCalls).toBe(0);
});
it("chunks recipient sets before they can approach the database parameter limit", async () => {
const client = createFakeClient();
const addresses = Array.from({ length: EMAIL_SUPPRESSION_QUERY_BATCH_SIZE + 1 }, (_, index) => `recipient-${index}@x.test`);
await expect(listSuppressedEmailAddresses({ tenantId: "t1", emailAddresses: addresses }, client)).resolves.toEqual(new Set());
expect(client.findManyCalls).toBe(2);
});
});