Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cb2-14876): add axle sorting #33

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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(),

Check warning on line 161 in src/models/ministryPlate.ts

View workflow job for this annotation

GitHub Actions / Build / build

Generic Object Injection Sink

Check warning on line 161 in src/models/ministryPlate.ts

View workflow job for this annotation

GitHub Actions / scanner

Generic Object Injection Sink
eecWeight: generateTrlEec ? sortedAxles[i].weights_eecWeight?.toString() : null,

Check warning on line 162 in src/models/ministryPlate.ts

View workflow job for this annotation

GitHub Actions / Build / build

Generic Object Injection Sink

Check warning on line 162 in src/models/ministryPlate.ts

View workflow job for this annotation

GitHub Actions / scanner

Generic Object Injection Sink
designWeight: sortedAxles[i].weights_designWeight?.toString(),

Check warning on line 163 in src/models/ministryPlate.ts

View workflow job for this annotation

GitHub Actions / Build / build

Generic Object Injection Sink

Check warning on line 163 in src/models/ministryPlate.ts

View workflow job for this annotation

GitHub Actions / scanner

Generic Object Injection Sink
},
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,

Check warning on line 166 in src/models/ministryPlate.ts

View workflow job for this annotation

GitHub Actions / Build / build

Generic Object Injection Sink

Check warning on line 166 in src/models/ministryPlate.ts

View workflow job for this annotation

GitHub Actions / scanner

Generic Object Injection Sink
plyRating: sortedAxles[i].tyres_dataTrAxles ?? sortedAxles[i].tyres_plyRating,

Check warning on line 167 in src/models/ministryPlate.ts

View workflow job for this annotation

GitHub Actions / Build / build

Generic Object Injection Sink

Check warning on line 167 in src/models/ministryPlate.ts

View workflow job for this annotation

GitHub Actions / scanner

Generic Object Injection Sink
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
Loading