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
+89
@@ -0,0 +1,89 @@
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import type { LegacyEventWebhookAttempt } from "@hivegrid/db/event-webhook-attempts.server";
|
||||
|
||||
// Override only the Redis-connection resolver + the lazily-imported runtime
|
||||
// queue factory so the "owned queue" branch (the API builds its own queue from
|
||||
// the resolved connection, then closes it in `finally`) runs without Redis.
|
||||
const { resolveRedisConnectionOptionsMock, createQueueMock, addMock, closeMock } = vi.hoisted(() => {
|
||||
const addMock = vi.fn();
|
||||
const closeMock = vi.fn().mockResolvedValue(undefined);
|
||||
return {
|
||||
addMock,
|
||||
closeMock,
|
||||
resolveRedisConnectionOptionsMock: vi.fn(),
|
||||
createQueueMock: vi.fn(() => ({ add: addMock, close: closeMock })),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@hivegrid/queue", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@hivegrid/queue")>();
|
||||
return { ...actual, resolveRedisConnectionOptions: resolveRedisConnectionOptionsMock };
|
||||
});
|
||||
|
||||
vi.mock("@hivegrid/queue/runtime", () => ({
|
||||
createQueue: createQueueMock,
|
||||
}));
|
||||
|
||||
const { queueLegacyEventWebhookAttemptDelivery } = await import("./webhookDeliveryQueue.js");
|
||||
|
||||
const attempt = {
|
||||
id: "attempt_owned_1",
|
||||
endpoint: "https://example.test/webhooks/events",
|
||||
tenantId: "tenant_owned",
|
||||
} satisfies LegacyEventWebhookAttempt;
|
||||
|
||||
const body = { id: "evt_owned", type: "member.created" };
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
closeMock.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("queueLegacyEventWebhookAttemptDelivery (self-owned queue)", () => {
|
||||
test("returns missing-redis-connection when no connection can be resolved", async () => {
|
||||
resolveRedisConnectionOptionsMock.mockReturnValue(undefined);
|
||||
|
||||
const result = await queueLegacyEventWebhookAttemptDelivery({ attempt, body, env: {} });
|
||||
|
||||
expect(result).toEqual({ enqueued: false, reason: "missing-redis-connection" });
|
||||
expect(createQueueMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("builds, enqueues on, and then closes a self-owned queue", async () => {
|
||||
resolveRedisConnectionOptionsMock.mockReturnValue({ host: "127.0.0.1", port: 6379 });
|
||||
const job = { id: "job_owned_1" };
|
||||
addMock.mockResolvedValue(job);
|
||||
|
||||
const result = await queueLegacyEventWebhookAttemptDelivery({
|
||||
attempt,
|
||||
body,
|
||||
requestId: "req_owned",
|
||||
env: { REDIS_URL: "redis://127.0.0.1:6379" } as never,
|
||||
});
|
||||
|
||||
expect(createQueueMock).toHaveBeenCalledTimes(1);
|
||||
expect(createQueueMock).toHaveBeenCalledWith("hivegrid.email", {
|
||||
connection: { host: "127.0.0.1", port: 6379 },
|
||||
});
|
||||
expect(addMock).toHaveBeenCalledTimes(1);
|
||||
expect(result).toEqual({ enqueued: true, job });
|
||||
// The owned queue must be closed exactly once after enqueueing.
|
||||
expect(closeMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("closes the self-owned queue even when enqueue fails", async () => {
|
||||
resolveRedisConnectionOptionsMock.mockReturnValue({ host: "127.0.0.1", port: 6379 });
|
||||
const error = new Error("enqueue exploded");
|
||||
addMock.mockRejectedValue(error);
|
||||
|
||||
await expect(
|
||||
queueLegacyEventWebhookAttemptDelivery({ attempt, body, env: { REDIS_URL: "redis://x" } as never }),
|
||||
).rejects.toThrow(error);
|
||||
|
||||
expect(closeMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user