Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/worker/src/jobs/transactional-mail-outbox-bootstrap.test.ts
T

72 lines
2.6 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { bootstrapTransactionalMailOutbox, isTransactionalMailOutboxRequired } from "./transactional-mail-outbox-bootstrap.js";
import { TRANSACTIONAL_MAIL_OUTBOX_QUEUE } from "./transactional-mail-outbox.js";
function buildHandlerDeps() {
return {
enqueueMail: vi.fn(async () => undefined),
};
}
describe("bootstrapTransactionalMailOutbox", () => {
it("disables itself outside the mail worker group", () => {
const res = bootstrapTransactionalMailOutbox({ WORKER_QUEUE_GROUP: "general" } as Record<string, string>);
expect(res.status).toBe("disabled");
if (res.status === "disabled") expect(res.reason).toMatch(/non-mail/);
});
it("disables itself when the env flag is false", () => {
const res = bootstrapTransactionalMailOutbox({
WORKER_QUEUE_GROUP: "mail",
TRANSACTIONAL_MAIL_OUTBOX_ENABLED: "false",
} as Record<string, string>);
expect(res.status).toBe("disabled");
if (res.status === "disabled") expect(res.reason).toMatch(/TRANSACTIONAL_MAIL_OUTBOX_ENABLED/);
});
it("subscribes to outbox.mail on the mail worker group", () => {
const create = vi.fn(() => ({ name: TRANSACTIONAL_MAIL_OUTBOX_QUEUE, close: async () => undefined }));
const res = bootstrapTransactionalMailOutbox(
{ WORKER_QUEUE_GROUP: "mail" } as Record<string, string>,
{ handlerDeps: buildHandlerDeps(), createWorkerImpl: create },
);
expect(res.status).toBe("started");
expect(create).toHaveBeenCalledWith(
TRANSACTIONAL_MAIL_OUTBOX_QUEUE,
expect.any(Function),
expect.objectContaining({ concurrency: 5 }),
);
});
it("honours TRANSACTIONAL_MAIL_OUTBOX_CONCURRENCY", () => {
const create = vi.fn(() => ({ name: TRANSACTIONAL_MAIL_OUTBOX_QUEUE, close: async () => undefined }));
bootstrapTransactionalMailOutbox(
{
WORKER_QUEUE_GROUP: "mail",
TRANSACTIONAL_MAIL_OUTBOX_CONCURRENCY: "9",
} as Record<string, string>,
{ handlerDeps: buildHandlerDeps(), createWorkerImpl: create },
);
expect(create).toHaveBeenCalledWith(
TRANSACTIONAL_MAIL_OUTBOX_QUEUE,
expect.any(Function),
expect.objectContaining({ concurrency: 9 }),
);
});
it("treats required mode as mail-group only", () => {
expect(
isTransactionalMailOutboxRequired({
WORKER_QUEUE_GROUP: "mail",
TRANSACTIONAL_MAIL_OUTBOX_REQUIRED: "true",
} as Record<string, string>),
).toBe(true);
expect(
isTransactionalMailOutboxRequired({
WORKER_QUEUE_GROUP: "general",
TRANSACTIONAL_MAIL_OUTBOX_REQUIRED: "true",
} as Record<string, string>),
).toBe(false);
});
});