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-9882): Add ability to produce a rejection letter for TRLs on provisional tech records #1350

Merged
merged 9 commits into from
Jan 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
CustomFormControl, FormNodeOption, FormNodeTypes, FormNodeWidth,
} from '@forms/services/dynamic-form.types';
import { LETTER_TYPES } from '@forms/templates/general/letter-types';
import { V3TechRecordModel } from '@models/vehicle-tech-record.model';
import { StatusCodes, V3TechRecordModel } from '@models/vehicle-tech-record.model';
import { Actions, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { TechnicalRecordService } from '@services/technical-record/technical-record.service';
Expand Down Expand Up @@ -64,6 +64,11 @@ export class GenerateLetterComponent implements OnInit {
}

get reasons(): Array<FormNodeOption<string>> {
if (this.techRecord?.techRecord_statusCode === StatusCodes.PROVISIONAL) {
return [
{ label: 'Trailer rejected', value: LETTER_TYPES[1].value },
];
}
return [
{ label: 'Trailer accepted', value: LETTER_TYPES[0].value },
{ label: 'Trailer rejected', value: LETTER_TYPES[1].value },
Expand Down
39 changes: 39 additions & 0 deletions src/app/forms/custom-sections/letters/letters.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,26 @@
import { SharedModule } from '@shared/shared.module';
import { State, initialAppState } from '@store/index';
import { of } from 'rxjs';
import { StatusCodes } from '@models/vehicle-tech-record.model';
import { TechnicalRecordService } from '@services/technical-record/technical-record.service';
import { TechRecordSearchSchema } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/search';
import { LettersComponent } from './letters.component';

const mockTechRecordService = {
techRecordHistory$: of([{
vin: 'test',
techRecord_statusCode: 'current',
techRecord_vehicleType: 'trl',
createdTimestamp: '12345',
systemNumber: '123',
techRecord_manufactureYear: 2021,
}] as TechRecordSearchSchema[]),
};

describe('LettersComponent', () => {
let component: LettersComponent;
let fixture: ComponentFixture<LettersComponent>;
let technicalRecordService: TechnicalRecordService;

Check warning on line 35 in src/app/forms/custom-sections/letters/letters.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (18.16.0)

'technicalRecordService' is assigned a value but never used
shivangidas marked this conversation as resolved.
Show resolved Hide resolved

beforeEach(async () => {
await TestBed.configureTestingModule({
Expand All @@ -41,8 +56,13 @@
provide: APP_BASE_HREF,
useValue: '/',
},
{
provide: TechnicalRecordService,
shivangidas marked this conversation as resolved.
Show resolved Hide resolved
useValue: mockTechRecordService,
},
],
}).compileComponents();

});

beforeEach(() => {
Expand All @@ -55,6 +75,8 @@
techRecord_statusCode: 'current',
} as TechRecordType<'trl'>;
fixture.detectChanges();

technicalRecordService = TestBed.inject(TechnicalRecordService);
});

it('should create', () => {
Expand All @@ -70,6 +92,23 @@
(component.techRecord as TechRecordType<'trl'>).techRecord_approvalType = ApprovalType.NTA;
expect(component.eligibleForLetter).toBeFalsy();
});

it('should return false if the statuscode is archived', () => {
(component.techRecord as TechRecordType<'trl'>).techRecord_approvalType = ApprovalType.GB_WVTA;
(component.techRecord as TechRecordType<'trl'>).techRecord_statusCode = StatusCodes.ARCHIVED;
expect(component.eligibleForLetter).toBeFalsy();
});
});

describe('checkRecordHistoryHasCurrent', () => {
it('should return false if the current technical record history has current status', () => {
expect(component.checkForCurrentRecordInHistory).toBeFalsy();
});

it('should return true if the provisional technical record history has current status', () => {
(component.techRecord as TechRecordType<'trl'>).techRecord_statusCode = 'provisional';
expect(component.checkForCurrentRecordInHistory).toBeTruthy();
});
});

describe('letter', () => {
Expand Down
24 changes: 21 additions & 3 deletions src/app/forms/custom-sections/letters/letters.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output,
} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { TechRecordSearchSchema } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/search';
import { ParagraphIds } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/trl/complete';
import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-vehicle-type';
import { TechRecordType as TechRecordTypeVehicleVerb } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-verb-vehicle-type';
Expand All @@ -13,6 +14,7 @@ import { LettersTemplate } from '@forms/templates/general/letters.template';
import { Roles } from '@models/roles.enum';
import { LettersIntoAuthApprovalType, LettersOfAuth, StatusCodes } from '@models/vehicle-tech-record.model';
import { Store } from '@ngrx/store';
import { TechnicalRecordService } from '@services/technical-record/technical-record.service';
import { updateScrollPosition } from '@store/technical-records';
import { Subscription, debounceTime } from 'rxjs';

Expand All @@ -33,6 +35,7 @@ export class LettersComponent implements OnInit, OnDestroy, OnChanges {

constructor(
private dynamicFormService: DynamicFormService,
private techRecordService: TechnicalRecordService,
private viewportScroller: ViewportScroller,
private router: Router,
private route: ActivatedRoute,
Expand Down Expand Up @@ -73,11 +76,21 @@ export class LettersComponent implements OnInit, OnDestroy, OnChanges {
}
: undefined;
}
// checking if the Technical Record History has current status code.
get checkForCurrentRecordInHistory(): boolean {
let ifCurrent = false;
pbardy2000 marked this conversation as resolved.
Show resolved Hide resolved
this.techRecordService.techRecordHistory$.subscribe((historyArray: TechRecordSearchSchema[] | undefined) => {
historyArray?.forEach((history: TechRecordSearchSchema) => {
if (history.techRecord_statusCode === StatusCodes.CURRENT
&& this.techRecord?.techRecord_statusCode === StatusCodes.PROVISIONAL) ifCurrent = true;
});
});
return ifCurrent;
}

get eligibleForLetter(): boolean {
const currentTechRecord = this.techRecord?.techRecord_statusCode === StatusCodes.CURRENT;

return this.correctApprovalType && currentTechRecord && !this.isEditing;
const IsArchivedTechRecord = this.techRecord?.techRecord_statusCode === StatusCodes.ARCHIVED;
tomcrawleyy marked this conversation as resolved.
Show resolved Hide resolved
return this.correctApprovalType && !IsArchivedTechRecord && !this.isEditing && !this.checkForCurrentRecordInHistory;
}

get reasonForIneligibility(): string {
Expand All @@ -86,6 +99,11 @@ export class LettersComponent implements OnInit, OnDestroy, OnChanges {
}

if (this.techRecord?.techRecord_statusCode !== StatusCodes.CURRENT) {
// if the Technical Record History has current status code return related words to inform users.
if (this.checkForCurrentRecordInHistory) {
// eslint-disable-next-line max-len
return 'Generating letters is not applicable to provisional records, where a current record also exists for a vehicle. Open the current record to generate letters.';
}
return 'Generating letters is only applicable to current technical records.';
tomcrawleyy marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down