|
| 1 | +package uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test |
| 4 | +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get |
| 5 | +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content |
| 6 | +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status |
| 7 | + |
| 8 | +class TransactionsIntegrationTest : IntegrationTestBase() { |
| 9 | + val prisonId = "MDI" |
| 10 | + val hmppsId = "G2996UX" |
| 11 | + val accountCode = "spends" |
| 12 | + final val fromDate = "2024-01-01" |
| 13 | + final val toDate = "2024-01-14" |
| 14 | + val transactionsPath = "/v1/prison" |
| 15 | + var dateQueryParams = "?from_date=$fromDate&to_date=$toDate" |
| 16 | + |
| 17 | + @Test |
| 18 | + fun `return a list of transactions for a prisoner`() { |
| 19 | + callApi("/v1/prison/$prisonId/prisoners/$hmppsId/transactions/$accountCode") |
| 20 | + .andExpect(status().isOk) |
| 21 | + .andExpect(content().json(getExpectedResponse("transactions-response"))) |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + fun `return a list of transactions when the dates are supplied in the request`() { |
| 26 | + val headers = org.springframework.http.HttpHeaders() |
| 27 | + headers.set("subject-distinguished-name", "C=GB,ST=London,L=London,O=Home Office,CN=automated-test-client") |
| 28 | + mockMvc |
| 29 | + .perform( |
| 30 | + get("$transactionsPath/$prisonId/prisoners/$hmppsId/transactions/$accountCode$dateQueryParams").headers(headers), |
| 31 | + ).andExpect(status().isOk) |
| 32 | + .andExpect(content().json(getExpectedResponse("transactions-response"))) |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + fun `returns no results`() { |
| 37 | + var wrongPrisonId = "XYZ" |
| 38 | + val headers = org.springframework.http.HttpHeaders() |
| 39 | + headers.set("subject-distinguished-name", "C=GB,ST=London,L=London,O=Home Office,CN=limited-prisons") |
| 40 | + mockMvc |
| 41 | + .perform( |
| 42 | + get("$transactionsPath/$wrongPrisonId/prisoners/$hmppsId/transactions/$accountCode").headers(headers), |
| 43 | + ).andExpect(status().isNotFound) |
| 44 | + } |
| 45 | +} |
0 commit comments