|
| 1 | +import { RunInsightsController } from './run-insights.controller'; |
| 2 | +import { RunInsightsService } from '../insights/run-insights.service'; |
| 3 | + |
| 4 | +describe('RunInsightsController', () => { |
| 5 | + let controller: RunInsightsController; |
| 6 | + let mockInsightsService: { |
| 7 | + exportRun: jest.Mock; |
| 8 | + compareRuns: jest.Mock; |
| 9 | + }; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + mockInsightsService = { |
| 13 | + exportRun: jest.fn(), |
| 14 | + compareRuns: jest.fn() |
| 15 | + }; |
| 16 | + controller = new RunInsightsController( |
| 17 | + mockInsightsService as unknown as RunInsightsService |
| 18 | + ); |
| 19 | + }); |
| 20 | + |
| 21 | + describe('exportRun', () => { |
| 22 | + it('delegates to insightsService.exportRun with options', async () => { |
| 23 | + const bundle = { run: { id: 'run-1' }, exportedAt: '2026-01-01T00:00:00Z' }; |
| 24 | + mockInsightsService.exportRun.mockResolvedValue(bundle); |
| 25 | + |
| 26 | + const query = { includeCanonical: true, includeRaw: false, eventLimit: 500 }; |
| 27 | + const result = await controller.exportRun('run-1', query as any); |
| 28 | + |
| 29 | + expect(mockInsightsService.exportRun).toHaveBeenCalledWith('run-1', { |
| 30 | + includeCanonical: true, |
| 31 | + includeRaw: false, |
| 32 | + eventLimit: 500 |
| 33 | + }); |
| 34 | + expect(result).toEqual(bundle); |
| 35 | + }); |
| 36 | + |
| 37 | + it('passes undefined options when query is empty', async () => { |
| 38 | + mockInsightsService.exportRun.mockResolvedValue({}); |
| 39 | + |
| 40 | + await controller.exportRun('run-1', {} as any); |
| 41 | + |
| 42 | + expect(mockInsightsService.exportRun).toHaveBeenCalledWith('run-1', { |
| 43 | + includeCanonical: undefined, |
| 44 | + includeRaw: undefined, |
| 45 | + eventLimit: undefined |
| 46 | + }); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + describe('compareRuns', () => { |
| 51 | + it('delegates to insightsService.compareRuns', async () => { |
| 52 | + const comparison = { statusMatch: true, left: {}, right: {} }; |
| 53 | + mockInsightsService.compareRuns.mockResolvedValue(comparison); |
| 54 | + |
| 55 | + const body = { leftRunId: 'run-1', rightRunId: 'run-2' }; |
| 56 | + const result = await controller.compareRuns(body as any); |
| 57 | + |
| 58 | + expect(mockInsightsService.compareRuns).toHaveBeenCalledWith('run-1', 'run-2'); |
| 59 | + expect(result).toEqual(comparison); |
| 60 | + }); |
| 61 | + }); |
| 62 | +}); |
0 commit comments