This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
VirologyV2SmokeTest.kt
475 lines (421 loc) · 18.5 KB
/
VirologyV2SmokeTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
package smoke
import assertions.CtaExchangeAssertionsV2.confirmatoryDayLimit
import assertions.CtaExchangeAssertionsV2.diagnosisKeySubmissionSupported
import assertions.CtaExchangeAssertionsV2.requiresConfirmatoryTest
import assertions.CtaExchangeAssertionsV2.shouldOfferFollowUpTest
import assertions.CtaExchangeAssertionsV2.testEndDate
import assertions.CtaExchangeAssertionsV2.testKit
import assertions.CtaExchangeAssertionsV2.testResult
import assertions.VirologyAssertionsV2.confirmatoryDayLimit
import assertions.VirologyAssertionsV2.diagnosisKeySubmissionSupported
import assertions.VirologyAssertionsV2.requiresConfirmatoryTest
import assertions.VirologyAssertionsV2.shouldOfferFollowUpTest
import assertions.VirologyAssertionsV2.testEndDate
import assertions.VirologyAssertionsV2.testKit
import assertions.VirologyAssertionsV2.testResult
import org.http4k.cloudnative.env.Environment
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
import org.junit.jupiter.params.provider.EnumSource
import smoke.actors.ApiVersion.V2
import smoke.actors.MobileApp
import smoke.actors.TestLab
import smoke.actors.createHandler
import smoke.env.SmokeTests
import strikt.api.expectThat
import strikt.assertions.isA
import strikt.assertions.isEqualTo
import strikt.assertions.isFalse
import strikt.assertions.isNull
import uk.nhs.nhsx.core.headers.MobileAppVersion
import uk.nhs.nhsx.domain.Country
import uk.nhs.nhsx.domain.Country.Companion.England
import uk.nhs.nhsx.domain.Country.Companion.Wales
import uk.nhs.nhsx.domain.TestEndDate
import uk.nhs.nhsx.domain.TestJourney
import uk.nhs.nhsx.domain.TestJourney.CtaExchange
import uk.nhs.nhsx.domain.TestJourney.Lookup
import uk.nhs.nhsx.domain.TestKit
import uk.nhs.nhsx.domain.TestKit.LAB_RESULT
import uk.nhs.nhsx.domain.TestKit.RAPID_RESULT
import uk.nhs.nhsx.domain.TestKit.RAPID_SELF_REPORTED
import uk.nhs.nhsx.domain.TestResult
import uk.nhs.nhsx.domain.TestResult.Negative
import uk.nhs.nhsx.domain.TestResult.Plod
import uk.nhs.nhsx.domain.TestResult.Positive
import uk.nhs.nhsx.virology.VirologyUploadHandler.VirologyResultSource
import uk.nhs.nhsx.virology.VirologyUploadHandler.VirologyResultSource.Fiorano
import uk.nhs.nhsx.virology.VirologyUploadHandler.VirologyResultSource.Npex
import uk.nhs.nhsx.virology.VirologyUploadHandler.VirologyTokenExchangeSource
import uk.nhs.nhsx.virology.exchange.CtaExchangeResult
import uk.nhs.nhsx.virology.lookup.VirologyLookupResponseV2
import uk.nhs.nhsx.virology.lookup.VirologyLookupResult
import uk.nhs.nhsx.virology.order.VirologyOrderResponse
import uk.nhs.nhsx.virology.policy.VirologyCriteria
import uk.nhs.nhsx.virology.result.VirologyTokenStatusResponse
class VirologyV2SmokeTest {
private val client = createHandler(Environment.ENV)
private val config = SmokeTests.loadConfig()
private val mobileApp = MobileApp(client, config)
private val testLab = TestLab(client, config)
private fun expectedSupportedFlagFor(
testJourney: TestJourney,
country: Country,
testKit: TestKit,
testResult: TestResult
): Boolean {
val supported = setOf(
VirologyCriteria(Lookup, England, LAB_RESULT, Positive),
VirologyCriteria(Lookup, England, RAPID_RESULT, Positive),
VirologyCriteria(Lookup, England, RAPID_SELF_REPORTED, Positive),
VirologyCriteria(Lookup, Wales, LAB_RESULT, Positive),
VirologyCriteria(Lookup, Wales, RAPID_RESULT, Positive),
VirologyCriteria(Lookup, Wales, RAPID_SELF_REPORTED, Positive),
VirologyCriteria(CtaExchange, England, LAB_RESULT, Positive),
VirologyCriteria(CtaExchange, England, RAPID_RESULT, Positive),
VirologyCriteria(CtaExchange, England, RAPID_SELF_REPORTED, Positive),
VirologyCriteria(CtaExchange, Wales, LAB_RESULT, Positive),
VirologyCriteria(CtaExchange, Wales, RAPID_RESULT, Positive),
VirologyCriteria(CtaExchange, Wales, RAPID_SELF_REPORTED, Positive)
)
return supported.contains(VirologyCriteria(testJourney, country, testKit, testResult))
}
private fun expectedRequiredFlagFor(
testJourney: TestJourney,
country: Country,
testKit: TestKit,
testResult: TestResult
): Boolean {
val required = setOf<VirologyCriteria>()
return required.contains(VirologyCriteria(testJourney, country, testKit, testResult))
}
private fun lookupResponse(orderResponse: VirologyOrderResponse, country: Country): VirologyLookupResponseV2 {
val pollingToken = orderResponse.testResultPollingToken
return (mobileApp.pollForTestResult(pollingToken, V2, country) as VirologyLookupResult.AvailableV2).response
}
@ParameterizedTest
@EnumSource(TestKit::class)
fun `order, upload positive result and poll via npex for all test kits`(input: TestKit) {
val orderResponse = mobileApp.orderTest(V2)
testLab.uploadTestResult(
token = orderResponse.tokenParameterValue,
result = Positive,
testKit = input,
source = Npex,
apiVersion = V2
)
val testResponse: VirologyLookupResponseV2 = lookupResponse(orderResponse, England)
expectThat(testResponse) {
testResult.isEqualTo(Positive)
testKit.isEqualTo(input)
testEndDate.isEqualTo(TestEndDate.of(2020, 4, 23))
diagnosisKeySubmissionSupported.isEqualTo(
expectedSupportedFlagFor(Lookup, England, input, Positive)
)
requiresConfirmatoryTest.isEqualTo(
expectedRequiredFlagFor(Lookup, England, input, Positive)
)
confirmatoryDayLimit.isNull()
shouldOfferFollowUpTest.isFalse()
}
}
@Test
fun `order, upload plod result and poll via npex`() {
val orderResponse = mobileApp.orderTest(V2)
testLab.uploadTestResult(
token = orderResponse.tokenParameterValue,
result = Plod,
testKit = LAB_RESULT,
source = Npex,
apiVersion = V2
)
val testResponse = lookupResponse(orderResponse, England)
expectThat(testResponse) {
testResult.isEqualTo(Plod)
testKit.isEqualTo(LAB_RESULT)
testEndDate.isEqualTo(TestEndDate.of(2020, 4, 23))
diagnosisKeySubmissionSupported.isFalse()
requiresConfirmatoryTest.isFalse()
confirmatoryDayLimit.isNull()
shouldOfferFollowUpTest.isFalse()
}
}
@ParameterizedTest
@EnumSource(TestKit::class)
fun `order, upload positive result and poll via fiorano for all test kits`(input: TestKit) {
val orderResponse = mobileApp.orderTest(V2)
testLab.uploadTestResult(
token = orderResponse.tokenParameterValue,
result = Positive,
testKit = input,
source = Fiorano,
apiVersion = V2
)
val testResponse = lookupResponse(orderResponse, Wales)
expectThat(testResponse) {
testResult.isEqualTo(Positive)
testKit.isEqualTo(input)
testEndDate.isEqualTo(TestEndDate.of(2020, 4, 23))
diagnosisKeySubmissionSupported.isEqualTo(
expectedSupportedFlagFor(Lookup, Wales, input, Positive)
)
requiresConfirmatoryTest.isEqualTo(
expectedRequiredFlagFor(Lookup, Wales, input, Positive)
)
confirmatoryDayLimit.isNull()
shouldOfferFollowUpTest.isFalse()
}
}
@ParameterizedTest
@EnumSource(value = TestKit::class, names = ["RAPID_RESULT", "RAPID_SELF_REPORTED"])
fun `negative rapid test results uploaded via npex are rejected`(testKit: TestKit) {
val orderResponse = mobileApp.orderTest(V2)
testLab.uploadTestResultWithUnprocessableEntityV2(
token = orderResponse.tokenParameterValue,
result = Negative,
testKit = testKit,
source = Npex
)
}
@ParameterizedTest
@EnumSource(value = TestKit::class, names = ["RAPID_RESULT", "RAPID_SELF_REPORTED"])
fun `negative rapid test results uploaded via fiorano are rejected`(testKit: TestKit) {
val orderResponse = mobileApp.orderTest(V2)
testLab.uploadTestResultWithUnprocessableEntityV2(
token = orderResponse.tokenParameterValue,
result = Negative,
testKit = testKit,
source = Fiorano
)
}
@ParameterizedTest
@EnumSource(VirologyResultSource::class)
fun `order, upload and poll negative lab result for all sources`(source: VirologyResultSource) {
val orderResponse = mobileApp.orderTest(V2)
testLab.uploadTestResult(
token = orderResponse.tokenParameterValue,
result = Negative,
testKit = LAB_RESULT,
source = source,
apiVersion = V2
)
val testResponse = lookupResponse(orderResponse, England)
expectThat(testResponse) {
testResult.isEqualTo(Negative)
testKit.isEqualTo(LAB_RESULT)
testEndDate.isEqualTo(TestEndDate.of(2020, 4, 23))
diagnosisKeySubmissionSupported.isEqualTo(
expectedSupportedFlagFor(Lookup, England, LAB_RESULT, Negative)
)
requiresConfirmatoryTest.isEqualTo(
expectedRequiredFlagFor(Lookup, England, LAB_RESULT, Negative)
)
confirmatoryDayLimit.isNull()
shouldOfferFollowUpTest.isFalse()
}
}
@ParameterizedTest
@EnumSource(TestKit::class)
fun `lab token gen and cta exchange via eng source for all test kits`(input: TestKit) {
val ctaToken = testLab.generateCtaTokenFor(
testResult = Positive,
testEndDate = TestEndDate.of(2020, 11, 19),
source = VirologyTokenExchangeSource.Eng,
apiVersion = V2,
testKit = input
)
val exchangeResponse = mobileApp.exchange(ctaToken, V2, England)
expectThat(exchangeResponse)
.isA<CtaExchangeResult.AvailableV2>()
.get(CtaExchangeResult.AvailableV2::ctaExchangeResponse).and {
testResult.isEqualTo(Positive)
testEndDate.isEqualTo(TestEndDate.of(2020, 11, 19))
testKit.isEqualTo(input)
diagnosisKeySubmissionSupported.isEqualTo(
expectedSupportedFlagFor(CtaExchange, England, input, Positive)
)
requiresConfirmatoryTest.isEqualTo(
expectedRequiredFlagFor(CtaExchange, England, input, Positive)
)
confirmatoryDayLimit.isNull()
shouldOfferFollowUpTest.isFalse()
}
}
@Test
fun `lab token gen and cta exchange via eng source for all test kits`() {
val ctaToken = testLab.generateCtaTokenFor(
testResult = Plod,
testEndDate = TestEndDate.of(2020, 11, 19),
source = VirologyTokenExchangeSource.Eng,
apiVersion = V2,
testKit = LAB_RESULT
)
val exchangeResponse = mobileApp.exchange(ctaToken, V2, England)
expectThat(exchangeResponse)
.isA<CtaExchangeResult.AvailableV2>()
.get(CtaExchangeResult.AvailableV2::ctaExchangeResponse).and {
testResult.isEqualTo(Plod)
testKit.isEqualTo(LAB_RESULT)
testEndDate.isEqualTo(TestEndDate.of(2020, 11, 19))
diagnosisKeySubmissionSupported.isFalse()
requiresConfirmatoryTest.isFalse()
confirmatoryDayLimit.isNull()
shouldOfferFollowUpTest.isFalse()
}
}
@ParameterizedTest
@EnumSource(TestKit::class)
fun `lab token gen and cta exchange via wls source for all test kits`(input: TestKit) {
val ctaToken = testLab.generateCtaTokenFor(
testResult = Positive,
testEndDate = TestEndDate.of(2020, 11, 19),
source = VirologyTokenExchangeSource.Wls,
apiVersion = V2,
testKit = input
)
val exchangeResponse = mobileApp.exchange(ctaToken, V2, Wales)
expectThat(exchangeResponse)
.isA<CtaExchangeResult.AvailableV2>()
.get(CtaExchangeResult.AvailableV2::ctaExchangeResponse).and {
testResult.isEqualTo(Positive)
testKit.isEqualTo(input)
testEndDate.isEqualTo(TestEndDate.of(2020, 11, 19))
diagnosisKeySubmissionSupported.isEqualTo(
expectedSupportedFlagFor(CtaExchange, Wales, input, Positive)
)
requiresConfirmatoryTest.isEqualTo(
expectedRequiredFlagFor(CtaExchange, Wales, input, Positive)
)
confirmatoryDayLimit.isNull()
shouldOfferFollowUpTest.isFalse()
}
}
@ParameterizedTest
@CsvSource(value = ["4, 26, false", "4, 25, false"])
fun `cta exchange available for specific app versions which require confirmatory test`(
majorAppVersion: Int,
minorAppVersion: Int,
confirmatoryTestRequired: Boolean
) {
val ctaToken = testLab.generateCtaTokenFor(
testResult = Positive,
testEndDate = TestEndDate.of(2020, 11, 19),
source = VirologyTokenExchangeSource.Eng,
apiVersion = V2,
testKit = RAPID_SELF_REPORTED
)
val appVersion = MobileAppVersion.Version(majorAppVersion, minorAppVersion)
val mobileApp = MobileApp(client, config, appVersion = appVersion)
val exchangeResponse = mobileApp.exchange(ctaToken, V2, England)
expectThat(exchangeResponse).isA<CtaExchangeResult.AvailableV2>()
.get(CtaExchangeResult.AvailableV2::ctaExchangeResponse).and {
requiresConfirmatoryTest.isEqualTo(confirmatoryTestRequired)
shouldOfferFollowUpTest.isFalse()
}
}
@Test
fun `cta exchange for new app versions and criteria that sets confirmatory day limit for England`() {
val ctaToken = testLab.generateCtaTokenFor(
testResult = Positive,
testEndDate = TestEndDate.of(2020, 11, 19),
source = VirologyTokenExchangeSource.Eng,
apiVersion = V2,
testKit = RAPID_RESULT
)
val mobileApp = MobileApp(client, config, appVersion = MobileAppVersion.Version(4, 11))
val exchangeResponse = mobileApp.exchange(ctaToken, V2, England)
expectThat(exchangeResponse)
.isA<CtaExchangeResult.AvailableV2>()
.get(CtaExchangeResult.AvailableV2::ctaExchangeResponse).and {
confirmatoryDayLimit.isNull()
requiresConfirmatoryTest.isFalse()
shouldOfferFollowUpTest.isFalse()
}
}
@Test
fun `cta exchange for new app versions and criteria that sets confirmatory day limit for Wales`() {
val ctaToken = testLab.generateCtaTokenFor(
testResult = Positive,
testEndDate = TestEndDate.of(2020, 11, 19),
source = VirologyTokenExchangeSource.Wls,
apiVersion = V2,
testKit = RAPID_RESULT
)
val mobileApp = MobileApp(client, config, appVersion = MobileAppVersion.Version(4, 11))
val exchangeResponse = mobileApp.exchange(ctaToken, V2, Wales)
expectThat(exchangeResponse)
.isA<CtaExchangeResult.AvailableV2>()
.get(CtaExchangeResult.AvailableV2::ctaExchangeResponse).and {
confirmatoryDayLimit.isNull()
requiresConfirmatoryTest.isFalse()
shouldOfferFollowUpTest.isFalse()
}
}
@ParameterizedTest
@EnumSource(TestKit::class)
fun `check for token status returns consumable when token has been generated and not consumed for all Eng test kits`(
testKit: TestKit
) {
val ctaToken = testLab.generateCtaTokenFor(
testResult = Positive,
testEndDate = TestEndDate.of(2020, 11, 19),
source = VirologyTokenExchangeSource.Eng,
apiVersion = V2,
testKit = testKit
)
val tokenCheckResponse = testLab.checkToken(ctaToken, VirologyTokenExchangeSource.Eng)
expectThat(tokenCheckResponse)
.get(VirologyTokenStatusResponse::tokenStatus)
.isEqualTo("consumable")
}
@ParameterizedTest
@EnumSource(TestKit::class)
fun `check for token status returns consumable when token has been generated and not consumed for all Wls test kits`(
testKit: TestKit
) {
val ctaToken = testLab.generateCtaTokenFor(
testResult = Positive,
testEndDate = TestEndDate.of(2020, 11, 19),
source = VirologyTokenExchangeSource.Wls,
apiVersion = V2,
testKit = testKit
)
val tokenCheckResponse = testLab.checkToken(ctaToken, VirologyTokenExchangeSource.Wls)
expectThat(tokenCheckResponse)
.get(VirologyTokenStatusResponse::tokenStatus)
.isEqualTo("consumable")
}
@ParameterizedTest
@EnumSource(TestKit::class)
fun `check for token status returns other when token has been generated and consumed for all Eng test kits`(testKit: TestKit) {
val ctaToken = testLab.generateCtaTokenFor(
testResult = Positive,
testEndDate = TestEndDate.of(2020, 11, 19),
source = VirologyTokenExchangeSource.Eng,
apiVersion = V2,
testKit = testKit
)
mobileApp.exchange(ctaToken, V2, England)
val tokenCheckResponse = testLab.checkToken(ctaToken, VirologyTokenExchangeSource.Eng)
expectThat(tokenCheckResponse)
.get(VirologyTokenStatusResponse::tokenStatus)
.isEqualTo("other")
}
@ParameterizedTest
@EnumSource(TestKit::class)
fun `check for token status returns other when token has been generated and consumed for all Wls test kits`(testKit: TestKit) {
val ctaToken = testLab.generateCtaTokenFor(
testResult = Positive,
testEndDate = TestEndDate.of(2020, 11, 19),
source = VirologyTokenExchangeSource.Wls,
apiVersion = V2,
testKit = testKit
)
mobileApp.exchange(ctaToken, V2, Wales)
val tokenCheckResponse = testLab.checkToken(ctaToken, VirologyTokenExchangeSource.Wls)
expectThat(tokenCheckResponse)
.get(VirologyTokenStatusResponse::tokenStatus)
.isEqualTo("other")
}
}