From 7a4097741b7a223f59bce1e88ce2610533922be8 Mon Sep 17 00:00:00 2001 From: Matt Waldron Date: Tue, 8 Oct 2024 10:23:52 +0100 Subject: [PATCH] refactored to use base abstract class and state bag --- .../CertificatePayloadGenerator.ts | 17 ++- src/certificate/CertificatePayloadStateBag.ts | 8 ++ src/certificate/ICertificatePayloadCommand.ts | 17 ++- .../commands/AdrCertificateCommand.ts | 21 ++- src/certificate/commands/DefectsCommand.ts | 31 ++--- .../commands/IvaCertificateCommand.ts | 22 ++- .../commands/MakeAndModelCommand.ts | 24 ++-- .../commands/MsvaCertificateCommand.ts | 21 ++- .../commands/OdometerHistoryCommand.ts | 25 ++-- .../commands/PassOrFailCertificateCommand.ts | 19 ++- .../RoadworthinessCertificateCommand.ts | 21 ++- src/certificate/commands/SignatureCommand.ts | 12 +- .../commands/TestHistoryCommand.ts | 14 +- src/certificate/commands/WatermarkCommand.ts | 10 +- tests/unit/certGen.unitTest.ts | 130 +++++++++++++----- 15 files changed, 227 insertions(+), 165 deletions(-) create mode 100644 src/certificate/CertificatePayloadStateBag.ts diff --git a/src/certificate/CertificatePayloadGenerator.ts b/src/certificate/CertificatePayloadGenerator.ts index ec50d00..ea894d4 100644 --- a/src/certificate/CertificatePayloadGenerator.ts +++ b/src/certificate/CertificatePayloadGenerator.ts @@ -3,6 +3,7 @@ import { Service } from 'typedi'; import { ITestResult } from '../models'; import { ICertificatePayload } from '../models'; import { CERTIFICATE_DATA } from '../models/Enums'; +import { CertificatePayloadStateBag } from './CertificatePayloadStateBag'; import { ICertificatePayloadCommand } from './ICertificatePayloadCommand'; import { AdrCertificateCommand } from './commands/AdrCertificateCommand'; import { DefectsCommand } from './commands/DefectsCommand'; @@ -61,8 +62,12 @@ export class CertificatePayloadGenerator implements ICertificatePayloadCommand { type: CERTIFICATE_DATA, isWelsh = false ): Promise { - this.initialise(type, isWelsh); - return this.generate(testResult); + this.initialise({ + type, + isWelsh, + testResult, + }); + return this.generate(); } /** @@ -70,8 +75,8 @@ export class CertificatePayloadGenerator implements ICertificatePayloadCommand { * @param type The type of certificate to generate * @param isWelsh True if a Welsh certificate should also be generated. */ - public initialise(type: CERTIFICATE_DATA, isWelsh = false) { - this.commands.forEach((cmd) => cmd.initialise(type, isWelsh)); + public initialise(state: CertificatePayloadStateBag) { + this.commands.forEach((cmd) => cmd.initialise(state)); } /** @@ -79,9 +84,9 @@ export class CertificatePayloadGenerator implements ICertificatePayloadCommand { * @param testResult the source test result for certificate generation * @returns A generated certificate payload */ - public async generate(testResult: ITestResult): Promise { + public async generate(): Promise { // Map over all the commands and get their certificate data. - const results = await Promise.all(this.commands.map((cmd) => cmd.generate(testResult))); + const results = await Promise.all(this.commands.map((cmd) => cmd.generate())); // Flatten all the certificate data into our result payload. return Promise.resolve(merge({} as ICertificatePayload, ...results)); diff --git a/src/certificate/CertificatePayloadStateBag.ts b/src/certificate/CertificatePayloadStateBag.ts new file mode 100644 index 0000000..5fa3e66 --- /dev/null +++ b/src/certificate/CertificatePayloadStateBag.ts @@ -0,0 +1,8 @@ +import { ITestResult } from '../models'; +import { CERTIFICATE_DATA } from '../models/Enums'; + +export type CertificatePayloadStateBag = { + type: CERTIFICATE_DATA; + isWelsh: boolean; + testResult: ITestResult; +}; diff --git a/src/certificate/ICertificatePayloadCommand.ts b/src/certificate/ICertificatePayloadCommand.ts index 759e45c..45c239e 100644 --- a/src/certificate/ICertificatePayloadCommand.ts +++ b/src/certificate/ICertificatePayloadCommand.ts @@ -1,8 +1,17 @@ import { ICertificatePayload } from '../models'; -import { ITestResult } from '../models'; -import { CERTIFICATE_DATA } from '../models/Enums'; +import { CertificatePayloadStateBag } from './CertificatePayloadStateBag'; export interface ICertificatePayloadCommand { - initialise(type: CERTIFICATE_DATA, isWelsh: boolean): void; - generate(testResult: ITestResult): Promise; + initialise(state: CertificatePayloadStateBag): void; + generate(): Promise; +} + +export abstract class BasePayloadCommand implements ICertificatePayloadCommand { + protected state: CertificatePayloadStateBag = {} as CertificatePayloadStateBag; + + initialise(state: CertificatePayloadStateBag) { + this.state = state; + } + + abstract generate(): Promise; } diff --git a/src/certificate/commands/AdrCertificateCommand.ts b/src/certificate/commands/AdrCertificateCommand.ts index da40104..4dde984 100644 --- a/src/certificate/commands/AdrCertificateCommand.ts +++ b/src/certificate/commands/AdrCertificateCommand.ts @@ -1,28 +1,25 @@ import { Service } from 'typedi'; -import { ITestResult } from '../../models'; import { ICertificatePayload } from '../../models'; import { CERTIFICATE_DATA } from '../../models/Enums'; import { TechRecordType } from '../../models/Types'; import { TechRecordService } from '../../tech-record/TechRecordService'; -import { ICertificatePayloadCommand } from '../ICertificatePayloadCommand'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class AdrCertificateCommand implements ICertificatePayloadCommand { - private type?: CERTIFICATE_DATA; - - constructor(private techRecordService: TechRecordService) {} - - private certificateIsAnAdr = (): boolean => this.type === CERTIFICATE_DATA.ADR_DATA; - - public initialise(type: CERTIFICATE_DATA, isWelsh = false) { - this.type = type; +export class AdrCertificateCommand extends BasePayloadCommand { + constructor(private techRecordService: TechRecordService) { + super(); } - public async generate(testResult: ITestResult): Promise { + private certificateIsAnAdr = (): boolean => this.state.type === CERTIFICATE_DATA.ADR_DATA; + + public async generate(): Promise { if (!this.certificateIsAnAdr()) { return {} as ICertificatePayload; } + const { testResult } = this.state; + const adrDetails: TechRecordType = await this.techRecordService.getAdrDetails(testResult); const makeAndModel = await this.techRecordService.getVehicleMakeAndModel(testResult); diff --git a/src/certificate/commands/DefectsCommand.ts b/src/certificate/commands/DefectsCommand.ts index cdcf682..ab4e61b 100644 --- a/src/certificate/commands/DefectsCommand.ts +++ b/src/certificate/commands/DefectsCommand.ts @@ -7,32 +7,29 @@ import { ITestType } from '../../models'; import { CERTIFICATE_DATA, TEST_RESULTS } from '../../models/Enums'; import { IDefectParent } from '../../models/IDefectParent'; import { IFlatDefect } from '../../models/IFlatDefect'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class DefectsCommand { - protected type?: CERTIFICATE_DATA; - - protected isWelsh = false; - +export class DefectsCommand extends BasePayloadCommand { constructor( private defectService: DefectService, private defectRepository: DefectRepository - ) {} + ) { + super(); + } private certificateIsAnPassOrFail = (): boolean => - this.type === CERTIFICATE_DATA.PASS_DATA || this.type === CERTIFICATE_DATA.FAIL_DATA; + this.state.type === CERTIFICATE_DATA.PASS_DATA || this.state.type === CERTIFICATE_DATA.FAIL_DATA; - public initialise(type: CERTIFICATE_DATA, isWelsh = false) { - this.type = type; - this.isWelsh = isWelsh; - } - - public async generate(testResult: ITestResult): Promise { + public async generate(): Promise { if (!this.certificateIsAnPassOrFail()) { return {} as ICertificatePayload; } - const { testTypes } = testResult; + const { + testResult, + testResult: { testTypes }, + } = this.state; const result = {} as ICertificatePayload; @@ -52,10 +49,12 @@ export class DefectsCommand { } private async getPayloadData(testResult: ITestResult, type: CERTIFICATE_DATA): Promise { + const { isWelsh } = this.state; + let defectListFromApi: IDefectParent[] = []; let flattenedDefects: IFlatDefect[] = []; - if (this.isWelsh) { + if (isWelsh) { defectListFromApi = await this.defectRepository.getDefectTranslations(); flattenedDefects = this.defectService.flattenDefectsFromApi(defectListFromApi); } @@ -65,7 +64,7 @@ export class DefectsCommand { type, testResult.vehicleType, flattenedDefects, - this.isWelsh + isWelsh ); return defects; } diff --git a/src/certificate/commands/IvaCertificateCommand.ts b/src/certificate/commands/IvaCertificateCommand.ts index af10cdf..0d34a83 100644 --- a/src/certificate/commands/IvaCertificateCommand.ts +++ b/src/certificate/commands/IvaCertificateCommand.ts @@ -1,32 +1,30 @@ import moment from 'moment'; import { Service } from 'typedi'; import { DefectService } from '../../defect/DefectService'; -import { IRequiredStandard, ITestResult } from '../../models'; +import { IRequiredStandard } from '../../models'; import { ICertificatePayload } from '../../models'; import { CERTIFICATE_DATA, IVA_30 } from '../../models/Enums'; import { TestResultService } from '../../test-result/TestResultService'; -import { ICertificatePayloadCommand } from '../ICertificatePayloadCommand'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class IvaCertificateCommand implements ICertificatePayloadCommand { - private type?: CERTIFICATE_DATA; - +export class IvaCertificateCommand extends BasePayloadCommand { constructor( private defectService: DefectService, private testResultService: TestResultService - ) {} - - private certificateIsAnIva = (): boolean => this.type === CERTIFICATE_DATA.IVA_DATA; - - initialise(type: CERTIFICATE_DATA, isWelsh = false) { - this.type = type; + ) { + super(); } - public async generate(testResult: ITestResult): Promise { + private certificateIsAnIva = (): boolean => this.state.type === CERTIFICATE_DATA.IVA_DATA; + + public async generate(): Promise { if (!this.certificateIsAnIva()) { return {} as ICertificatePayload; } + const { testResult } = this.state; + const ivaFailDetailsForDocGen = { vin: testResult.vin, serialNumber: testResult.vehicleType === 'trl' ? testResult.trailerId : testResult.vrm, diff --git a/src/certificate/commands/MakeAndModelCommand.ts b/src/certificate/commands/MakeAndModelCommand.ts index 175e90c..8848033 100644 --- a/src/certificate/commands/MakeAndModelCommand.ts +++ b/src/certificate/commands/MakeAndModelCommand.ts @@ -1,37 +1,35 @@ import { Service } from 'typedi'; import { ICertificatePayload } from '../../models'; -import { ITestResult } from '../../models'; import { CERTIFICATE_DATA, TEST_RESULTS } from '../../models/Enums'; import { TechRecordService } from '../../tech-record/TechRecordService'; import { TestResultService } from '../../test-result/TestResultService'; import { TrailerRepository } from '../../trailer/TrailerRepository'; -import { ICertificatePayloadCommand } from '../ICertificatePayloadCommand'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class MakeAndModelCommand implements ICertificatePayloadCommand { - protected type?: CERTIFICATE_DATA; - +export class MakeAndModelCommand extends BasePayloadCommand { constructor( private techRecordService: TechRecordService, private trailerRepository: TrailerRepository, private testResultService: TestResultService - ) {} + ) { + super(); + } private certificateIsAnPassOrFail = (): boolean => - this.type === CERTIFICATE_DATA.PASS_DATA || this.type === CERTIFICATE_DATA.FAIL_DATA; - - initialise(type: CERTIFICATE_DATA, isWelsh = false) { - this.type = type; - } + this.state.type === CERTIFICATE_DATA.PASS_DATA || this.state.type === CERTIFICATE_DATA.FAIL_DATA; - public async generate(testResult: ITestResult): Promise { + public async generate(): Promise { const result = {} as ICertificatePayload; if (!this.certificateIsAnPassOrFail()) { return result; } - const { testTypes, vehicleType } = testResult; + const { + testResult, + testResult: { testTypes, vehicleType }, + } = this.state; const makeAndModel = await this.techRecordService.getVehicleMakeAndModel(testResult); diff --git a/src/certificate/commands/MsvaCertificateCommand.ts b/src/certificate/commands/MsvaCertificateCommand.ts index 9c36809..e17d85e 100644 --- a/src/certificate/commands/MsvaCertificateCommand.ts +++ b/src/certificate/commands/MsvaCertificateCommand.ts @@ -1,29 +1,26 @@ import moment from 'moment'; import { Service } from 'typedi'; import { DefectService } from '../../defect/DefectService'; -import { ITestResult } from '../../models'; import { ICertificatePayload } from '../../models'; import { IRequiredStandard } from '../../models'; import { CERTIFICATE_DATA } from '../../models/Enums'; -import { ICertificatePayloadCommand } from '../ICertificatePayloadCommand'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class MsvaCertificateCommand implements ICertificatePayloadCommand { - private type?: CERTIFICATE_DATA; - - constructor(private defectService: DefectService) {} - - private certificateIsAnMsva = (): boolean => this.type === CERTIFICATE_DATA.MSVA_DATA; - - initialise(type: CERTIFICATE_DATA, isWelsh = false) { - this.type = type; +export class MsvaCertificateCommand extends BasePayloadCommand { + constructor(private defectService: DefectService) { + super(); } - public async generate(testResult: ITestResult): Promise { + private certificateIsAnMsva = (): boolean => this.state.type === CERTIFICATE_DATA.MSVA_DATA; + + public async generate(): Promise { if (!this.certificateIsAnMsva()) { return {} as ICertificatePayload; } + const { testResult } = this.state; + const msvaFailDetailsForDocGen = { vin: testResult.vin, serialNumber: testResult.vrm, diff --git a/src/certificate/commands/OdometerHistoryCommand.ts b/src/certificate/commands/OdometerHistoryCommand.ts index 17686b4..9ae69ed 100644 --- a/src/certificate/commands/OdometerHistoryCommand.ts +++ b/src/certificate/commands/OdometerHistoryCommand.ts @@ -3,36 +3,35 @@ import { ICertificatePayload } from '../../models'; import { ITestResult } from '../../models'; import { CERTIFICATE_DATA, TEST_RESULTS, VEHICLE_TYPES } from '../../models/Enums'; import { TestResultRepository } from '../../test-result/TestResultRepository'; -import { ICertificatePayloadCommand } from '../ICertificatePayloadCommand'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class OdometerHistoryCommand implements ICertificatePayloadCommand { - protected type?: CERTIFICATE_DATA; - - constructor(private testResultRepository: TestResultRepository) {} +export class OdometerHistoryCommand extends BasePayloadCommand { + constructor(private testResultRepository: TestResultRepository) { + super(); + } private certificateIsAnPassOrFail = (): boolean => - this.type === CERTIFICATE_DATA.PASS_DATA || this.type === CERTIFICATE_DATA.FAIL_DATA; + this.state.type === CERTIFICATE_DATA.PASS_DATA || this.state.type === CERTIFICATE_DATA.FAIL_DATA; private vehicleIsTrailer = (testResult: ITestResult): boolean => testResult.vehicleType === VEHICLE_TYPES.TRL; - initialise(type: CERTIFICATE_DATA, isWelsh = false) { - this.type = type; - } - - public async generate(testResult: ITestResult): Promise { + public async generate(): Promise { const result = {} as ICertificatePayload; if (!this.certificateIsAnPassOrFail()) { return result; } + const { + testResult, + testResult: { testTypes, systemNumber }, + } = this.state; + if (this.vehicleIsTrailer(testResult)) { return result; } - const { testTypes, systemNumber } = testResult; - const odometerHistory = await this.testResultRepository.getOdometerHistory(systemNumber); if (testTypes.testResult !== TEST_RESULTS.FAIL) { diff --git a/src/certificate/commands/PassOrFailCertificateCommand.ts b/src/certificate/commands/PassOrFailCertificateCommand.ts index ee2d928..a6e5c57 100644 --- a/src/certificate/commands/PassOrFailCertificateCommand.ts +++ b/src/certificate/commands/PassOrFailCertificateCommand.ts @@ -3,27 +3,24 @@ import { Service } from 'typedi'; import { ITestResult } from '../../models'; import { ICertificatePayload } from '../../models'; import { CERTIFICATE_DATA, TEST_RESULTS, VEHICLE_TYPES } from '../../models/Enums'; -import { ICertificatePayloadCommand } from '../ICertificatePayloadCommand'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class PassOrFailCertificateCommand implements ICertificatePayloadCommand { - protected type?: CERTIFICATE_DATA; - +export class PassOrFailCertificateCommand extends BasePayloadCommand { private certificateIsAnPassOrFail = (): boolean => - this.type === CERTIFICATE_DATA.PASS_DATA || this.type === CERTIFICATE_DATA.FAIL_DATA; - - public initialise(type: CERTIFICATE_DATA, isWelsh = false) { - this.type = type; - } + this.state.type === CERTIFICATE_DATA.PASS_DATA || this.state.type === CERTIFICATE_DATA.FAIL_DATA; - public async generate(testResult: ITestResult): Promise { + public async generate(): Promise { const result = {} as ICertificatePayload; if (!this.certificateIsAnPassOrFail()) { return result; } - const { testTypes } = testResult; + const { + testResult, + testResult: { testTypes }, + } = this.state; const payload = await this.getPayloadData(testResult); diff --git a/src/certificate/commands/RoadworthinessCertificateCommand.ts b/src/certificate/commands/RoadworthinessCertificateCommand.ts index 226bdf1..d4ab613 100644 --- a/src/certificate/commands/RoadworthinessCertificateCommand.ts +++ b/src/certificate/commands/RoadworthinessCertificateCommand.ts @@ -1,33 +1,30 @@ import moment from 'moment'; import { Service } from 'typedi'; import { DefectService } from '../../defect/DefectService'; -import { ITestResult } from '../../models'; import { IRoadworthinessCertificateData } from '../../models'; import { ICertificatePayload } from '../../models'; import { CERTIFICATE_DATA, TEST_RESULTS, VEHICLE_TYPES } from '../../models/Enums'; import { TechRecordService } from '../../tech-record/TechRecordService'; -import { ICertificatePayloadCommand } from '../ICertificatePayloadCommand'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class RoadworthinessCertificateCommand implements ICertificatePayloadCommand { - private type?: CERTIFICATE_DATA; - +export class RoadworthinessCertificateCommand extends BasePayloadCommand { constructor( private defectService: DefectService, private techRecordService: TechRecordService - ) {} - - private certificateIsAnRwt = (): boolean => this.type === CERTIFICATE_DATA.RWT_DATA; - - initialise(type: CERTIFICATE_DATA, isWelsh = false) { - this.type = type; + ) { + super(); } - public async generate(testResult: ITestResult): Promise { + private certificateIsAnRwt = (): boolean => this.state.type === CERTIFICATE_DATA.RWT_DATA; + + public async generate(): Promise { if (!this.certificateIsAnRwt()) { return {} as ICertificatePayload; } + const { testResult } = this.state; + const weightDetails = await this.techRecordService.getWeightDetails(testResult); let defectRWTList: string[] | undefined; diff --git a/src/certificate/commands/SignatureCommand.ts b/src/certificate/commands/SignatureCommand.ts index 47d119a..577954d 100644 --- a/src/certificate/commands/SignatureCommand.ts +++ b/src/certificate/commands/SignatureCommand.ts @@ -2,20 +2,18 @@ import { Readable } from 'stream'; import { GetObjectOutput } from '@aws-sdk/client-s3'; import { Service } from 'typedi'; import { ICertificatePayload } from '../../models'; -import { ITestResult } from '../../models'; -import { CERTIFICATE_DATA } from '../../models/Enums'; import { S3BucketService } from '../../services/S3BucketService'; -import { ICertificatePayloadCommand } from '../ICertificatePayloadCommand'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class SignatureCommand implements ICertificatePayloadCommand { +export class SignatureCommand extends BasePayloadCommand { constructor(private s3Client: S3BucketService) { - this.s3Client = s3Client; + super(); } - initialise(type: CERTIFICATE_DATA, isWelsh = false) {} + public async generate(): Promise { + const { testResult } = this.state; - public async generate(testResult: ITestResult): Promise { const signature = await this.getSignature(testResult.createdById ?? testResult.testerStaffId); return { diff --git a/src/certificate/commands/TestHistoryCommand.ts b/src/certificate/commands/TestHistoryCommand.ts index 2b7b10a..78d54fa 100644 --- a/src/certificate/commands/TestHistoryCommand.ts +++ b/src/certificate/commands/TestHistoryCommand.ts @@ -1,18 +1,16 @@ import moment from 'moment'; import { Service } from 'typedi'; import { ICertificatePayload } from '../../models'; -import { ITestResult } from '../../models'; -import { CERTIFICATE_DATA } from '../../models/Enums'; -import { ICertificatePayloadCommand } from '../ICertificatePayloadCommand'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class TestHistoryCommand implements ICertificatePayloadCommand { - initialise(type: CERTIFICATE_DATA, isWelsh = false) {} - - public async generate(testResult: ITestResult): Promise { +export class TestHistoryCommand extends BasePayloadCommand { + public async generate(): Promise { const result = {} as ICertificatePayload; - const { testTypes, testHistory, createdByName, createdAt } = testResult as any; + const { + testResult: { testTypes, testHistory, createdByName, createdAt }, + } = this.state as any; if (testHistory) { // eslint-disable-next-line diff --git a/src/certificate/commands/WatermarkCommand.ts b/src/certificate/commands/WatermarkCommand.ts index f2e94c1..b6392c1 100644 --- a/src/certificate/commands/WatermarkCommand.ts +++ b/src/certificate/commands/WatermarkCommand.ts @@ -1,14 +1,10 @@ import { Service } from 'typedi'; import { ICertificatePayload } from '../../models'; -import { ITestResult } from '../../models'; -import { CERTIFICATE_DATA } from '../../models/Enums'; -import { ICertificatePayloadCommand } from '../ICertificatePayloadCommand'; +import { BasePayloadCommand } from '../ICertificatePayloadCommand'; @Service() -export class WatermarkCommand implements ICertificatePayloadCommand { - initialise(type: CERTIFICATE_DATA, isWelsh = false) {} - - public async generate(testResult: ITestResult): Promise { +export class WatermarkCommand extends BasePayloadCommand { + public async generate(): Promise { return { Watermark: process.env.BRANCH === 'prod' ? '' : 'NOT VALID', } as ICertificatePayload; diff --git a/tests/unit/certGen.unitTest.ts b/tests/unit/certGen.unitTest.ts index 7a32325..fa28576 100644 --- a/tests/unit/certGen.unitTest.ts +++ b/tests/unit/certGen.unitTest.ts @@ -42,6 +42,7 @@ import { CERTIFICATE_DATA } from "../../src/models/Enums"; import { IvaCertificateCommand } from "../../src/certificate/commands/IvaCertificateCommand"; import { PassOrFailCertificateCommand } from "../../src/certificate/commands/PassOrFailCertificateCommand"; import { DefectsCommand } from "../../src/certificate/commands/DefectsCommand"; +import { CertificatePayloadStateBag } from "../../src/certificate/CertificatePayloadStateBag"; const sandbox = sinon.createSandbox(); @@ -4581,16 +4582,21 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.FAIL_DATA, + testResult + } as CertificatePayloadStateBag; + const passOrFailCommand = Container.get(PassOrFailCertificateCommand); - passOrFailCommand.initialise(CERTIFICATE_DATA.FAIL_DATA); + passOrFailCommand.initialise(state); const defectsCommand = Container.get(DefectsCommand); - defectsCommand.initialise(CERTIFICATE_DATA.FAIL_DATA); + defectsCommand.initialise(state); const payload = { FAIL_DATA: { - ...(await passOrFailCommand.generate(testResult)).FAIL_DATA, - ...(await defectsCommand.generate(testResult)).FAIL_DATA + ...(await passOrFailCommand.generate()).FAIL_DATA, + ...(await defectsCommand.generate()).FAIL_DATA } }; @@ -4640,16 +4646,21 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.FAIL_DATA, + testResult: testResult2 + } as CertificatePayloadStateBag; + const passOrFailCommand = Container.get(PassOrFailCertificateCommand); - passOrFailCommand.initialise(CERTIFICATE_DATA.FAIL_DATA); + passOrFailCommand.initialise(state); const defectsCommand = Container.get(DefectsCommand); - defectsCommand.initialise(CERTIFICATE_DATA.FAIL_DATA); + defectsCommand.initialise(state); const payload = { FAIL_DATA: { - ...(await passOrFailCommand.generate(testResult2)).FAIL_DATA, - ...(await defectsCommand.generate(testResult2)).FAIL_DATA + ...(await passOrFailCommand.generate()).FAIL_DATA, + ...(await defectsCommand.generate()).FAIL_DATA } }; @@ -4699,16 +4710,21 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.FAIL_DATA, + testResult: testResult3 + } as CertificatePayloadStateBag; + const passOrFailCommand = Container.get(PassOrFailCertificateCommand); - passOrFailCommand.initialise(CERTIFICATE_DATA.FAIL_DATA); + passOrFailCommand.initialise(state); const defectsCommand = Container.get(DefectsCommand); - defectsCommand.initialise(CERTIFICATE_DATA.FAIL_DATA); + defectsCommand.initialise(state); const payload = { FAIL_DATA: { - ...(await passOrFailCommand.generate(testResult3)).FAIL_DATA, - ...(await defectsCommand.generate(testResult3)).FAIL_DATA + ...(await passOrFailCommand.generate()).FAIL_DATA, + ...(await defectsCommand.generate()).FAIL_DATA } }; @@ -4768,9 +4784,14 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.IVA_DATA, + testResult: testResult1 + } as CertificatePayloadStateBag; + const ivaCommand = Container.get(IvaCertificateCommand); - ivaCommand.initialise(CERTIFICATE_DATA.IVA_DATA); - const payload = await ivaCommand.generate(testResult1); + ivaCommand.initialise(state); + const payload = await ivaCommand.generate(); expect(payload).toEqual(expectedResult); }); @@ -4828,9 +4849,14 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.IVA_DATA, + testResult: testResult21 + } as CertificatePayloadStateBag; + const ivaCommand = Container.get(IvaCertificateCommand); - ivaCommand.initialise(CERTIFICATE_DATA.IVA_DATA); - const payload = await ivaCommand.generate(testResult21); + ivaCommand.initialise(state); + const payload = await ivaCommand.generate(); expect(payload).toEqual(expectedResult); }); } @@ -4893,9 +4919,14 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.IVA_DATA, + testResult: testResult2 + } as CertificatePayloadStateBag; + const ivaCommand = Container.get(IvaCertificateCommand); - ivaCommand.initialise(CERTIFICATE_DATA.IVA_DATA); - const payload = await ivaCommand.generate(testResult2); + ivaCommand.initialise(state); + const payload = await ivaCommand.generate(); expect(payload).toEqual(expectedResult); }); } @@ -4943,9 +4974,14 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.IVA_DATA, + testResult: testResult3 + } as CertificatePayloadStateBag; + const ivaCommand = Container.get(IvaCertificateCommand); - ivaCommand.initialise(CERTIFICATE_DATA.IVA_DATA); - const payload = await ivaCommand.generate(testResult3); + ivaCommand.initialise(state); + const payload = await ivaCommand.generate(); expect(payload).toEqual(expectedResult); }); } @@ -4994,9 +5030,14 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.IVA_DATA, + testResult: testResult4 + } as CertificatePayloadStateBag; + const ivaCommand = Container.get(IvaCertificateCommand); - ivaCommand.initialise(CERTIFICATE_DATA.IVA_DATA); - const payload = await ivaCommand.generate(testResult4); + ivaCommand.initialise(state); + const payload = await ivaCommand.generate(); expect(payload).toEqual(expectedResult); }); } @@ -5046,9 +5087,14 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.IVA_DATA, + testResult: testResult5 + } as CertificatePayloadStateBag; + const ivaCommand = Container.get(IvaCertificateCommand); - ivaCommand.initialise(CERTIFICATE_DATA.IVA_DATA); - const payload = await ivaCommand.generate(testResult5); + ivaCommand.initialise(state); + const payload = await ivaCommand.generate(); expect(payload).toEqual(expectedResult); }); } @@ -5093,9 +5139,14 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.MSVA_DATA, + testResult: testResult6 + } as CertificatePayloadStateBag; + const msvaCommand = Container.get(MsvaCertificateCommand); - msvaCommand.initialise(CERTIFICATE_DATA.MSVA_DATA); - const payload = await msvaCommand.generate(testResult6); + msvaCommand.initialise(state); + const payload = await msvaCommand.generate(); expect(payload).toEqual(expectedResult); }); } @@ -5151,9 +5202,14 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.MSVA_DATA, + testResult: testResult7 + } as CertificatePayloadStateBag; + const msvaCommand = Container.get(MsvaCertificateCommand); - msvaCommand.initialise(CERTIFICATE_DATA.MSVA_DATA); - const payload = await msvaCommand.generate(testResult7); + msvaCommand.initialise(state); + const payload = await msvaCommand.generate(); expect(payload).toEqual(expectedResult); }); @@ -5203,9 +5259,14 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.MSVA_DATA, + testResult: testResult7 + } as CertificatePayloadStateBag; + const msvaCommand = Container.get(MsvaCertificateCommand); - msvaCommand.initialise(CERTIFICATE_DATA.MSVA_DATA); - const payload = await msvaCommand.generate(testResult7); + msvaCommand.initialise(state); + const payload = await msvaCommand.generate(); expect(payload).toEqual(expectedResult); }); } @@ -5250,9 +5311,14 @@ describe("cert-gen", () => { } }; + const state = { + type: CERTIFICATE_DATA.MSVA_DATA, + testResult: testResult8 + } as CertificatePayloadStateBag; + const msvaCommand = Container.get(MsvaCertificateCommand); - msvaCommand.initialise(CERTIFICATE_DATA.MSVA_DATA); - const payload = await msvaCommand.generate(testResult8); + msvaCommand.initialise(state); + const payload = await msvaCommand.generate(); expect(payload).toEqual(expectedResult); }); }