Completes the escalation-event repository/service changes from the prior
commit: normalizes the exactOptionalPropertyTypes mismatch in the
findFirst fallback lookup, and updates every existing unit test
(sla-pause-resume, sla-breach-detection, sla-compliance-metric,
escalation-rule-match) to the new SlaRunRepository.updateWithVersion and
EscalationEventRepository.create({event, wasNewlyCreated}) signatures.
Full typecheck/lint/architecture-check clean.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { SlaService } from '@/modules/orchestration/sla/service/sla.service';
|
|
import { SLARun } from '@prisma/client';
|
|
|
|
function run(overrides: Partial<SLARun>): SLARun {
|
|
return {
|
|
id: 'run-1',
|
|
ticketId: 'ticket-1',
|
|
policyId: 'policy-1',
|
|
firstResponseDueAt: null,
|
|
resolutionDueAt: null,
|
|
status: 'running',
|
|
version: 1,
|
|
pausedAt: null,
|
|
resumedAt: null,
|
|
breachedAt: null,
|
|
firstResponseBreachedAt: null,
|
|
completedAt: null,
|
|
...overrides,
|
|
} as SLARun;
|
|
}
|
|
|
|
describe('SlaService.runBreachDetectionSweep', () => {
|
|
it('marks every running run past its resolution due date as breached and fires escalation', async () => {
|
|
const overdue = run({ id: 'r1', ticketId: 't1' });
|
|
const updateWithVersion = vi.fn().mockResolvedValue(overdue);
|
|
const runsRepo = {
|
|
findRunningPastResolutionDueAt: vi.fn().mockResolvedValue([overdue]),
|
|
findRunningPastFirstResponseDueAt: vi.fn().mockResolvedValue([]),
|
|
updateWithVersion,
|
|
} as never;
|
|
const handleBreach = vi.fn().mockResolvedValue(undefined);
|
|
const escalation = { handleBreach } as never;
|
|
|
|
const service = new SlaService(undefined, runsRepo, undefined, undefined, escalation);
|
|
await service.runBreachDetectionSweep();
|
|
|
|
expect(updateWithVersion).toHaveBeenCalledWith('r1', 1, expect.objectContaining({ status: 'breached' }));
|
|
expect(handleBreach).toHaveBeenCalledWith('t1', 'resolution_breach');
|
|
});
|
|
|
|
it('never touches a run that is not past its due date (the query itself excludes it — verified by trusting only what the repository returns)', async () => {
|
|
const runsRepo = {
|
|
findRunningPastResolutionDueAt: vi.fn().mockResolvedValue([]),
|
|
findRunningPastFirstResponseDueAt: vi.fn().mockResolvedValue([]),
|
|
updateWithVersion: vi.fn(),
|
|
} as never;
|
|
const handleBreach = vi.fn();
|
|
const service = new SlaService(undefined, runsRepo, undefined, undefined, {
|
|
handleBreach,
|
|
} as never);
|
|
|
|
await service.runBreachDetectionSweep();
|
|
expect(handleBreach).not.toHaveBeenCalled();
|
|
});
|
|
});
|