Skip to content

Commit

Permalink
PI-2365: Added feature flag for detail and summary (#4043)
Browse files Browse the repository at this point in the history
* PI-2365: Added feature flag for detail and summary

* Formatting changes

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
pmcphee77 and github-actions[bot] authored Jul 17, 2024
1 parent 432b6ef commit 6ca064d
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
],
"otherIds": {
"crn": "X320741",
"crn": "C123456",
"pncNumber": "2004/0712343H",
"croNumber": "123456/04A",
"nomsNumber": "G9542VP",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"request": {
"method": "GET",
"urlPath": "/secure/offenders/crn/X320741/all",
"urlPath": "/secure/offenders/crn/C123456/all",
"headers": {
"Content-Type": {
"equalTo": "application/json"
Expand All @@ -16,13 +16,13 @@
"headers": {
"Content-Type": "application/json"
},
"bodyFileName": "GET_offender_all_X320741.json"
"bodyFileName": "GET_offender_all_C123456.json"
}
},
{
"request": {
"method": "GET",
"urlPath": "/secure/offenders/crn/X320741",
"urlPath": "/secure/offenders/crn/C123456",
"headers": {
"Content-Type": {
"equalTo": "application/json"
Expand All @@ -34,7 +34,7 @@
"headers": {
"Content-Type": "application/json"
},
"bodyFileName": "GET_offender_X320741.json"
"bodyFileName": "GET_offender_C123456.json"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package uk.gov.justice.digital.hmpps

import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.kotlin.whenever
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken

@AutoConfigureMockMvc
Expand All @@ -17,18 +21,27 @@ internal class ProxyIntegrationTest {
@Autowired
lateinit var mockMvc: MockMvc

@MockBean
lateinit var featureFlags: FeatureFlags

@BeforeEach
fun setup() {
whenever(featureFlags.enabled("ccd-offender-detail-enabled")).thenReturn(false)
whenever(featureFlags.enabled("ccd-offender-summary-enabled")).thenReturn(false)
}

@Test
fun `proxies to community api for offenders all`() {
mockMvc
.perform(get("/secure/offenders/crn/X320741/all").withToken())
.perform(get("/secure/offenders/crn/C123456/all").withToken())
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$.otherIds.crn").value("X320741"))
.andExpect(jsonPath("$.otherIds.crn").value("C123456"))
}

@Test
fun `proxies to community api for offenders summary`() {
mockMvc
.perform(get("/secure/offenders/crn/X320741").withToken())
.perform(get("/secure/offenders/crn/C123456").withToken())
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$.contactDetails.addresses[0].town").value("Leicester"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package uk.gov.justice.digital.hmpps

import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.kotlin.whenever
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken

@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = RANDOM_PORT)
internal class ProxyToNewIntegrationTest {
@Autowired
lateinit var mockMvc: MockMvc

@MockBean
lateinit var featureFlags: FeatureFlags

@BeforeEach
fun setup() {
whenever(featureFlags.enabled("ccd-offender-detail-enabled")).thenReturn(true)
whenever(featureFlags.enabled("ccd-offender-summary-enabled")).thenReturn(true)
}

@Test
fun `proxies to community api for offenders all`() {
mockMvc
.perform(get("/secure/offenders/crn/C123456/all").withToken())
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$.otherIds.crn").value("C123456"))
}

@Test
fun `proxies to community api for offenders summary`() {
mockMvc
.perform(get("/secure/offenders/crn/C123456").withToken())
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$.contactDetails.emailAddresses[0]").value("[email protected]"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,42 @@ import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.client.HttpStatusCodeException
import uk.gov.justice.digital.hmpps.api.resource.ProbationRecordResource
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import java.net.URI

@RestController
@RequestMapping("secure/**")
@RequestMapping("secure")
class CommunityApiController(
@Value("\${community-api.url}") private val communityApiUrl: String,
private val probationRecordResource: ProbationRecordResource,
private val featureFlags: FeatureFlags,
private val communityApiClient: CommunityApiClient
) {
@GetMapping

@GetMapping("/offenders/crn/{crn}/all")
fun offenderDetail(request: HttpServletRequest, response: HttpServletResponse, @PathVariable crn: String): Any {

if (featureFlags.enabled("ccd-offender-detail-enabled")) {
return probationRecordResource.getOffenderDetail(crn)
}
return proxy(request, response)
}

@GetMapping("/offenders/crn/{crn}")
fun offenderSummary(request: HttpServletRequest, response: HttpServletResponse, @PathVariable crn: String): Any {

if (featureFlags.enabled("ccd-offender-summary-enabled")) {
return probationRecordResource.getOffenderDetailSummary(crn)
}
return proxy(request, response)
}

@GetMapping("/**")
fun proxy(request: HttpServletRequest, response: HttpServletResponse): ResponseEntity<String> {

val headers = request.headerNames.asSequence().associateWith { request.getHeader(it) }.toMutableMap()
Expand Down

0 comments on commit 6ca064d

Please sign in to comment.