41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { ConflictException } from '@nestjs/common';
|
|
import type { DataSource, EntityManager } from 'typeorm';
|
|
import { InspectionActsService } from '../../src/inspection-acts/inspection-acts.service';
|
|
|
|
type SingleActGuard = {
|
|
assertVisitHasNoAct(manager: EntityManager, visitId: string): Promise<void>;
|
|
};
|
|
|
|
function serviceGuard(): SingleActGuard {
|
|
return new InspectionActsService(
|
|
{} as DataSource,
|
|
{} as never,
|
|
) as unknown as SingleActGuard;
|
|
}
|
|
|
|
test('single-act guard allows a visit without an act', async () => {
|
|
const manager = {
|
|
query: async () => [],
|
|
} as unknown as EntityManager;
|
|
|
|
await assert.doesNotReject(
|
|
serviceGuard().assertVisitHasNoAct(manager, 'visit-id'),
|
|
);
|
|
});
|
|
|
|
test('single-act guard rejects a second act for the same visit', async () => {
|
|
const manager = {
|
|
query: async () => [{ code: 'ACTA-2026-000001' }],
|
|
} as unknown as EntityManager;
|
|
|
|
await assert.rejects(
|
|
serviceGuard().assertVisitHasNoAct(manager, 'visit-id'),
|
|
(error: unknown) => error instanceof ConflictException
|
|
&& error.getResponse() instanceof Object
|
|
&& (error.getResponse() as { code?: string }).code
|
|
=== 'INSPECTION_VISIT_ACT_ALREADY_EXISTS',
|
|
);
|
|
});
|