diff --git a/src/models/ministryPlate.ts b/src/models/ministryPlate.ts index cd57cb3..577ae32 100644 --- a/src/models/ministryPlate.ts +++ b/src/models/ministryPlate.ts @@ -118,8 +118,8 @@ export class MinistryPlateDocument extends DocumentModel { tyreUseCode: techRecord.techRecord_tyreUseCode, axles: this.populateAxles( techRecord.techRecord_vehicleType === 'hgv' - ? (techRecord.techRecord_axles as HGVAxles[]) - : (techRecord.techRecord_axles as TRLAxles[]), + ? (techRecord.techRecord_axles as HGVAxles[] ?? []) + : (techRecord.techRecord_axles as TRLAxles[] ?? []), generateTrlEec, ), } diff --git a/tests/unit/ministryPlate.test.ts b/tests/unit/ministryPlate.test.ts index 4cc0407..7ebf8d4 100644 --- a/tests/unit/ministryPlate.test.ts +++ b/tests/unit/ministryPlate.test.ts @@ -76,6 +76,12 @@ describe('Document Model tests', () => { expect(document.PLATES_DATA.axles.axle4.weights.gbWeight).toBe('123'); }); + it('should not fail if no axles present', () => { + (request.techRecord as TechRecordType<'hgv', 'get'>).techRecord_axles = null as unknown as HGVAxles[]; + const document = new MinistryPlateDocument(request); + expect(document.PLATES_DATA.axles.axle1).toStrictEqual({}); + }); + it('should apply no water mark for prod', () => { process.env.BRANCH = 'prod'; const document = new MinistryPlateDocument(request);