@@ -20,6 +20,7 @@ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Transaction
20
20
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Type
21
21
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApi
22
22
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.UpstreamApiError
23
+ import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetTransactionForPersonService
23
24
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetTransactionsForPersonService
24
25
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.internal.AuditService
25
26
import java.time.LocalDate
@@ -30,15 +31,16 @@ class TransactionsControllerTest(
30
31
@Autowired var springMockMvc : MockMvc ,
31
32
@MockitoBean val auditService : AuditService ,
32
33
@MockitoBean val getTransactionsForPersonService : GetTransactionsForPersonService ,
34
+ @MockitoBean val getTransactionForPersonService : GetTransactionForPersonService ,
33
35
) : DescribeSpec(
34
36
{
35
37
val hmppsId = " 200313116M"
36
38
val prisonId = " ABC"
37
39
val accountCode = " spends"
38
- val clientUniqueRef = " client_unique_ref "
40
+ val clientUniqueRef = " ABC123456X "
39
41
val basePath = " /v1/prison/$prisonId /prisoners/$hmppsId "
40
42
val transactionsPath = " $basePath /accounts/$accountCode /transactions"
41
- val transactionPath = " $basePath /accounts /$clientUniqueRef /transactions "
43
+ val transactionPath = " $basePath /transactions /$clientUniqueRef "
42
44
val mockMvc = IntegrationAPIMockMvc (springMockMvc)
43
45
44
46
val transactions =
@@ -55,7 +57,15 @@ class TransactionsControllerTest(
55
57
),
56
58
)
57
59
58
- it("calls the service with expected parameters when supplied a date range") {
60
+ val transaction =
61
+ Transaction (
62
+ id = "123",
63
+ type = Type (code = "spends", desc = "Spends "),
64
+ amount = 100,
65
+ date = "2016-10-21",
66
+ description = "Spends desc",
67
+ )
68
+ it("calls the transactions service with expected parameters when supplied a date range") {
59
69
val dateParams = " ?from_date=2025-01-01&to_date=2025-01-01"
60
70
mockMvc.performAuthorised(transactionsPath + dateParams)
61
71
@@ -123,7 +133,65 @@ class TransactionsControllerTest(
123
133
),
124
134
)
125
135
val dateParams = " ?from_date=2025-01-01&to_date=2025-01-01"
126
- val result = mockMvc.performAuthorised(basePath + dateParams)
136
+ val result = mockMvc.performAuthorised(transactionsPath + dateParams)
137
+
138
+ result.response.status.shouldBe(HttpStatus .BAD_REQUEST .value())
139
+ }
140
+
141
+ // get Transaction
142
+ it("returns a prisoner's transaction according to clientUniqueRef") {
143
+ whenever(getTransactionForPersonService.execute(hmppsId, prisonId, clientUniqueRef, null)).thenReturn(Response (transaction))
144
+
145
+ val result = mockMvc.performAuthorised(transactionPath)
146
+
147
+ result.response.contentAsString.shouldContain(
148
+ """
149
+ {
150
+ "id": "123",
151
+ "type": {
152
+ "code": "spends",
153
+ "desc": "Spends "
154
+ },
155
+ "description": "Spends desc",
156
+ "amount": 100,
157
+ "date": "2016-10-21"
158
+ }
159
+ """.removeWhitespaceAndNewlines(),
160
+ )
161
+ }
162
+
163
+ it("returns a 404 NOT FOUND status code when could not find the transaction") {
164
+ whenever(getTransactionForPersonService.execute(hmppsId, prisonId, clientUniqueRef, null)).thenReturn(
165
+ Response (
166
+ data = null,
167
+ errors =
168
+ listOf(
169
+ UpstreamApiError (
170
+ causedBy = UpstreamApi .NOMIS ,
171
+ type = UpstreamApiError .Type .ENTITY_NOT_FOUND ,
172
+ ),
173
+ ),
174
+ ),
175
+ )
176
+ val result = mockMvc.performAuthorised(transactionPath)
177
+
178
+ result.response.status.shouldBe(HttpStatus .NOT_FOUND .value())
179
+ }
180
+
181
+ it("returns a 400 BAD REQUEST status code when there is an invalid HMPPS ID or incorrect prison, to get a singular transaction") {
182
+ whenever(getTransactionForPersonService.execute(hmppsId, prisonId, clientUniqueRef, null)).thenReturn(
183
+ Response (
184
+ data = null,
185
+ errors =
186
+ listOf(
187
+ UpstreamApiError (
188
+ causedBy = UpstreamApi .NOMIS ,
189
+ type = UpstreamApiError .Type .BAD_REQUEST ,
190
+ ),
191
+ ),
192
+ ),
193
+ )
194
+ val result = mockMvc.performAuthorised(transactionPath)
127
195
128
196
result.response.status.shouldBe(HttpStatus .BAD_REQUEST .value())
129
197
}
0 commit comments