forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.controller.spec.ts
More file actions
55 lines (48 loc) · 1.88 KB
/
Copy pathanalytics.controller.spec.ts
File metadata and controls
55 lines (48 loc) · 1.88 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
import { Test, TestingModule } from "@nestjs/testing";
import { AnalyticsController } from "./analytics.controller";
import { AnalyticsService } from "./analytics.service";
describe("AnalyticsController", () => {
let controller: AnalyticsController;
const mockService = {
getSpendingTrends: jest.fn(),
enqueueExport: jest.fn(),
getReportStatus: jest.fn(),
} as any;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AnalyticsController],
providers: [{ provide: AnalyticsService, useValue: mockService }],
}).compile();
controller = module.get<AnalyticsController>(AnalyticsController);
});
afterEach(() => jest.resetAllMocks());
it("delegates to service.getSpendingTrends", async () => {
mockService.getSpendingTrends.mockResolvedValue([
{ period: "2026-01-01", totalSpent: 100 },
]);
const result = await controller.getSpendingTrends({});
expect(result).toEqual([{ period: "2026-01-01", totalSpent: 100 }]);
expect(mockService.getSpendingTrends).toHaveBeenCalled();
});
it("delegates export request to service.enqueueExport", async () => {
mockService.enqueueExport.mockResolvedValue({
id: "report-123",
status: "pending",
});
const result = await controller.export({
type: "spending-trends",
format: "csv",
} as any);
expect(result).toEqual({ id: "report-123", status: "pending" });
expect(mockService.enqueueExport).toHaveBeenCalled();
});
it("delegates getReport to service.getReportStatus", async () => {
mockService.getReportStatus.mockResolvedValue({
id: "report-123",
status: "completed",
});
const result = await controller.getReport("report-123");
expect(result).toEqual({ id: "report-123", status: "completed" });
expect(mockService.getReportStatus).toHaveBeenCalledWith("report-123");
});
});