Skip to content

Commit

Permalink
feat(cb2-1234): add axle sorting (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
naathanbrown committed Oct 25, 2024
1 parent 412da36 commit c28c23c
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 85 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ npm-audit.html
# idea specific hidden files
.idea/**
*.iml

# vscode
.vscode/**
61 changes: 0 additions & 61 deletions .vscode/launch.json

This file was deleted.

14 changes: 0 additions & 14 deletions .vscode/settings.json

This file was deleted.

17 changes: 9 additions & 8 deletions src/models/ministryPlate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
}
Expand Down Expand Up @@ -154,17 +154,18 @@ export class MinistryPlateDocument extends DocumentModel {
axle4: {},
} as Axles;
const terminatingCondition = Math.min(axles.length, 4);
const sortedAxles = axles.sort((a, b) => a.axleNumber - b.axleNumber);
for (let i = 0; i < terminatingCondition; i++) {
plateAxles[`axle${i + 1}`] = {
weights: {
gbWeight: axles[i].weights_gbWeight?.toString(),
eecWeight: generateTrlEec ? axles[i].weights_eecWeight?.toString() : null,
designWeight: axles[i].weights_designWeight?.toString(),
gbWeight: sortedAxles[i].weights_gbWeight?.toString(),
eecWeight: generateTrlEec ? sortedAxles[i].weights_eecWeight?.toString() : null,
designWeight: sortedAxles[i].weights_designWeight?.toString(),
},
tyres: {
tyreSize: axles[i].tyres_tyreSize,
plyRating: axles[i].tyres_dataTrAxles ?? axles[i].tyres_plyRating,
fitmentCode: axles[i].tyres_fitmentCode,
tyreSize: sortedAxles[i].tyres_tyreSize,
plyRating: sortedAxles[i].tyres_dataTrAxles ?? sortedAxles[i].tyres_plyRating,
fitmentCode: sortedAxles[i].tyres_fitmentCode,
},
};
}
Expand Down
92 changes: 90 additions & 2 deletions tests/unit/ministryPlate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Document Model tests', () => {
tyres_tyreSize: '1',
tyres_plyRating: '2',
tyres_fitmentCode: '3',
weights_gbWeight: 123,
weights_gbWeight: 321,
weights_eecWeight: 123,
weights_designWeight: 123,
},
Expand All @@ -73,7 +73,95 @@ describe('Document Model tests', () => {
},
] as unknown as HGVAxles[];
const document = new MinistryPlateDocument(request);
expect(document.PLATES_DATA.axles.axle4.weights.gbWeight).toBe('123');
expect(document.PLATES_DATA.axles.axle4.weights.gbWeight).toBe('321');
});

it('should order axles by axle number', () => {
(request.techRecord as TechRecordType<'hgv', 'get'>).techRecord_axles = [
{
axleNumber: 4,
tyres_tyreSize: '1',
tyres_plyRating: '2',
tyres_fitmentCode: '3',
weights_gbWeight: 4,
weights_eecWeight: 123,
weights_designWeight: 123,
},
{
axleNumber: 2,
tyres_tyreSize: '1',
tyres_plyRating: '2',
tyres_fitmentCode: '3',
weights_gbWeight: 2,
weights_eecWeight: 123,
weights_designWeight: 123,
},
{
axleNumber: 1,
tyres_tyreSize: '1',
tyres_plyRating: '2',
tyres_fitmentCode: '3',
weights_gbWeight: 1,
weights_eecWeight: 123,
weights_designWeight: 123,
},
{
axleNumber: 3,
tyres_tyreSize: '9',
tyres_plyRating: '9',
tyres_fitmentCode: '9',
weights_gbWeight: 3,
weights_eecWeight: 999,
weights_designWeight: 999,
},
] as unknown as HGVAxles[];
const document = new MinistryPlateDocument(request);
expect(document.PLATES_DATA.axles.axle4.weights.gbWeight).toBe('4');
expect(document.PLATES_DATA.axles.axle3.weights.gbWeight).toBe('3');
expect(document.PLATES_DATA.axles.axle2.weights.gbWeight).toBe('2');
expect(document.PLATES_DATA.axles.axle1.weights.gbWeight).toBe('1');
});

it('should remain order if no axle number and not fail', () => {
(request.techRecord as TechRecordType<'hgv', 'get'>).techRecord_axles = [
{
tyres_tyreSize: '1',
tyres_plyRating: '2',
tyres_fitmentCode: '3',
weights_gbWeight: 1,
weights_eecWeight: 123,
weights_designWeight: 123,
},
{
tyres_tyreSize: '1',
tyres_plyRating: '2',
tyres_fitmentCode: '3',
weights_gbWeight: 2,
weights_eecWeight: 123,
weights_designWeight: 123,
},
{
tyres_tyreSize: '1',
tyres_plyRating: '2',
tyres_fitmentCode: '3',
weights_gbWeight: 3,
weights_eecWeight: 123,
weights_designWeight: 123,
},
{
tyres_tyreSize: '9',
tyres_plyRating: '9',
tyres_fitmentCode: '9',
weights_gbWeight: 4,
weights_eecWeight: 999,
weights_designWeight: 999,
},
] as unknown as HGVAxles[];
const document = new MinistryPlateDocument(request);
expect(document.PLATES_DATA.axles.axle4.weights.gbWeight).toBe('4');
expect(document.PLATES_DATA.axles.axle3.weights.gbWeight).toBe('3');
expect(document.PLATES_DATA.axles.axle2.weights.gbWeight).toBe('2');
expect(document.PLATES_DATA.axles.axle1.weights.gbWeight).toBe('1');
});

it('should not fail if no axles present', () => {
Expand Down

0 comments on commit c28c23c

Please sign in to comment.