-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagnostics.controller.test.ts
More file actions
46 lines (40 loc) · 1.68 KB
/
diagnostics.controller.test.ts
File metadata and controls
46 lines (40 loc) · 1.68 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
import 'reflect-metadata';
import { describe, it, expect, vi } from 'vitest';
import { DiagnosticsController } from './diagnostics.controller.js';
import type { DiagnosticsService } from '../services/DiagnosticsService.js';
vi.mock('../logger.js', () => ({
logger: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
}));
/** Build a DiagnosticsService stub. */
function makeDiagnostics(): DiagnosticsService {
return {
readTail: vi.fn().mockResolvedValue(['line1', 'line2', 'line3']),
getTodayLogPath: vi.fn().mockReturnValue('/var/log/app/main-2026-05-23.log'),
} as unknown as DiagnosticsService;
}
describe('DiagnosticsController', () => {
describe('getTail', () => {
it('should return lines from DiagnosticsService', async () => {
const svc = makeDiagnostics();
const result = await new DiagnosticsController(svc).getTail();
expect(result).toEqual({ lines: ['line1', 'line2', 'line3'] });
});
it('should call DiagnosticsService.readTail with 500 lines', async () => {
const svc = makeDiagnostics();
await new DiagnosticsController(svc).getTail();
expect(svc.readTail).toHaveBeenCalledWith(500);
});
});
describe('getPath', () => {
it('should return the current log path from DiagnosticsService', () => {
const svc = makeDiagnostics();
const result = new DiagnosticsController(svc).getPath();
expect(result).toEqual({ path: '/var/log/app/main-2026-05-23.log' });
});
it('should delegate to DiagnosticsService.getTodayLogPath', () => {
const svc = makeDiagnostics();
new DiagnosticsController(svc).getPath();
expect(svc.getTodayLogPath).toHaveBeenCalled();
});
});
});