Files
ims/tests/lib/pdf/incident-report.test.ts
T

78 lines
2.4 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { buildIncidentReportPdf, type IncidentReportData } from '@/lib/pdf/incident-report'
const MOCK: IncidentReportData = {
referenceNo: 'SC1-202607-0001',
incidentType: 'injury',
reportedAt: '2026-07-01T08:00:00.000Z',
siteName: 'Setia Warehouse KL',
zoneName: 'Loading Bay A',
reporterName: 'Ahmad Bin Ali',
severity: 3,
medicalStatus: 'first_aid',
description: 'Worker slipped on wet floor near loading bay.',
injuryInvolved: true,
assetInvolved: false,
isFatality: false,
isSeriousBodilyInjury: false,
isDangerousOccurrence: false,
isOccupationalDisease: false,
lostDays: null,
triagedBy: 'Supervisor Tan',
triagedAt: '2026-07-01T10:00:00.000Z',
triageNotes: 'Reviewed on-site. First aid applied.',
investigation: {
method: 'five_why',
findingsText: 'Floor was wet due to a leaking pipe.',
rootCauseSummary: 'Maintenance backlog on pipe inspection.',
alcoholTestResult: 'negative',
urineTestResult: 'negative',
},
capas: [
{
description: 'Install non-slip mats in loading bay.',
ownerName: 'Maintenance Dept',
department: 'Maintenance',
dueDate: '2026-07-15',
priority: 'high',
status: 'closed',
completedAt: '2026-07-14T09:00:00.000Z',
ownerNotes: 'Mats installed and inspected.',
},
],
addenda: [
{
authorName: 'HSE Officer Lim',
createdAt: '2026-07-20T14:00:00.000Z',
body: 'Follow-up inspection passed. Area cleared.',
},
],
closedAt: '2026-07-20T15:00:00.000Z',
}
describe('buildIncidentReportPdf', () => {
it('returns a Uint8Array starting with PDF magic bytes', async () => {
const result = await buildIncidentReportPdf(MOCK)
expect(result).toBeInstanceOf(Uint8Array)
// PDF files start with %PDF
const header = String.fromCharCode(...result.slice(0, 4))
expect(header).toBe('%PDF')
})
it('handles incident with no investigation, CAPAs, or addenda', async () => {
const minimal: IncidentReportData = {
...MOCK,
triagedBy: null,
triagedAt: null,
triageNotes: null,
investigation: null,
capas: [],
addenda: [],
}
const result = await buildIncidentReportPdf(minimal)
expect(result).toBeInstanceOf(Uint8Array)
const header = String.fromCharCode(...result.slice(0, 4))
expect(header).toBe('%PDF')
})
})