From 3f251d1c63cdbd809d5b1b527ed8f63924e5c940 Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:53:39 +0100 Subject: [PATCH 1/3] feat(cb2-13762): remove test code --- src/app/models/test-types/test-type.model.ts | 2 +- src/app/store/test-records/reducers/test-records.reducer.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/models/test-types/test-type.model.ts b/src/app/models/test-types/test-type.model.ts index f98f5fd0d..926ebde82 100644 --- a/src/app/models/test-types/test-type.model.ts +++ b/src/app/models/test-types/test-type.model.ts @@ -6,7 +6,7 @@ export interface TestType { testTypeId: string; testNumber: string; name: string; - testCode: string; + testCode?: string; testTypeName: string; testTypeStartTimestamp: string | Date; diff --git a/src/app/store/test-records/reducers/test-records.reducer.ts b/src/app/store/test-records/reducers/test-records.reducer.ts index 3d05829fc..c41f5822d 100644 --- a/src/app/store/test-records/reducers/test-records.reducer.ts +++ b/src/app/store/test-records/reducers/test-records.reducer.ts @@ -180,6 +180,9 @@ function cleanTestResultPayload(testResult: TestResultModel | undefined) { } const testTypes = testResult.testTypes.map((testType, index) => { + // Always remove testCode + delete testType.testCode; + // Remove empty requiredStandards from pass/prs non-voluntary IVA/MVSA tests if (index === 0) { const { testTypeId, requiredStandards } = testType; From 797078152e368bad10eb835e66f1a39be34a3269 Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Fri, 30 Aug 2024 12:45:43 +0100 Subject: [PATCH 2/3] fix(cb2-8973): move to resolver approach --- .../vehicle-header.component.ts | 8 ++--- .../create-test-records-routing.module.ts | 2 ++ .../resolvers/test-code/test-code.resolver.ts | 33 +++++++++++++++++++ .../test-result/test-result.resolver.ts | 4 +-- .../technical-record.service.ts | 19 +++++++++++ .../effects/test-records.effects.ts | 18 +--------- .../reducers/test-records.reducer.ts | 3 -- 7 files changed, 60 insertions(+), 27 deletions(-) create mode 100644 src/app/resolvers/test-code/test-code.resolver.ts diff --git a/src/app/features/test-records/components/vehicle-header/vehicle-header.component.ts b/src/app/features/test-records/components/vehicle-header/vehicle-header.component.ts index 33fedc060..bdb067ec1 100644 --- a/src/app/features/test-records/components/vehicle-header/vehicle-header.component.ts +++ b/src/app/features/test-records/components/vehicle-header/vehicle-header.component.ts @@ -1,4 +1,5 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; import { TestTypesTaxonomy } from '@api/test-types'; import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-vehicle-type'; import { TEST_TYPES_GROUP7 } from '@forms/models/testTypeId.enum'; @@ -8,7 +9,6 @@ import { TestResultModel } from '@models/test-results/test-result.model'; import { TestType, resultOfTestEnum } from '@models/test-types/test-type.model'; import { V3TechRecordModel, VehicleTypes } from '@models/vehicle-tech-record.model'; import { Store } from '@ngrx/store'; -import { TechnicalRecordService } from '@services/technical-record/technical-record.service'; import { TestTypesService } from '@services/test-types/test-types.service'; import { TagType, TagTypes } from '@shared/components/tag/tag.component'; import { techRecord } from '@store/technical-records'; @@ -28,8 +28,8 @@ export class VehicleHeaderComponent { constructor( private testTypesService: TestTypesService, - private techRecordService: TechnicalRecordService, - private store: Store + private store: Store, + private activatedRoute: ActivatedRoute ) {} get test(): TestType | undefined { @@ -78,7 +78,7 @@ export class VehicleHeaderComponent { } get testCode(): string | undefined { - const testCode = this.testResult?.testTypes[0].testCode; + const testCode = this.testResult?.testTypes[0].testCode || this.activatedRoute.snapshot?.data?.['testCode']; return testCode ? `(${testCode})` : ''; } diff --git a/src/app/features/test-records/create/create-test-records-routing.module.ts b/src/app/features/test-records/create/create-test-records-routing.module.ts index 791467732..7dc40c8c7 100644 --- a/src/app/features/test-records/create/create-test-records-routing.module.ts +++ b/src/app/features/test-records/create/create-test-records-routing.module.ts @@ -10,6 +10,7 @@ import { TestRecordCreateRoutes } from '@models/routes.enum'; import { contingencyTestResolver } from 'src/app/resolvers/contingency-test/contingency-test.resolver'; import { defectsTaxonomyResolver } from 'src/app/resolvers/defects-taxonomy/defects-taxonomy.resolver'; import { requiredStandardsResolver } from 'src/app/resolvers/required-standards/required-standards.resolver'; +import { testCodeResolver } from 'src/app/resolvers/test-code/test-code.resolver'; import { testStationsResolver } from 'src/app/resolvers/test-stations/test-stations.resolver'; import { testTypeTaxonomyResolver } from 'src/app/resolvers/test-type-taxonomy/test-type-taxonomy.resolver'; import { CreateTestRecordComponent } from './views/create-test-record/create-test-record.component'; @@ -38,6 +39,7 @@ const routes: Routes = [ TestTypeTaxonomy: testTypeTaxonomyResolver, defectTaxonomy: defectsTaxonomyResolver, testStations: testStationsResolver, + testCode: testCodeResolver, }, data: { title: 'Test details', roles: Roles.TestResultCreateContingency, breadcrumbPreserveQueryParams: true }, canActivate: [RoleGuard], diff --git a/src/app/resolvers/test-code/test-code.resolver.ts b/src/app/resolvers/test-code/test-code.resolver.ts new file mode 100644 index 000000000..9163eb373 --- /dev/null +++ b/src/app/resolvers/test-code/test-code.resolver.ts @@ -0,0 +1,33 @@ +import { inject } from '@angular/core'; +import { ResolveFn } from '@angular/router'; +import { TestTypesService } from '@api/test-types'; +import { Store, select } from '@ngrx/store'; +import { TechnicalRecordService } from '@services/technical-record/technical-record.service'; +import { techRecord } from '@store/technical-records'; +import { Observable, map, switchMap } from 'rxjs'; + +export const testCodeResolver: ResolveFn> = (route) => { + const store = inject(Store); + const testTypesService = inject(TestTypesService); + const techRecordService = inject(TechnicalRecordService); + const testTypeId: string | undefined = route.queryParams['testType']; + + // fetch test code from back-end (because its not provided by reference data) + return store.pipe( + select(techRecord), + switchMap((record) => { + return testTypesService.getTestTypesid( + String(testTypeId), + ['defaultTestCode'], + record!.techRecord_vehicleType, + techRecordService.getVehicleSize(record!) as string, + record!.techRecord_vehicleConfiguration!, + record!.techRecord_noOfAxles!, + record!.techRecord_euVehicleCategory!, + techRecordService.getVehicleClassDescription(record!) as string, + techRecordService.getVehicleSubClass(record!)?.[0] as string + ); + }), + map((response) => response.defaultTestCode) + ); +}; diff --git a/src/app/resolvers/test-result/test-result.resolver.ts b/src/app/resolvers/test-result/test-result.resolver.ts index f6d154926..90eab1b75 100644 --- a/src/app/resolvers/test-result/test-result.resolver.ts +++ b/src/app/resolvers/test-result/test-result.resolver.ts @@ -20,8 +20,6 @@ export const testResultResolver: ResolveFn = () => { return action$.pipe( ofType(fetchSelectedTestResultSuccess, fetchSelectedTestResultFailed), take(1), - map((action) => { - return action.type === fetchSelectedTestResultSuccess.type; - }) + map((action) => action.type === fetchSelectedTestResultSuccess.type) ); }; diff --git a/src/app/services/technical-record/technical-record.service.ts b/src/app/services/technical-record/technical-record.service.ts index c95648207..f397b456d 100644 --- a/src/app/services/technical-record/technical-record.service.ts +++ b/src/app/services/technical-record/technical-record.service.ts @@ -387,4 +387,23 @@ export class TechnicalRecordService { return false; } + + getVehicleSize(techRecord: V3TechRecordModel) { + return techRecord.techRecord_vehicleType === 'psv' ? techRecord.techRecord_vehicleSize : undefined; + } + + getVehicleClassDescription(techRecord: V3TechRecordModel) { + return techRecord.techRecord_vehicleType === 'psv' || + techRecord.techRecord_vehicleType === 'hgv' || + techRecord.techRecord_vehicleType === 'trl' || + techRecord.techRecord_vehicleType === 'motorcycle' + ? techRecord.techRecord_vehicleClass_description + : undefined; + } + + getVehicleSubClass(techRecord: V3TechRecordModel) { + return techRecord.techRecord_vehicleType === 'car' || techRecord.techRecord_vehicleType === 'lgv' + ? techRecord.techRecord_vehicleSubclass + : undefined; + } } diff --git a/src/app/store/test-records/effects/test-records.effects.ts b/src/app/store/test-records/effects/test-records.effects.ts index bc053bb57..aa08c8d8a 100644 --- a/src/app/store/test-records/effects/test-records.effects.ts +++ b/src/app/store/test-records/effects/test-records.effects.ts @@ -280,22 +280,7 @@ export class TestResultsEffects { take(1) ) ), - switchMap(([action, editedTestResult, testType, testStation, user]) => { - return this.testTypesService - .getTestTypesid( - String(testType?.id), - ['defaultTestCode'], - editedTestResult!.vehicleType, - editedTestResult!.vehicleSize, - editedTestResult!.vehicleConfiguration!, - editedTestResult!.noOfAxles, - editedTestResult!.euVehicleCategory!, - String(editedTestResult!.vehicleClass!), - String(editedTestResult!.vehicleSubclass!) - ) - .pipe(map((res) => [action, editedTestResult, testType, testStation, user, res.defaultTestCode] as const)); - }), - concatMap(([action, editedTestResult, testTypeTaxonomy, testStation, user, testCode]) => { + concatMap(([action, editedTestResult, testTypeTaxonomy, testStation, user]) => { const id = action.testType; const vehicleType = editedTestResult?.vehicleType; @@ -326,7 +311,6 @@ export class TestResultsEffects { }); mergedForms.testTypes[0].testTypeId = id; - mergedForms.testTypes[0].testCode = String(testCode); mergedForms.testTypes[0].name = testTypeTaxonomy?.name ?? ''; mergedForms.testTypes[0].testTypeName = testTypeTaxonomy?.testTypeName ?? ''; mergedForms.typeOfTest = (testTypeTaxonomy?.typeOfTest as TypeOfTest) ?? TypeOfTest.CONTINGENCY; diff --git a/src/app/store/test-records/reducers/test-records.reducer.ts b/src/app/store/test-records/reducers/test-records.reducer.ts index c41f5822d..3d05829fc 100644 --- a/src/app/store/test-records/reducers/test-records.reducer.ts +++ b/src/app/store/test-records/reducers/test-records.reducer.ts @@ -180,9 +180,6 @@ function cleanTestResultPayload(testResult: TestResultModel | undefined) { } const testTypes = testResult.testTypes.map((testType, index) => { - // Always remove testCode - delete testType.testCode; - // Remove empty requiredStandards from pass/prs non-voluntary IVA/MVSA tests if (index === 0) { const { testTypeId, requiredStandards } = testType; From 5fee241cdf22df01ef47f0d4a159af0d180eb4f9 Mon Sep 17 00:00:00 2001 From: pbardy2000 <146740183+pbardy2000@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:50:18 +0100 Subject: [PATCH 3/3] fix(cb2-8973): fix unit tests --- src/app/store/test-records/effects/test-records.effects.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/store/test-records/effects/test-records.effects.spec.ts b/src/app/store/test-records/effects/test-records.effects.spec.ts index 710e86505..17d07d9d9 100644 --- a/src/app/store/test-records/effects/test-records.effects.spec.ts +++ b/src/app/store/test-records/effects/test-records.effects.spec.ts @@ -671,7 +671,6 @@ describe('TestResultsEffects', () => { reasonForAbandoning: '', seatbeltInstallationCheckDate: false, secondaryCertificateNumber: null, - testCode: 'undefined', testExpiryDate: '', testResult: resultOfTestEnum.fail, testTypeEndTimestamp: '', @@ -768,7 +767,6 @@ describe('TestResultsEffects', () => { testResult: resultOfTestEnum.fail, testTypeEndTimestamp: '', testTypeId: '126', - testCode: 'undefined', testTypeName: '', testTypeStartTimestamp: '', },