Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { queueNames, type TypedQueue } from "@hivegrid/queue";
|
||||
import { createQueuedMailProvider } from "./queue.js";
|
||||
import { MailProviderError } from "./types.js";
|
||||
|
||||
function createQueueMock() {
|
||||
return {
|
||||
add: vi.fn(async () => ({ id: "job_123" })),
|
||||
close: vi.fn(async () => undefined),
|
||||
} as unknown as TypedQueue<typeof queueNames.email> & {
|
||||
add: ReturnType<typeof vi.fn>;
|
||||
close: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
}
|
||||
|
||||
describe("QueuedMailProvider recipient validation", () => {
|
||||
test("rejects an empty recipient list before building a job descriptor", async () => {
|
||||
const queue = createQueueMock();
|
||||
const provider = createQueuedMailProvider({ queue });
|
||||
|
||||
await expect(provider.send({ to: [], subject: "Welcome", text: "Hello" })).rejects.toMatchObject({
|
||||
provider: "queue",
|
||||
message: "At least one recipient is required.",
|
||||
} satisfies Partial<MailProviderError>);
|
||||
expect(queue.add).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("QueuedMailProvider sendAt normalization", () => {
|
||||
test("passes a numeric unix-seconds sendAt through unchanged", async () => {
|
||||
const queue = createQueueMock();
|
||||
const provider = createQueuedMailProvider({ queue });
|
||||
const epochSeconds = 1_778_580_000;
|
||||
|
||||
await provider.send({ to: ["user@example.com"], subject: "Later", text: "Hello", sendAt: epochSeconds });
|
||||
|
||||
expect(queue.add).toHaveBeenCalledWith(
|
||||
"send-transactional-email",
|
||||
expect.objectContaining({ sendAt: epochSeconds }),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
test("converts a Date sendAt to floored unix seconds", async () => {
|
||||
const queue = createQueueMock();
|
||||
const provider = createQueuedMailProvider({ queue });
|
||||
|
||||
await provider.send({
|
||||
to: ["user@example.com"],
|
||||
subject: "Later",
|
||||
text: "Hello",
|
||||
// 1.999s past the second boundary must floor down, not round up.
|
||||
sendAt: new Date(1_778_580_001_999),
|
||||
});
|
||||
|
||||
expect(queue.add).toHaveBeenCalledWith(
|
||||
"send-transactional-email",
|
||||
expect.objectContaining({ sendAt: 1_778_580_001 }),
|
||||
expect.any(Object)
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user