1
1
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.services
2
2
3
3
import io.kotest.core.spec.style.DescribeSpec
4
+ import io.kotest.matchers.shouldBe
5
+ import org.mockito.Mockito
6
+ import org.mockito.internal.verification.VerificationModeFactory
7
+ import org.mockito.kotlin.verify
8
+ import org.mockito.kotlin.whenever
4
9
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer
5
10
import org.springframework.boot.test.mock.mockito.MockBean
6
11
import org.springframework.test.context.ContextConfiguration
@@ -9,14 +14,17 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
9
14
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Licence
10
15
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.LicenceCondition
11
16
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
17
+ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
18
+ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
19
+ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
12
20
13
21
@ContextConfiguration(
14
22
initializers = [ConfigDataApplicationContextInitializer ::class ],
15
23
classes = [GetLicenceConditionService ::class ],
16
24
)
17
25
internal class GetLicenceConditionServiceTest (
18
26
@MockBean val createAndVaryLicenceGateway : CreateAndVaryLicenceGateway ,
19
- // @MockBean val getPersonService: GetPersonService,
27
+ @MockBean val getPersonService : GetPersonService ,
20
28
private val getLicenceConditionService : GetLicenceConditionService ,
21
29
) : DescribeSpec(
22
30
{
@@ -26,59 +34,60 @@ internal class GetLicenceConditionServiceTest(
26
34
val licences = listOf(Licence (id = "12345"))
27
35
val conditions = listOf(LicenceCondition (condition = "MockCondition ", category = "AP "))
28
36
29
- // beforeEach {
30
- // // Mockito.reset(getPersonService)
31
- // Mockito.reset(createAndVaryLicenceGateway)
32
- //
33
- // // whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn(Response(person))
34
- // whenever(createAndVaryLicenceGateway.getLicenceSummaries(id = crn)).thenReturn(Response(licences))
35
- // whenever(createAndVaryLicenceGateway.getLicenceConditions(id = 12345)).thenReturn(Response(conditions))
36
- // }
37
- // it("performs a search according to hmpps Id") {
38
- // getLicenceConditionService.execute(hmppsId)
39
- // verify(getPersonService, VerificationModeFactory.times(1)).execute(hmppsId = hmppsId)
40
- // }
37
+ beforeEach {
38
+ Mockito .reset(getPersonService)
39
+ Mockito .reset(createAndVaryLicenceGateway)
41
40
42
- // it("should return a list of errors if person not found") {
43
- // // whenever(getPersonService.execute(hmppsId = "notfound")).thenReturn(
44
- // // Response(
45
- // // data = null,
46
- // // errors =
47
- // // listOf(
48
- // // UpstreamApiError(
49
- // // causedBy = UpstreamApi.CVL,
50
- // // type = UpstreamApiError.Type.ENTITY_NOT_FOUND,
51
- // // ),
52
- // // ),
53
- // // ),
54
- // // )
55
- // val result = getLicenceConditionService.execute("notfound")
56
- // result.data.licences.shouldBe(emptyList())
57
- // result.errors.first().type.shouldBe(UpstreamApiError.Type.ENTITY_NOT_FOUND)
58
- // }
41
+ whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn(Response (person))
42
+ whenever(createAndVaryLicenceGateway.getLicenceSummaries(id = crn)).thenReturn(Response (licences))
43
+ whenever(createAndVaryLicenceGateway.getLicenceConditions(id = 12345)).thenReturn(Response (conditions))
44
+ }
59
45
60
- // it("should return a list of errors if create and vary licence gateway service returns error") {
61
- // whenever(createAndVaryLicenceGateway.getLicenceSummaries(id = crn)).thenReturn(
62
- // Response(
63
- // data = emptyList(),
64
- // errors =
65
- // listOf(
66
- // UpstreamApiError(
67
- // causedBy = UpstreamApi.CVL,
68
- // type = UpstreamApiError.Type.ENTITY_NOT_FOUND,
69
- // ),
70
- // ),
71
- // ),
72
- // )
73
- // val result = getLicenceConditionService.execute(hmppsId = hmppsId)
74
- // result.data.licences.shouldBe(emptyList())
75
- // result.errors.first().type.shouldBe(UpstreamApiError.Type.ENTITY_NOT_FOUND)
76
- // }
77
- //
78
- // it("should return licence condition from gateway") {
79
- // val result = getLicenceConditionService.execute(hmppsId = hmppsId)
80
- // result.data.licences.first().conditions.first().condition.shouldBe("MockCondition")
81
- // result.errors.count().shouldBe(0)
82
- // }
46
+ it("performs a search according to hmpps Id ") {
47
+ getLicenceConditionService.execute(hmppsId)
48
+ verify(getPersonService, VerificationModeFactory .times(1)).execute(hmppsId = hmppsId)
49
+ }
50
+
51
+ it("should return a list of errors if person not found") {
52
+ whenever(getPersonService.execute(hmppsId = "notfound")).thenReturn(
53
+ Response (
54
+ data = null,
55
+ errors =
56
+ listOf(
57
+ UpstreamApiError (
58
+ causedBy = UpstreamApi .CVL ,
59
+ type = UpstreamApiError .Type .ENTITY_NOT_FOUND ,
60
+ ),
61
+ ),
62
+ ),
63
+ )
64
+ val result = getLicenceConditionService.execute("notfound")
65
+ result.data.licences.shouldBe(emptyList())
66
+ result.errors.first().type.shouldBe(UpstreamApiError .Type .ENTITY_NOT_FOUND )
67
+ }
68
+
69
+ it("should return a list of errors if create and vary licence gateway service returns error") {
70
+ whenever(createAndVaryLicenceGateway.getLicenceSummaries(id = crn)).thenReturn(
71
+ Response (
72
+ data = emptyList(),
73
+ errors =
74
+ listOf(
75
+ UpstreamApiError (
76
+ causedBy = UpstreamApi .CVL ,
77
+ type = UpstreamApiError .Type .ENTITY_NOT_FOUND ,
78
+ ),
79
+ ),
80
+ ),
81
+ )
82
+ val result = getLicenceConditionService.execute(hmppsId = hmppsId)
83
+ result.data.licences.shouldBe(emptyList())
84
+ result.errors.first().type.shouldBe(UpstreamApiError .Type .ENTITY_NOT_FOUND )
85
+ }
86
+
87
+ it("should return licence condition from gateway") {
88
+ val result = getLicenceConditionService.execute(hmppsId = hmppsId)
89
+ result.data.licences.first().conditions.first().condition.shouldBe("MockCondition ")
90
+ result.errors.count().shouldBe(0)
91
+ }
83
92
},
84
93
)
0 commit comments