Skip to content

Commit 7c245e9

Browse files
committed
test: parameterise system time
1 parent fbf9ebf commit 7c245e9

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

packages/gsul/tests/testBuildResult.test.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ type scenariosType = {
77
inputPrescriptions: inputPrescriptionType
88
queryResults: Array<itemType>
99
expectedResult: outputPrescriptionType
10+
currentTime: number
1011
}
1112
const now = new Date()
1213
const futureDateTime = new Date(now.valueOf() + (24 * 60 * 60 * 1000)).toISOString()
1314
const scenarios: Array<scenariosType> = [
1415
{
1516
scenarioDescription: "should return correct data when a matched prescription found",
17+
currentTime: new Date("2000-01-01T00:00:00Z").getTime(),
1618
inputPrescriptions: {
1719
prescriptionID: "abc",
1820
odsCode: "123"
@@ -40,6 +42,7 @@ const scenarios: Array<scenariosType> = [
4042
},
4143
{
4244
scenarioDescription: "should return no items when empty item status are found",
45+
currentTime: new Date("2000-01-01T00:00:00Z").getTime(),
4346
inputPrescriptions: {
4447
prescriptionID: "abc",
4548
odsCode: "123"
@@ -53,6 +56,7 @@ const scenarios: Array<scenariosType> = [
5356
},
5457
{
5558
scenarioDescription: "should return latest data when a multiple updates found",
59+
currentTime: new Date("2000-01-01T00:00:00Z").getTime(),
5660
inputPrescriptions: {
5761
prescriptionID: "abc",
5862
odsCode: "123"
@@ -86,6 +90,7 @@ const scenarios: Array<scenariosType> = [
8690
},
8791
{
8892
scenarioDescription: "should return latest item for multiple updates for each of multiple statuses",
93+
currentTime: new Date("2000-01-01T00:00:00Z").getTime(),
8994
inputPrescriptions: {
9095
prescriptionID: "abc",
9196
odsCode: "123"
@@ -137,6 +142,7 @@ const scenarios: Array<scenariosType> = [
137142
},
138143
{
139144
scenarioDescription: "should exclude item when post-dated update hasn't matured",
145+
currentTime: new Date("2000-01-01T00:00:00Z").getTime(),
140146
inputPrescriptions: {
141147
prescriptionID: "abc",
142148
odsCode: "123"
@@ -158,6 +164,7 @@ const scenarios: Array<scenariosType> = [
158164
},
159165
{
160166
scenarioDescription: "should use latest post-dated update when multiple have matured",
167+
currentTime: new Date("2000-01-01T00:00:00Z").getTime(),
161168
inputPrescriptions: {
162169
prescriptionID: "abc",
163170
odsCode: "123"
@@ -219,6 +226,7 @@ const scenarios: Array<scenariosType> = [
219226
},
220227
{
221228
scenarioDescription: "should return an item when it _has_ matured even though the post-dated time is in the future",
229+
currentTime: new Date("2000-01-01T00:00:00Z").getTime(),
222230
inputPrescriptions: {
223231
prescriptionID: "abc",
224232
odsCode: "123"
@@ -248,6 +256,7 @@ const scenarios: Array<scenariosType> = [
248256
},
249257
{
250258
scenarioDescription: "should return no items when empty item status are found",
259+
currentTime: new Date("2000-01-01T00:00:00Z").getTime(),
251260
inputPrescriptions: {
252261
prescriptionID: "abc",
253262
odsCode: "123"
@@ -261,10 +270,9 @@ const scenarios: Array<scenariosType> = [
261270
}
262271
]
263272
describe("Unit tests for buildResults", () => {
264-
it.each<scenariosType>(scenarios)("$scenarioDescription", ({inputPrescriptions, queryResults, expectedResult}) => {
265-
// Use a fixed time of 2000-01-01 for tests (946684800000 ms since epoch)
266-
const fixedCurrentTime = new Date("2000-01-01T00:00:00Z").getTime()
267-
const result = filterOutFutureReduceToLatestUpdates(inputPrescriptions, queryResults, fixedCurrentTime)
268-
expect(result).toMatchObject(expectedResult)
269-
})
273+
it.each<scenariosType>(scenarios)("$scenarioDescription",
274+
({inputPrescriptions, queryResults, expectedResult, currentTime}) => {
275+
const result = filterOutFutureReduceToLatestUpdates(inputPrescriptions, queryResults, currentTime)
276+
expect(result).toMatchObject(expectedResult)
277+
})
270278
})

0 commit comments

Comments
 (0)