forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-webhooks.controller.spec.ts
More file actions
65 lines (51 loc) · 1.93 KB
/
Copy pathadmin-webhooks.controller.spec.ts
File metadata and controls
65 lines (51 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Test, TestingModule } from "@nestjs/testing";
import { AdminWebhooksController } from "./admin-webhooks.controller";
import { WebhooksService } from "./webhooks.service";
describe("AdminWebhooksController", () => {
let controller: AdminWebhooksController;
const mockWebhooksService = {
listDeadLetters: jest.fn(),
getDeadLetter: jest.fn(),
retryDeadLetter: jest.fn(),
};
beforeEach(async () => {
jest.clearAllMocks();
const module: TestingModule = await Test.createTestingModule({
controllers: [AdminWebhooksController],
providers: [{ provide: WebhooksService, useValue: mockWebhooksService }],
}).compile();
controller = module.get<AdminWebhooksController>(AdminWebhooksController);
});
it("lists dead-letter jobs", async () => {
mockWebhooksService.listDeadLetters.mockResolvedValue([{ id: "dlq-1" }]);
const result = await controller.listDeadLetters({
status: "pending_retry" as any,
limit: 20,
});
expect(result).toEqual([{ id: "dlq-1" }]);
expect(mockWebhooksService.listDeadLetters).toHaveBeenCalledWith({
status: "pending_retry",
limit: 20,
});
});
it("returns a single dead-letter job", async () => {
mockWebhooksService.getDeadLetter.mockResolvedValue({ id: "dlq-2" });
const result = await controller.getDeadLetter("dlq-2");
expect(result).toEqual({ id: "dlq-2" });
expect(mockWebhooksService.getDeadLetter).toHaveBeenCalledWith("dlq-2");
});
it("queues a retry for a dead-letter job", async () => {
mockWebhooksService.retryDeadLetter.mockResolvedValue({
deadLetterId: "dlq-3",
deliveryId: "del-3",
status: "requeued",
});
const result = await controller.retryDeadLetter("dlq-3");
expect(result).toEqual({
deadLetterId: "dlq-3",
deliveryId: "del-3",
status: "requeued",
});
expect(mockWebhooksService.retryDeadLetter).toHaveBeenCalledWith("dlq-3");
});
});