feat: validate transport incident requires truck_id

Add 'transport' to INCIDENT_TYPES; add truck_id field to IncidentInput;
reject transport submissions missing truck_id.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CPf5Rc8QPx6V8KLEEgfKEQ
This commit is contained in:
2026-07-13 10:50:13 +08:00
co-authored by Claude Sonnet 4.6
parent ebeab27e5e
commit 6c1ad71643
2 changed files with 28 additions and 1 deletions
+4 -1
View File
@@ -1,4 +1,4 @@
export const INCIDENT_TYPES = ['injury', 'near_miss', 'hazard', 'asset_damage', 'environmental', 'security', 'fire'] as const export const INCIDENT_TYPES = ['injury', 'near_miss', 'hazard', 'asset_damage', 'environmental', 'security', 'fire', 'transport'] as const
export const MEDICAL_STATUSES = ['none', 'first_aid', 'medical_treatment', 'lti'] as const export const MEDICAL_STATUSES = ['none', 'first_aid', 'medical_treatment', 'lti'] as const
export type IncidentType = typeof INCIDENT_TYPES[number] export type IncidentType = typeof INCIDENT_TYPES[number]
@@ -12,6 +12,7 @@ export interface IncidentInput {
medical_status?: MedicalStatus medical_status?: MedicalStatus
asset_involved: boolean asset_involved: boolean
type_details?: Record<string, unknown> type_details?: Record<string, unknown>
truck_id?: string | null
} }
// Whitelisted type-specific intake fields per incident type (PRD §3). // Whitelisted type-specific intake fields per incident type (PRD §3).
@@ -76,6 +77,8 @@ export function validateIncidentInput(input: IncidentInput): { ok: boolean; erro
if (!INCIDENT_TYPES.includes(input.incident_type)) errors.push('incident_type is invalid') if (!INCIDENT_TYPES.includes(input.incident_type)) errors.push('incident_type is invalid')
if (input.injury_involved && !input.medical_status) errors.push('medical_status is required when injury is involved') if (input.injury_involved && !input.medical_status) errors.push('medical_status is required when injury is involved')
if (input.medical_status && !MEDICAL_STATUSES.includes(input.medical_status)) errors.push('medical_status is invalid') if (input.medical_status && !MEDICAL_STATUSES.includes(input.medical_status)) errors.push('medical_status is invalid')
if (input.incident_type === 'transport' && !input.truck_id?.trim())
errors.push('truck_id is required for transport incidents')
return { ok: errors.length === 0, errors } return { ok: errors.length === 0, errors }
} }
+24
View File
@@ -42,6 +42,30 @@ describe('validateIncidentInput', () => {
expect(result.ok).toBe(false) expect(result.ok).toBe(false)
expect(result.errors).toContain('incident_type is invalid') expect(result.errors).toContain('incident_type is invalid')
}) })
it('accepts transport type when truck_id is present', () => {
const r = validateIncidentInput({
zone_token: 'z',
incident_type: 'transport',
description: 'Truck clipped the dock frame reversing into bay 3.',
injury_involved: false,
asset_involved: false,
truck_id: 'truck-uuid',
} as any)
expect(r.ok).toBe(true)
})
it('rejects transport type without a truck_id', () => {
const r = validateIncidentInput({
zone_token: 'z',
incident_type: 'transport',
description: 'Truck clipped the dock frame reversing into bay 3.',
injury_involved: false,
asset_involved: false,
} as any)
expect(r.ok).toBe(false)
expect(r.errors).toContain('truck_id is required for transport incidents')
})
}) })
describe('validateTypeDetails', () => { describe('validateTypeDetails', () => {