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

fix(cb2-8973): use correct vehicle class #1572

Merged
merged 9 commits into from
Sep 4, 2024
14 changes: 11 additions & 3 deletions src/app/interceptors/error-handling/error-handling.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ export interface HttpResponseRedirectConfig {
* The route to redirect to
*/
redirectTo?: string;
/**
* Blacklist urls from the given behaviour
*/
blacklist?: string[];
}
type InternalConfig = Required<Pick<HttpResponseRedirectConfig, 'httpStatusRedirect' | 'redirectTo'>>;

type InternalConfig = Required<Pick<HttpResponseRedirectConfig, 'httpStatusRedirect' | 'redirectTo' | 'blacklist'>>;

@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
config: InternalConfig;

private readonly defaultConfig = { httpStatusRedirect: [500], redirectTo: 'error' };
private readonly defaultConfig = { httpStatusRedirect: [500], redirectTo: 'error', blacklist: [] };

constructor(
private router: Router,
Expand All @@ -34,7 +39,10 @@ export class ErrorInterceptor implements HttpInterceptor {
return next.handle(request).pipe(
catchError((error) => {
if (error instanceof HttpErrorResponse) {
if (this.config.httpStatusRedirect.includes(error.status)) {
if (
this.config.httpStatusRedirect.includes(error.status) &&
!this.config.blacklist?.some((url) => request.url.includes(url))
) {
void this.router.navigateByUrl(this.config.redirectTo);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/interceptors/interceptor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { ErrorInterceptorModule } from './error-handling/error-handling.module';
backoff: true,
whiteList: ['document-retrieval'],
}),
ErrorInterceptorModule.forRoot({ httpStatusRedirect: [500], redirectTo: 'error' }),
// @TODO - Remove blacklisted paths once source of 500 errors are resolved
ErrorInterceptorModule.forRoot({ httpStatusRedirect: [500], redirectTo: 'error', blacklist: ['/test-types/'] }),
],
})
export class InterceptorModule {}
7 changes: 4 additions & 3 deletions src/app/resolvers/test-code/test-code.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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';
import { Observable, catchError, map, of, switchMap } from 'rxjs';

export const testCodeResolver: ResolveFn<Observable<string | undefined>> = (route) => {
const store = inject(Store);
Expand All @@ -24,10 +24,11 @@ export const testCodeResolver: ResolveFn<Observable<string | undefined>> = (rout
record!.techRecord_vehicleConfiguration!,
record!.techRecord_noOfAxles!,
record!.techRecord_euVehicleCategory!,
techRecordService.getVehicleClassDescription(record!) as string,
techRecordService.getVehicleClass(record!) as string,
techRecordService.getVehicleSubClass(record!)?.[0] as string
);
}),
map((response) => response.defaultTestCode)
map((response) => response.defaultTestCode),
catchError(() => of('')) // ensure error response doesn't prevent test creation
);
};
207 changes: 207 additions & 0 deletions src/app/services/technical-record/technical-record.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,4 +837,211 @@ describe('TechnicalRecordService', () => {
expect(spy).toHaveBeenCalledWith(SEARCH_TYPES.VRM, 'new vrm');
});
});

describe('getVehicleSize', () => {
it('should return the vehicle size of the provided tech record, if the vehicle type is a PSV', () => {
const techRecord = {
techRecord_vehicleType: VehicleTypes.PSV,
techRecord_bodyType: 'body type',
techRecord_seatsLowerDeck: 10,
techRecord_seatsUpperDeck: 12,
techRecord_vehicleSize: 22,
} as unknown as V3TechRecordModel;

expect(service.getVehicleSize(techRecord)).toBe(22);
});

it('should return undefined when the provided tech record is not a PSV', () => {
const techRecord = {
techRecord_vehicleType: VehicleTypes.HGV,
techRecord_bodyType: 'body type',
} as unknown as V3TechRecordModel;

expect(service.getVehicleSize(techRecord)).toBeUndefined();
});
});

describe('getVehicleClassDescription', () => {
it('should return the vehicle class description for PSV, HGV, TRL and Motorcycles', () => {
const psv = {
techRecord_vehicleType: VehicleTypes.PSV,
techRecord_bodyType: 'body type',
techRecord_seatsLowerDeck: 10,
techRecord_seatsUpperDeck: 12,
techRecord_vehicleSize: 22,
techRecord_vehicleClass_description: 'vehicle class description',
} as unknown as V3TechRecordModel;

const hgv = {
techRecord_vehicleType: VehicleTypes.HGV,
techRecord_bodyType: 'body type',
techRecord_vehicleClass_description: 'vehicle class description',
} as unknown as V3TechRecordModel;

const trl = {
techRecord_vehicleType: VehicleTypes.TRL,
techRecord_bodyType: 'body type',
techRecord_vehicleClass_description: 'vehicle class description',
} as unknown as V3TechRecordModel;

const motorcycle = {
techRecord_vehicleType: VehicleTypes.MOTORCYCLE,
techRecord_bodyType: 'body type',
techRecord_vehicleClass_description: 'vehicle class description',
} as unknown as V3TechRecordModel;

expect(service.getVehicleClassDescription(psv)).toBe('vehicle class description');
expect(service.getVehicleClassDescription(hgv)).toBe('vehicle class description');
expect(service.getVehicleClassDescription(trl)).toBe('vehicle class description');
expect(service.getVehicleClassDescription(motorcycle)).toBe('vehicle class description');
});

it('should return undefined when the vehicle type is not PSV, HGV, TRL or Motorcycle', () => {
const car = {
techRecord_vehicleType: VehicleTypes.CAR,
techRecord_bodyType: 'body type',
} as unknown as V3TechRecordModel;

expect(service.getVehicleClassDescription(car)).toBeUndefined();
});
});

describe('getVehicleClassCode', () => {
it('should return the vehicle class code for complete motorcycles', () => {
const motorcycle = {
techRecord_vehicleType: VehicleTypes.MOTORCYCLE,
techRecord_bodyType: 'body type',
techRecord_recordCompleteness: 'complete',
techRecord_vehicleClass_code: 'vehicle class code',
} as unknown as V3TechRecordModel;

expect(service.getVehicleClassCode(motorcycle)).toBe('vehicle class code');
});

it('should return undefined for incomplete motorcycles', () => {
const motorcycle = {
techRecord_vehicleType: VehicleTypes.MOTORCYCLE,
techRecord_bodyType: 'body type',
techRecord_recordCompleteness: 'incomplete',
techRecord_vehicleClass_code: 'vehicle class code',
} as unknown as V3TechRecordModel;

expect(service.getVehicleClassCode(motorcycle)).toBeUndefined();
});

it('should return undefined for non motorcycles', () => {
const car = {
techRecord_vehicleType: VehicleTypes.CAR,
techRecord_bodyType: 'body type',
techRecord_recordCompleteness: 'complete',
} as unknown as V3TechRecordModel;

expect(service.getVehicleClassCode(car)).toBeUndefined();
});
});

describe('getVehicleClass', () => {
it('should return the vehicle class code for a complete motorcycle', () => {
const motorcycle = {
techRecord_vehicleType: VehicleTypes.MOTORCYCLE,
techRecord_bodyType: 'body type',
techRecord_recordCompleteness: 'complete',
techRecord_vehicleClass_code: 'vehicle class code',
} as unknown as V3TechRecordModel;

expect(service.getVehicleClass(motorcycle)).toBe('vehicle class code');
});

it('should return the vehicle class description for PSVs, HGVs and TRLs', () => {
const psv = {
techRecord_vehicleType: VehicleTypes.PSV,
techRecord_bodyType: 'body type',
techRecord_seatsLowerDeck: 10,
techRecord_seatsUpperDeck: 12,
techRecord_vehicleSize: 22,
techRecord_vehicleClass_description: 'vehicle class description',
} as unknown as V3TechRecordModel;

const hgv = {
techRecord_vehicleType: VehicleTypes.HGV,
techRecord_bodyType: 'body type',
techRecord_vehicleClass_description: 'vehicle class description',
} as unknown as V3TechRecordModel;

const trl = {
techRecord_vehicleType: VehicleTypes.TRL,
techRecord_bodyType: 'body type',
techRecord_vehicleClass_description: 'vehicle class description',
} as unknown as V3TechRecordModel;

expect(service.getVehicleClass(psv)).toBe('vehicle class description');
expect(service.getVehicleClass(hgv)).toBe('vehicle class description');
expect(service.getVehicleClass(trl)).toBe('vehicle class description');
});

it('should return undefined for CARs and LGVs', () => {
const car = {
techRecord_vehicleType: VehicleTypes.CAR,
techRecord_bodyType: 'body type',
} as unknown as V3TechRecordModel;

const lgv = {
techRecord_vehicleType: VehicleTypes.LGV,
techRecord_bodyType: 'body type',
} as unknown as V3TechRecordModel;

expect(service.getVehicleClass(car)).toBeUndefined();
expect(service.getVehicleClass(lgv)).toBeUndefined();
});
});

describe('getVehicleSubClass', () => {
it('should return the vehicle sub class for a CARs and LGVs', () => {
const car = {
techRecord_vehicleType: VehicleTypes.CAR,
techRecord_bodyType: 'body type',
techRecord_vehicleSubclass: 'vehicle subclass',
} as unknown as V3TechRecordModel;

const lgv = {
techRecord_vehicleType: VehicleTypes.LGV,
techRecord_bodyType: 'body type',
techRecord_vehicleSubclass: 'vehicle subclass',
} as unknown as V3TechRecordModel;

expect(service.getVehicleSubClass(car)).toBe('vehicle subclass');
expect(service.getVehicleSubClass(lgv)).toBe('vehicle subclass');
});

it('should return undefined for non-CARs and non-LGVs', () => {
const psv = {
techRecord_vehicleType: VehicleTypes.PSV,
techRecord_bodyType: 'body type',
techRecord_vehicleSubclass: 'vehicle subclass',
} as unknown as V3TechRecordModel;

const hgv = {
techRecord_vehicleType: VehicleTypes.HGV,
techRecord_bodyType: 'body type',
techRecord_vehicleSubclass: 'vehicle subclass',
} as unknown as V3TechRecordModel;

const trl = {
techRecord_vehicleType: VehicleTypes.TRL,
techRecord_bodyType: 'body type',
techRecord_vehicleSubclass: 'vehicle subclass',
} as unknown as V3TechRecordModel;

const motorcycle = {
techRecord_vehicleType: VehicleTypes.MOTORCYCLE,
techRecord_bodyType: 'body type',
techRecord_vehicleSubclass: 'vehicle subclass',
} as unknown as V3TechRecordModel;

expect(service.getVehicleSubClass(psv)).toBeUndefined();
expect(service.getVehicleSubClass(hgv)).toBeUndefined();
expect(service.getVehicleSubClass(trl)).toBeUndefined();
expect(service.getVehicleSubClass(motorcycle)).toBeUndefined();
});
});
});
11 changes: 11 additions & 0 deletions src/app/services/technical-record/technical-record.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core';
import { AbstractControl, AsyncValidatorFn, ValidationErrors } from '@angular/forms';
import { AxleTyreProperties } from '@api/vehicle';
import { EUVehicleCategory } from '@dvsa/cvs-type-definitions/types/v3/tech-record/enums/euVehicleCategory.enum.js';
import { TechRecordGETMotorcycleComplete } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/motorcycle/complete';
import { TechRecordSearchSchema } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/search';
import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-verb';
import {
Expand Down Expand Up @@ -401,6 +402,16 @@ export class TechnicalRecordService {
: undefined;
}

getVehicleClassCode(techRecord: V3TechRecordModel) {
return techRecord.techRecord_vehicleType === 'motorcycle' && techRecord.techRecord_recordCompleteness === 'complete'
? (techRecord as TechRecordGETMotorcycleComplete).techRecord_vehicleClass_code
: undefined;
}

getVehicleClass(techRecord: V3TechRecordModel) {
return this.getVehicleClassCode(techRecord) ?? this.getVehicleClassDescription(techRecord);
}

getVehicleSubClass(techRecord: V3TechRecordModel) {
return techRecord.techRecord_vehicleType === 'car' || techRecord.techRecord_vehicleType === 'lgv'
? techRecord.techRecord_vehicleSubclass
Expand Down
Loading