generated from dvsa/dvsa-lambda-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cb2-14394): test filter MOT recalls funciton
- Loading branch information
1 parent
c398215
commit 3c3dac0
Showing
2 changed files
with
161 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import { MotRecalls } from "../../../src/models/motRecalls"; | ||
import { filterMotRecalls } from "../../../src/util/recalls"; | ||
|
||
describe('Recalls util functions', () => { | ||
|
||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
jest.setSystemTime(new Date()); | ||
}) | ||
|
||
describe('filterMotRecalls', () => { | ||
let date: Date; | ||
const emptyResponse = { | ||
manufacturer: null, | ||
hasRecall: false, | ||
} | ||
|
||
beforeEach(() => { | ||
date = new Date() | ||
}) | ||
|
||
it('should correctly filter a list of 3 when one is a recall', () => { | ||
const recallResponse = { | ||
vin: '1234', | ||
manufacturer: 'test manufacturer', | ||
recalls: [ | ||
{ | ||
manufacturerCampaignReference: '123ABC', | ||
dvsaCampaignReference: '1234ABC', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() - 1))).toISOString().split("T")[0], | ||
repairStatus: "NOT_FIXED" | ||
}, | ||
{ | ||
manufacturerCampaignReference: '123CBA', | ||
dvsaCampaignReference: '1234CBA', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() - 1))).toISOString().split("T")[0], | ||
repairStatus: "FIXED" | ||
}, | ||
{ | ||
manufacturerCampaignReference: 'CBA123', | ||
dvsaCampaignReference: 'CBA1234', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() - 1))).toISOString().split("T")[0], | ||
repairStatus: "FIXED" | ||
} | ||
], | ||
lastUpdatedDate: '123456' | ||
} | ||
const res = filterMotRecalls(recallResponse as MotRecalls) | ||
expect(res).toStrictEqual({ | ||
manufacturer: 'test manufacturer', | ||
hasRecall: true, | ||
}) | ||
}) | ||
it('should correctly filter a list of 3 when two are recalls', () => { | ||
const recallResponse = { | ||
vin: '1234', | ||
manufacturer: 'test manufacturer', | ||
recalls: [ | ||
{ | ||
manufacturerCampaignReference: '123ABC', | ||
dvsaCampaignReference: '1234ABC', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() - 1))).toISOString().split("T")[0], | ||
repairStatus: "NOT_FIXED" | ||
}, | ||
{ | ||
manufacturerCampaignReference: '123CBA', | ||
dvsaCampaignReference: '1234CBA', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() - 1))).toISOString().split("T")[0], | ||
repairStatus: "NOT_FIXED" | ||
}, | ||
{ | ||
manufacturerCampaignReference: 'CBA123', | ||
dvsaCampaignReference: 'CBA1234', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() - 1))).toISOString().split("T")[0], | ||
repairStatus: "FIXED" | ||
} | ||
], | ||
lastUpdatedDate: '123456' | ||
} | ||
const res = filterMotRecalls(recallResponse as MotRecalls) | ||
expect(res).toStrictEqual({ | ||
manufacturer: 'test manufacturer', | ||
hasRecall: true, | ||
}) | ||
}) | ||
it('should filter to nothing when all dates are in the future', () => { | ||
const recallResponse = { | ||
vin: '1234', | ||
manufacturer: 'test manufacturer', | ||
recalls: [ | ||
{ | ||
manufacturerCampaignReference: '123ABC', | ||
dvsaCampaignReference: '1234ABC', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() + 1))).toISOString().split("T")[0], | ||
repairStatus: "NOT_FIXED" | ||
}, | ||
{ | ||
manufacturerCampaignReference: '123CBA', | ||
dvsaCampaignReference: '1234CBA', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() + 2))).toISOString().split("T")[0], | ||
repairStatus: "NOT_FIXED" | ||
} | ||
], | ||
lastUpdatedDate: '123456' | ||
} | ||
const res = filterMotRecalls(recallResponse as MotRecalls) | ||
expect(res).toStrictEqual(emptyResponse) | ||
}) | ||
it('should filter to nothing when all vehicles are fixed', () => { | ||
const recallResponse = { | ||
vin: '1234', | ||
manufacturer: 'test manufacturer', | ||
recalls: [ | ||
{ | ||
manufacturerCampaignReference: '123ABC', | ||
dvsaCampaignReference: '1234ABC', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() - 1))).toISOString().split("T")[0], | ||
repairStatus: "FIXED" | ||
}, | ||
{ | ||
manufacturerCampaignReference: '123CBA', | ||
dvsaCampaignReference: '1234CBA', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() - 1))).toISOString().split("T")[0], | ||
repairStatus: "FIXED" | ||
} | ||
], | ||
lastUpdatedDate: '123456' | ||
} | ||
const res = filterMotRecalls(recallResponse as MotRecalls) | ||
expect(res).toStrictEqual(emptyResponse) | ||
}) | ||
it('should filter to nothing when all vehicles are fixed and all dates are in the future', () => { | ||
const recallResponse = { | ||
vin: '1234', | ||
manufacturer: 'test manufacturer', | ||
recalls: [ | ||
{ | ||
manufacturerCampaignReference: '123ABC', | ||
dvsaCampaignReference: '1234ABC', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() + 1))).toISOString().split("T")[0], | ||
repairStatus: "FIXED" | ||
}, | ||
{ | ||
manufacturerCampaignReference: '123CBA', | ||
dvsaCampaignReference: '1234CBA', | ||
recallCampaignStartDate: new Date((date.setDate(date.getDate() + 1))).toISOString().split("T")[0], | ||
repairStatus: "FIXED" | ||
} | ||
], | ||
lastUpdatedDate: '123456' | ||
} | ||
const res = filterMotRecalls(recallResponse as MotRecalls) | ||
expect(res).toStrictEqual(emptyResponse) | ||
}) | ||
}) | ||
|
||
|
||
}) |