63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { queueNames, type TypedQueue } from "@hivegrid/queue";
|
|
|
|
import { GDPR_USER_SELF_EXPORT_TYPE, enqueueGdprExport } from "./gdprExportQueue.server";
|
|
|
|
function createQueueMock(jobId = "queued-job"): TypedQueue<typeof queueNames.exports> & { add: ReturnType<typeof vi.fn>; close: ReturnType<typeof vi.fn> } {
|
|
return {
|
|
add: vi.fn(async () => ({ id: jobId })),
|
|
close: vi.fn(async () => undefined),
|
|
} as unknown as TypedQueue<typeof queueNames.exports> & { add: ReturnType<typeof vi.fn>; close: ReturnType<typeof vi.fn> };
|
|
}
|
|
|
|
describe("enqueueGdprExport", () => {
|
|
it("enqueues a GDPR self-export on the shared export queue", async () => {
|
|
const queue = createQueueMock("bullmq_job_1");
|
|
|
|
await expect(
|
|
enqueueGdprExport(
|
|
{
|
|
exportJobId: "gdpr_export_1",
|
|
tenantId: "tenant_1",
|
|
requestedByUserId: "user_1",
|
|
scope: "user_self",
|
|
targetUserId: "user_1",
|
|
requestId: "req_1",
|
|
},
|
|
{ queue },
|
|
),
|
|
).resolves.toEqual({ enqueued: true, jobId: "bullmq_job_1" });
|
|
|
|
expect(queue.add).toHaveBeenCalledWith(
|
|
"run-export",
|
|
expect.objectContaining({
|
|
kind: "export.run",
|
|
exportJobId: "gdpr_export_1",
|
|
tenantId: "tenant_1",
|
|
requestedByUserId: "user_1",
|
|
exportType: GDPR_USER_SELF_EXPORT_TYPE,
|
|
format: "json",
|
|
requestId: "req_1",
|
|
metadata: { scope: "user_self", targetUserId: "user_1" },
|
|
}),
|
|
expect.objectContaining({ jobId: "gdpr_export_1" }),
|
|
);
|
|
expect(queue.close).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("returns queue-unavailable when no queue or Redis connection is configured", async () => {
|
|
await expect(
|
|
enqueueGdprExport(
|
|
{
|
|
exportJobId: "gdpr_export_1",
|
|
tenantId: "tenant_1",
|
|
requestedByUserId: "user_1",
|
|
scope: "user_self",
|
|
},
|
|
{ env: {} },
|
|
),
|
|
).resolves.toEqual({ enqueued: false, reason: "queue-unavailable" });
|
|
});
|
|
});
|