Phase 5 (usability + compliance): - In-app notification bell/badge: migration 016 adds read state + per-user RLS + create_in_app_notification SECURITY DEFINER RPC; /api/notifications; wired into incident creation, CAPA assign/verify, escalation cron - Incident closure: new POST /api/incidents/[id]/close (requires verification status + all CAPAs verified); migration 017 locks closed incidents at DB level (update/delete triggers) with append-only incident_addenda + UI panel - Server-side pagination on HSE/supervisor incident inboxes (.range, 25/page) - Investigation form: alcohol/urine test result + witness statement refs (existing schema columns, now editable) - Type-specific intake fields: migration 018 adds incidents.type_details JSONB; whitelist validation; environmental/asset/security/fire field groups in report form; EN/MS/ZH labels; offline queue support - JKKP 8 annual register CSV export (/api/reports/jkkp8) + dashboard button + January statutory deadline banner - Admin page: user invite (service-role client), role/site/active management, site + zone CRUD with QR report links — replaces Phase 0 stub - Evidence gallery thumbnails via Supabase render transform with fallback Phase 6 (analytics): - 12-month stacked trend chart (leading/lagging/other) + top root causes (lib/dashboard/trends.ts pure helpers) - AI rising-risk zones: /api/dashboard/ai/risk-flags aggregates 90-day zone stats, claude-opus-4-8 forced tool_use, panel on HSE + management dashboards, suggestion audit-logged Also fixes 9 pre-existing missing /ims basePath prefixes in client fetches and download links. 132 tests passing, tsc clean, next build clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CPf5Rc8QPx6V8KLEEgfKEQ
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { buildJkkp8Rows, jkkp8Csv, type Jkkp8Incident } from '@/lib/reports/jkkp8'
|
|
|
|
function makeIncident(overrides: Partial<Jkkp8Incident> = {}): Jkkp8Incident {
|
|
return {
|
|
reference_no: 'SETIA-202607-0001',
|
|
incident_type: 'injury',
|
|
description: 'Fell from ladder',
|
|
reported_at: '2026-07-01T08:00:00Z',
|
|
medical_status: 'lti',
|
|
lost_days: 5,
|
|
is_fatality: false,
|
|
is_serious_bodily_injury: false,
|
|
is_dangerous_occurrence: false,
|
|
is_occupational_disease: false,
|
|
sites: { name: 'Setia Alam' },
|
|
zones: { name: 'Dock 3' },
|
|
reporter: { name: 'Ali' },
|
|
dosh_reports: [],
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
describe('buildJkkp8Rows', () => {
|
|
it('includes incidents with lost_days >= 4', () => {
|
|
const rows = buildJkkp8Rows([makeIncident()])
|
|
expect(rows).toHaveLength(1)
|
|
expect(rows[0].obligation).toContain('Lost-time injury')
|
|
expect(rows[0].filing_status).toBe('pending')
|
|
})
|
|
|
|
it('excludes non-reportable incidents', () => {
|
|
const rows = buildJkkp8Rows([
|
|
makeIncident({ lost_days: 1, medical_status: 'first_aid' }),
|
|
])
|
|
expect(rows).toHaveLength(0)
|
|
})
|
|
|
|
it('includes occupational disease (JKKP 7/8 path)', () => {
|
|
const rows = buildJkkp8Rows([
|
|
makeIncident({ lost_days: 0, is_occupational_disease: true }),
|
|
])
|
|
expect(rows).toHaveLength(1)
|
|
expect(rows[0].obligation).toContain('Occupational disease')
|
|
})
|
|
|
|
it('summarises dosh filing status when reports exist', () => {
|
|
const rows = buildJkkp8Rows([
|
|
makeIncident({
|
|
dosh_reports: [
|
|
{ form_type: 'jkkp6', status: 'submitted', submitted_at: '2026-07-03T10:00:00Z' },
|
|
],
|
|
}),
|
|
])
|
|
expect(rows[0].filing_status).toBe('JKKP6: submitted (2026-07-03)')
|
|
})
|
|
})
|
|
|
|
describe('jkkp8Csv', () => {
|
|
it('escapes commas and quotes in descriptions', () => {
|
|
const rows = buildJkkp8Rows([
|
|
makeIncident({ description: 'Slip, near "dock" area' }),
|
|
])
|
|
const csv = jkkp8Csv(rows)
|
|
expect(csv).toContain('"Slip, near ""dock"" area"')
|
|
expect(csv.split('\r\n')).toHaveLength(2)
|
|
})
|
|
})
|