|
1 | 1 | package uk.gov.justice.digital.hmpps.hmppsintegrationapi.services
|
2 | 2 |
|
3 |
| -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.AccountBalance |
4 |
| -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Balances |
5 |
| -import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisAccounts |
6 |
| - |
7 | 3 | import io.kotest.core.spec.style.DescribeSpec
|
8 | 4 | import io.kotest.matchers.shouldBe
|
9 | 5 | import org.mockito.Mockito
|
10 | 6 | import org.mockito.internal.verification.VerificationModeFactory
|
11 | 7 | import org.mockito.kotlin.verify
|
12 | 8 | import org.mockito.kotlin.whenever
|
13 | 9 | import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer
|
14 |
| -import org.springframework.boot.test.context.SpringBootTest |
15 | 10 | import org.springframework.test.context.ContextConfiguration
|
16 | 11 | import org.springframework.test.context.bean.override.mockito.MockitoBean
|
17 | 12 | import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.NomisGateway
|
18 | 13 | import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Identifiers
|
19 | 14 | import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Person
|
20 | 15 | import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response
|
| 16 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.nomis.NomisAccounts |
21 | 17 |
|
22 | 18 | @ContextConfiguration(
|
23 | 19 | initializers = [ConfigDataApplicationContextInitializer::class],
|
24 | 20 | classes = [GetBalancesForPersonService::class],
|
25 | 21 | )
|
26 |
| - |
27 | 22 | internal class GetBalancesForPersonServiceTest(
|
28 | 23 | @MockitoBean val nomisGateway: NomisGateway,
|
29 | 24 | @MockitoBean val getPersonService: GetPersonService,
|
30 | 25 | private val getBalancesForPersonService: GetBalancesForPersonService,
|
31 | 26 | ) : DescribeSpec(
|
32 |
| - { |
33 |
| - val hmppsId = "1234/56789B" |
34 |
| - val prisonerId = "Z99999ZZ" |
35 |
| - val prisonId = "ABC" |
36 |
| - |
37 |
| - val personFromPrisonOffenderSearch = |
38 |
| - Person( |
39 |
| - firstName = "Chandler", |
40 |
| - lastName = "ProbationBing", |
41 |
| - identifiers = Identifiers(nomisNumber = prisonerId), |
42 |
| - ) |
43 |
| - |
44 |
| - beforeEach { |
45 |
| - Mockito.reset(getPersonService) |
46 |
| - Mockito.reset(nomisGateway) |
47 |
| - |
48 |
| - require(hmppsId.matches(Regex("^[0-9]+/[0-9A-Za-z]+$"))) { |
49 |
| - "Invalid Hmpps Id format: $hmppsId" |
| 27 | + { |
| 28 | + val hmppsId = "1234/56789B" |
| 29 | + val prisonerId = "Z99999ZZ" |
| 30 | + val prisonId = "ABC" |
| 31 | + val nomisSpends = 100 |
| 32 | + val nomisSavings = 100 |
| 33 | + val nomisCash = 100 |
| 34 | + |
| 35 | + val personFromPrisonOffenderSearch = |
| 36 | + Person( |
| 37 | + firstName = "Chandler", |
| 38 | + lastName = "ProbationBing", |
| 39 | + identifiers = Identifiers(nomisNumber = prisonerId), |
| 40 | + ) |
| 41 | + |
| 42 | + beforeEach { |
| 43 | + Mockito.reset(getPersonService) |
| 44 | + Mockito.reset(nomisGateway) |
| 45 | + |
| 46 | + require(hmppsId.matches(Regex("^[0-9]+/[0-9A-Za-z]+$"))) { |
| 47 | + "Invalid Hmpps Id format: $hmppsId" |
| 48 | + } |
| 49 | + |
| 50 | + whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn( |
| 51 | + Response( |
| 52 | + data = personFromPrisonOffenderSearch, |
| 53 | + ), |
| 54 | + ) |
| 55 | + |
| 56 | + whenever(nomisGateway.getAccountsForPerson(prisonId, prisonerId)).thenReturn( |
| 57 | + Response( |
| 58 | + data = |
| 59 | + NomisAccounts(spends = nomisSpends, savings = nomisSavings, cash = nomisCash), |
| 60 | + ), |
| 61 | + ) |
50 | 62 | }
|
| 63 | +// val expectedNomisAccounts = nomisGateway.getAccountsForPerson(prisonId, prisonerId).data |
| 64 | +// val balance = Balances( |
| 65 | +// accountBalances = arrayOf( |
| 66 | +// AccountBalance(accountCode = "spends", amount = nomisSpends), |
| 67 | +// AccountBalance(accountCode = "saving", amount = nomisSavings), |
| 68 | +// AccountBalance(accountCode = "cash", amount = nomisCash), |
| 69 | +// ) |
| 70 | +// ) |
| 71 | + val balance = arrayOf(mapOf("accountCode:" to "spends", "amount:" to nomisSpends), mapOf("accountCode:" to "savings", "amount:" to nomisSavings), mapOf("accountCode:" to "cash", "amount:" to nomisCash)) |
51 | 72 |
|
52 |
| - whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn( |
53 |
| - Response( |
54 |
| - data = personFromPrisonOffenderSearch, |
55 |
| - ), |
56 |
| - ) |
57 |
| - |
58 |
| - whenever(nomisGateway.getAccountsForPerson(prisonId, prisonerId)).thenReturn( |
59 |
| - Response( |
60 |
| - data = |
61 |
| - NomisAccounts(spends = 100, savings = 100, cash = 100) |
62 |
| - ), |
63 |
| - ) |
64 |
| - |
65 |
| - } |
66 |
| - val expectedNomisAccounts = nomisGateway.getAccountsForPerson(prisonId, prisonerId).data |
67 |
| - val balance = Balances( |
68 |
| - accountBalances = arrayOf( |
69 |
| - AccountBalance(accountCode = "spends", amount = expectedNomisAccounts?.spends), |
70 |
| - AccountBalance(accountCode = "saving", amount = expectedNomisAccounts?.savings), |
71 |
| - AccountBalance(accountCode = "cash", amount = expectedNomisAccounts?.cash) |
72 |
| - ) |
73 |
| - ) |
74 |
| - |
75 |
| - it("gets a person using a Hmpps ID") { |
76 |
| - getBalancesForPersonService.execute(prisonId, hmppsId) |
77 |
| - |
78 |
| - verify(getPersonService, VerificationModeFactory.times(1)).execute(hmppsId = hmppsId) |
79 |
| - } |
80 |
| - |
81 |
| - |
82 |
| - it("gets accounts from NOMIS using a prisoner number") { |
83 |
| - getBalancesForPersonService.execute(prisonId, hmppsId) |
84 |
| - |
85 |
| - verify(nomisGateway, VerificationModeFactory.times(1)).getAccountsForPerson(prisonId = prisonId, nomisNumber = prisonerId) |
86 |
| - } |
| 73 | + it("gets a person using a Hmpps ID") { |
| 74 | + getBalancesForPersonService.execute(prisonId, hmppsId) |
87 | 75 |
|
88 |
| - it("Returns a persons account balances given a hmppsId") { |
89 |
| - whenever(getPersonService.execute(hmppsId = hmppsId)).thenReturn( |
90 |
| - Response( |
91 |
| - data = personFromPrisonOffenderSearch, |
92 |
| - ), |
93 |
| - ) |
| 76 | + verify(getPersonService, VerificationModeFactory.times(1)).execute(hmppsId = hmppsId) |
| 77 | + } |
94 | 78 |
|
95 |
| - val result = getBalancesForPersonService.execute(prisonId, hmppsId) |
| 79 | + it("gets accounts from NOMIS using a prisoner number") { |
| 80 | + getBalancesForPersonService.execute(prisonId, hmppsId) |
96 | 81 |
|
97 |
| - result.shouldBe( |
98 |
| - Response(data = mapOf("prisonId" to prisonId, "prisonerId" to prisonerId, "balances" to balance)), |
99 |
| - ) |
100 |
| - } |
| 82 | + verify(nomisGateway, VerificationModeFactory.times(1)).getAccountsForPerson(prisonId = prisonId, nomisNumber = prisonerId) |
| 83 | + } |
101 | 84 |
|
| 85 | + it("Returns a persons account balances given a hmppsId") { |
| 86 | + val result = getBalancesForPersonService.execute(prisonId, hmppsId) |
102 | 87 |
|
103 |
| - } |
104 |
| -) |
| 88 | + result.data.shouldBe( |
| 89 | + mapOf("prisonId" to prisonId, "prisonerId" to prisonerId, "balances" to balance), |
| 90 | + ) |
| 91 | + } |
| 92 | + }, |
| 93 | + ) |
105 | 94 |
|
106 | 95 | // describe("when an upstream API returns an error when looking up a person from a Hmpps ID") {
|
107 | 96 | // beforeEach {
|
@@ -170,5 +159,4 @@ internal class GetBalancesForPersonServiceTest(
|
170 | 159 | // response.errors.shouldHaveSize(2)
|
171 | 160 | // }
|
172 | 161 | // },
|
173 |
| -//) |
174 |
| - |
| 162 | +// ) |
0 commit comments