|
1 | 1 | package uk.gov.justice.digital.hmpps.hmppsintegrationapi.controllers.v1.person
|
2 | 2 |
|
3 |
| -class PersonResponsibleOfficerControllerTest |
| 3 | +import io.kotest.core.spec.style.DescribeSpec |
| 4 | +import io.kotest.matchers.shouldBe |
| 5 | +import org.mockito.Mockito |
| 6 | +import org.mockito.kotlin.whenever |
| 7 | +import org.springframework.beans.factory.annotation.Autowired |
| 8 | +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest |
| 9 | +import org.springframework.boot.test.mock.mockito.MockBean |
| 10 | +import org.springframework.http.HttpStatus |
| 11 | +import org.springframework.test.context.ActiveProfiles |
| 12 | +import org.springframework.test.web.servlet.MockMvc |
| 13 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.helpers.IntegrationAPIMockMvc |
| 14 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.CommunityOffenderManager |
| 15 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PersonResponsibleOfficerName |
| 16 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Prison |
| 17 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.PrisonOffenderManager |
| 18 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Response |
| 19 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetCommunityOffenderManagerForPersonService |
| 20 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.GetPrisonOffenderManagerForPersonService |
| 21 | +import uk.gov.justice.digital.hmpps.hmppsintegrationapi.services.internal.AuditService |
| 22 | +import java.net.URLEncoder |
| 23 | +import java.nio.charset.StandardCharsets |
| 24 | + |
| 25 | +@WebMvcTest(controllers = [PersonResponsibleOfficerController::class]) |
| 26 | +@ActiveProfiles("test") |
| 27 | +internal class PersonResponsibleOfficerControllerTest( |
| 28 | + @Autowired var springMockMvc: MockMvc, |
| 29 | + @MockBean val auditService: AuditService, |
| 30 | + @MockBean val getCommunityOffenderManagerForPersonService: GetCommunityOffenderManagerForPersonService, |
| 31 | + @MockBean val getPrisonOffenderManagerForPersonService: GetPrisonOffenderManagerForPersonService, |
| 32 | +) : DescribeSpec() { |
| 33 | + init { |
| 34 | + val hmppsId = "9999/11111A" |
| 35 | + val encodedHmppsId = URLEncoder.encode(hmppsId, StandardCharsets.UTF_8) |
| 36 | + val path = "/v1/persons/$encodedHmppsId/person-responsible-officer" |
| 37 | + val mockMvc = IntegrationAPIMockMvc(springMockMvc) |
| 38 | + |
| 39 | + describe("GET $path") { |
| 40 | + beforeTest { |
| 41 | + Mockito.reset(getPrisonOffenderManagerForPersonService) |
| 42 | + Mockito.reset(getCommunityOffenderManagerForPersonService) |
| 43 | + whenever(getPrisonOffenderManagerForPersonService.execute(hmppsId)).thenReturn( |
| 44 | + Response( |
| 45 | + PrisonOffenderManager( |
| 46 | + forename = "Paul", |
| 47 | + surname = "Reds", |
| 48 | + prison = Prison(code = "PrisonCode1"), |
| 49 | + ), |
| 50 | + ), |
| 51 | + ) |
| 52 | + |
| 53 | + whenever(getCommunityOffenderManagerForPersonService.execute(hmppsId)).thenReturn( |
| 54 | + Response( |
| 55 | + CommunityOffenderManager( |
| 56 | + name = PersonResponsibleOfficerName("Helen", surname = "Miller"), |
| 57 | + email = "helenemail@email.com", |
| 58 | + telephoneNumber = "0987654321", |
| 59 | + team = |
| 60 | + PersonResponsibleOfficerTeam( |
| 61 | + code = "PrisonCode2", |
| 62 | + description = "Description", |
| 63 | + email = "email_again@email.com", |
| 64 | + telephoneNumber = "01234567890", |
| 65 | + ), |
| 66 | + ), |
| 67 | + ), |
| 68 | + ) |
| 69 | + Mockito.reset(auditService) |
| 70 | + } |
| 71 | + |
| 72 | + it("returns a 200 OK status code") { |
| 73 | + val result = mockMvc.performAuthorised(path) |
| 74 | + |
| 75 | + result.response.status.shouldBe(HttpStatus.OK.value()) |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments