@@ -8,6 +8,8 @@ type scenariosType = {
88 queryResults : Array < itemType >
99 expectedResult : outputPrescriptionType
1010}
11+ const now = new Date ( )
12+ const futureDateTime = new Date ( now . valueOf ( ) + ( 24 * 60 * 60 * 1000 ) ) . toISOString ( )
1113const scenarios : Array < scenariosType > = [
1214 {
1315 scenarioDescription : "should return correct data when a matched prescription found" ,
@@ -97,9 +99,9 @@ const scenarios: Array<scenariosType> = [
9799 } ,
98100 {
99101 itemId : "item_1" ,
100- latestStatus : "latest_item_1_status " ,
102+ latestStatus : "item_1_status " ,
101103 isTerminalState : true ,
102- lastUpdateDateTime : "1972-01-01T00:00:00Z"
104+ lastUpdateDateTime : "1972-01-01T00:00:00Z" // newer update for item_1
103105 } ,
104106 {
105107 itemId : "item_2" ,
@@ -109,9 +111,9 @@ const scenarios: Array<scenariosType> = [
109111 } ,
110112 {
111113 itemId : "item_2" ,
112- latestStatus : "early_item_2_status " ,
114+ latestStatus : "item_2_status " ,
113115 isTerminalState : true ,
114- lastUpdateDateTime : "1970-01-01T00:00:00Z"
116+ lastUpdateDateTime : "1970-01-01T00:00:00Z" // older update for item_2
115117 }
116118 ] ,
117119 expectedResult : {
@@ -120,7 +122,7 @@ const scenarios: Array<scenariosType> = [
120122 items : [
121123 {
122124 itemId : "item_1" ,
123- latestStatus : "latest_item_1_status " ,
125+ latestStatus : "item_1_status " ,
124126 isTerminalState : true ,
125127 lastUpdateDateTime : "1972-01-01T00:00:00Z"
126128 } ,
@@ -171,15 +173,28 @@ const scenarios: Array<scenariosType> = [
171173 itemId : "item_1" ,
172174 latestStatus : "Ready to collect" ,
173175 isTerminalState : false ,
174- lastUpdateDateTime : "1971-01-01T00:00:00Z" ,
175- postDatedLastModifiedSetAt : "1970-01-02T00:00:00Z"
176+ lastUpdateDateTime : "1970-01-02T00:00:00Z" ,
177+ postDatedLastModifiedSetAt : "1970-01-01T00:00:00Z" // first RTC: post-dated and matured
178+ } ,
179+ {
180+ itemId : "item_1" ,
181+ latestStatus : "Ready to collect" ,
182+ isTerminalState : false ,
183+ lastUpdateDateTime : futureDateTime ,
184+ postDatedLastModifiedSetAt : "1970-01-02T00:00:00Z" // second RTC: post-dated and yet to mature
185+ } ,
186+ {
187+ itemId : "item_1" ,
188+ latestStatus : "With pharmacy" ,
189+ isTerminalState : false ,
190+ lastUpdateDateTime : "1970-01-03T00:00:00Z" // Back to 'With pharmacy'
176191 } ,
177192 {
178193 itemId : "item_1" ,
179194 latestStatus : "Ready to collect" ,
180195 isTerminalState : false ,
181- lastUpdateDateTime : "1972 -01-01T00 :00:00Z" ,
182- postDatedLastModifiedSetAt : "1971 -01-02T00 :00:00Z"
196+ lastUpdateDateTime : "1970 -01-04T00 :00:00Z" ,
197+ postDatedLastModifiedSetAt : "1970 -01-03T00 :00:00Z" // third RTC: post-dated and matured
183198 }
184199 ] ,
185200 expectedResult : {
@@ -190,17 +205,59 @@ const scenarios: Array<scenariosType> = [
190205 itemId : "item_1" ,
191206 latestStatus : "With pharmacy" ,
192207 isTerminalState : false ,
193- lastUpdateDateTime : "1970-01-01T00 :00:00Z"
208+ lastUpdateDateTime : "1970-01-03T00 :00:00Z"
194209 } ,
195210 {
196211 itemId : "item_1" ,
197212 latestStatus : "Ready to collect" ,
198213 isTerminalState : false ,
199- lastUpdateDateTime : "1972 -01-01T00 :00:00Z" ,
200- postDatedLastModifiedSetAt : "1971 -01-02T00 :00:00Z"
214+ lastUpdateDateTime : "1970 -01-04T00 :00:00Z" ,
215+ postDatedLastModifiedSetAt : "1970 -01-03T00 :00:00Z"
201216 }
202217 ]
203218 }
219+ } ,
220+ {
221+ scenarioDescription : "should return an item when it _has_ matured even though the post-dated time is in the future" ,
222+ inputPrescriptions : {
223+ prescriptionID : "abc" ,
224+ odsCode : "123"
225+ } ,
226+ queryResults : [
227+ {
228+ itemId : "item_1" ,
229+ latestStatus : "Ready to collect" ,
230+ isTerminalState : false ,
231+ lastUpdateDateTime : "1970-01-01T00:00:00Z" ,
232+ postDatedLastModifiedSetAt : futureDateTime
233+ }
234+ ] ,
235+ expectedResult : {
236+ prescriptionID : "abc" ,
237+ onboarded : true ,
238+ items : [
239+ {
240+ itemId : "item_1" ,
241+ latestStatus : "Ready to collect" ,
242+ isTerminalState : false ,
243+ lastUpdateDateTime : "1970-01-01T00:00:00Z" ,
244+ postDatedLastModifiedSetAt : futureDateTime
245+ }
246+ ]
247+ }
248+ } ,
249+ {
250+ scenarioDescription : "should return no items when empty item status are found" ,
251+ inputPrescriptions : {
252+ prescriptionID : "abc" ,
253+ odsCode : "123"
254+ } ,
255+ queryResults : [ ] ,
256+ expectedResult : {
257+ prescriptionID : "abc" ,
258+ onboarded : false ,
259+ items : [ ]
260+ }
204261 }
205262]
206263describe ( "Unit tests for buildResults" , ( ) => {
0 commit comments