@@ -7,12 +7,14 @@ type scenariosType = {
77 inputPrescriptions : inputPrescriptionType
88 queryResults : Array < itemType >
99 expectedResult : outputPrescriptionType
10+ currentTime : number
1011}
1112const now = new Date ( )
1213const futureDateTime = new Date ( now . valueOf ( ) + ( 24 * 60 * 60 * 1000 ) ) . toISOString ( )
1314const 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"
@@ -187,7 +194,7 @@ const scenarios: Array<scenariosType> = [
187194 itemId : "item_1" ,
188195 latestStatus : "With pharmacy" ,
189196 isTerminalState : false ,
190- lastUpdateDateTime : "1970-01-03T00:00:00Z" // Back to 'With pharmacy'
197+ lastUpdateDateTime : "1970-01-03T00:00:00Z" // revoke RTC, back to 'With pharmacy'
191198 } ,
192199 {
193200 itemId : "item_1" ,
@@ -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"
@@ -258,13 +267,89 @@ const scenarios: Array<scenariosType> = [
258267 onboarded : false ,
259268 items : [ ]
260269 }
270+ } ,
271+ {
272+ scenarioDescription : "should return With pharmacy when RTC has been revoked" ,
273+ currentTime : new Date ( "2025-12-11T12:00:00Z" ) . getTime ( ) ,
274+ inputPrescriptions : {
275+ prescriptionID : "abc" ,
276+ odsCode : "123"
277+ } ,
278+ queryResults : [
279+ {
280+ itemId : "item_1" ,
281+ latestStatus : "Ready to collect" ,
282+ isTerminalState : false ,
283+ lastUpdateDateTime : "2025-12-11T10:00:00Z" ,
284+ postDatedLastModifiedSetAt : "2025-12-10T10:00:00Z"
285+ } ,
286+ {
287+ itemId : "item_1" ,
288+ latestStatus : "With pharmacy" ,
289+ isTerminalState : false ,
290+ lastUpdateDateTime : "2025-12-10T11:00:00Z"
291+ }
292+ ] ,
293+ expectedResult : {
294+ prescriptionID : "abc" ,
295+ onboarded : true ,
296+ items : [
297+ {
298+ itemId : "item_1" ,
299+ latestStatus : "With pharmacy" ,
300+ isTerminalState : false ,
301+ lastUpdateDateTime : "2025-12-10T11:00:00Z"
302+ }
303+ ]
304+ }
305+ } ,
306+ {
307+ scenarioDescription : "should return With pharmacy when RTC has been revoked but later RTC has matured" ,
308+ currentTime : new Date ( "2025-12-11T19:00:00Z" ) . getTime ( ) ,
309+ inputPrescriptions : {
310+ prescriptionID : "abc" ,
311+ odsCode : "123"
312+ } ,
313+ queryResults : [
314+ {
315+ itemId : "item_1" ,
316+ latestStatus : "Ready to collect" ,
317+ isTerminalState : false ,
318+ lastUpdateDateTime : "2025-12-11T19:00:00Z" ,
319+ postDatedLastModifiedSetAt : "2025-12-10T13:00:00Z"
320+ } ,
321+ {
322+ itemId : "item_1" ,
323+ latestStatus : "With pharmacy" ,
324+ isTerminalState : false ,
325+ lastUpdateDateTime : "2025-12-10T11:00:00Z"
326+ }
327+ ] ,
328+ expectedResult : {
329+ prescriptionID : "abc" ,
330+ onboarded : true ,
331+ items : [
332+ {
333+ itemId : "item_1" ,
334+ latestStatus : "With pharmacy" ,
335+ isTerminalState : false ,
336+ lastUpdateDateTime : "2025-12-10T11:00:00Z"
337+ } ,
338+ {
339+ itemId : "item_1" ,
340+ latestStatus : "Ready to collect" ,
341+ isTerminalState : false ,
342+ lastUpdateDateTime : "2025-12-11T19:00:00Z" ,
343+ postDatedLastModifiedSetAt : "2025-12-10T13:00:00Z"
344+ }
345+ ]
346+ }
261347 }
262348]
263349describe ( "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- } )
350+ it . each < scenariosType > ( scenarios ) ( "$scenarioDescription" ,
351+ ( { inputPrescriptions, queryResults, expectedResult, currentTime} ) => {
352+ const result = filterOutFutureReduceToLatestUpdates ( inputPrescriptions , queryResults , currentTime )
353+ expect ( result ) . toMatchObject ( expectedResult )
354+ } )
270355} )
0 commit comments