import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import test from 'node:test'; const root = process.cwd(); const read = (relative: string) => fs.readFileSync(path.join(root, relative), 'utf8'); test('D5.6.4/F4 generates inspection codes server-side with an annual transactional sequence', () => { const generator = read('src/inspection-visits/inspection-visit-code.ts'); assert.match(generator, /pg_advisory_xact_lock/); assert.match(generator, /America\/Argentina\/Mendoza/); assert.match(generator, /padStart\(5, '0'\)/); assert.match(generator, /return `INSP-/); assert.match(generator, /dateRow\.day/); assert.match(generator, /dateRow\.month/); assert.match(generator, /dateRow\.short_year/); }); test('D5.6.4/F4 creates one inspection from Area Operator, start and lead inspector without legacy title or end date', () => { const dto = read('src/inspection-visits/dto/create-inspection-visit.dto.ts'); const service = read('src/inspection-visits/inspection-visits.service.ts'); assert.doesNotMatch(dto, /code!/); assert.doesNotMatch(dto, /title!/); assert.doesNotMatch(dto, /plannedEndAt/); assert.match(dto, /operationalAreaId!/); assert.match(dto, /operatorCompanyId!/); assert.match(dto, /plannedStartAt!/); assert.match(dto, /leadInspectorUserId!/); assert.match(service, /const code = await nextInspectionVisitCode\(manager, plannedStartAt\)/); assert.doesNotMatch(service, /title: code/); assert.doesNotMatch(service, /plannedEndAt/); }); test('D5.6.4 assigns the lead inspector and generates the checklist in the same creation transaction', () => { const service = read('src/inspection-visits/inspection-visits.service.ts'); assert.match(service, /leadInspectorUserId: dto\.leadInspectorUserId/); assert.match(service, /await this\.replaceMemberLinks\(/); assert.match(service, /await this\.generateChecklistInternal\(manager, visit, principal\.userId\)/); }); test('D5.6.4/F4 uses the same inspection numbering and start-only planning for verification visits', () => { const dto = read('src/inspection-verifications/dto/plan-verification-visit.dto.ts'); const service = read('src/inspection-verifications/inspection-verifications.service.ts'); assert.doesNotMatch(dto, /plannedEndAt/); assert.match(service, /nextInspectionVisitCode\(manager, plannedStartAt\)/); assert.doesNotMatch(service, /plannedEndAt/); });