Skip to content

Commit 503405b

Browse files
[HIA-721]
WIP getting some tests set up for the Gateway
1 parent e947ebf commit 503405b

File tree

5 files changed

+125
-1
lines changed

5 files changed

+125
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways;
2+
3+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.assessRisksAndNeeds.CrnRiskManagementPlans
4+
5+
class RiskManagementGateway {
6+
7+
fun getRiskManagementPlansForCrn(crn: String): CrnRiskManagementPlans {
8+
return CrnRiskManagementPlans(crn, "plan", emptyList())
9+
}
10+
}

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/models/assessRisksAndNeeds/CrnRiskManagementPlans.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data class CrnRiskManagementPlans(
88
val limitedAccessOffender: String,
99
val riskManagementPlan: List<CrnRiskManagementPlan>
1010
) {
11-
fun toRiskManagementPlan(): List<RiskManagementPlan> {
11+
fun toRiskManagementPlans(): List<RiskManagementPlan> {
1212
return this.riskManagementPlan.stream()
1313
.map {
1414
RiskManagementPlan(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"crn": "D1974X",
3+
"limitedAccessOffender": true,
4+
"riskManagementPlan": [
5+
{
6+
"assessmentId": 0,
7+
"dateCompleted": "2024-05-04T01:04:20",
8+
"partcompStatus": "string",
9+
"initiationDate": "2024-05-04T01:04:20",
10+
"assessmentStatus": "string",
11+
"assessmentType": "string",
12+
"superStatus": "string",
13+
"keyInformationCurrentSituation": "string",
14+
"furtherConsiderationsCurrentSituation": "string",
15+
"supervision": "string",
16+
"monitoringAndControl": "string",
17+
"interventionsAndTreatment": "string",
18+
"victimSafetyPlanning": "string",
19+
"contingencyPlans": "string",
20+
"laterWIPAssessmentExists": true,
21+
"latestWIPDate": "2024-05-04T01:04:20",
22+
"laterSignLockAssessmentExists": true,
23+
"latestSignLockDate": "2024-05-04T01:04:20",
24+
"laterPartCompUnsignedAssessmentExists": true,
25+
"latestPartCompUnsignedDate": "2024-05-04T01:04:20",
26+
"laterPartCompSignedAssessmentExists": true,
27+
"latestPartCompSignedDate": "2024-05-04T01:04:20",
28+
"laterCompleteAssessmentExists": true,
29+
"latestCompleteDate": "2024-05-04T01:04:20"
30+
}
31+
]
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.riskManagement
2+
3+
import io.kotest.core.spec.style.DescribeSpec
4+
import org.mockito.Mockito
5+
import org.mockito.internal.verification.VerificationModeFactory
6+
import org.mockito.kotlin.verify
7+
import org.mockito.kotlin.whenever
8+
import org.springframework.boot.test.mock.mockito.MockBean
9+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.HmppsAuthGateway
10+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.gateways.RiskManagementGateway
11+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.HmppsAuthMockServer
12+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.RiskManagementApiMockServer
13+
import java.io.File
14+
15+
class RiskManagementGatewayTest (
16+
@MockBean val hmppsAuthGateway: HmppsAuthGateway,
17+
private val riskManagementGateway: RiskManagementGateway,
18+
) : DescribeSpec({
19+
20+
val riskManagementMockServer = RiskManagementApiMockServer()
21+
22+
beforeEach{
23+
riskManagementMockServer.start()
24+
Mockito.reset(hmppsAuthGateway)
25+
26+
whenever(hmppsAuthGateway.getClientToken("Risk Management Plan Search")).thenReturn(HmppsAuthMockServer.TOKEN)
27+
}
28+
29+
afterTest {
30+
riskManagementMockServer.stop()
31+
}
32+
33+
describe("get risks for given crn") {
34+
val crn = "D1974X"
35+
36+
riskManagementMockServer.stubGetRiskManagementPlan(
37+
crn,
38+
File(
39+
"src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/riskManagement/fixtures/GetRiskManagementPlanResponse.json",
40+
).readText(),
41+
)
42+
43+
it("authenticates using HMPPS Auth with credentials") {
44+
riskManagementGateway.getRiskManagementPlansForCrn(crn)
45+
46+
verify(hmppsAuthGateway, VerificationModeFactory.times(1)).getClientToken("Prisoner Offender Search")
47+
}
48+
49+
}
50+
51+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers
2+
3+
import com.github.tomakehurst.wiremock.WireMockServer
4+
import com.github.tomakehurst.wiremock.client.WireMock.matching
5+
import com.github.tomakehurst.wiremock.client.WireMock.get
6+
import com.github.tomakehurst.wiremock.client.WireMock.aResponse
7+
import org.springframework.http.HttpStatus
8+
9+
class RiskManagementApiMockServer : WireMockServer(WIREMOCK_PORT) {
10+
companion object {
11+
private const val WIREMOCK_PORT = 4009
12+
}
13+
14+
fun stubGetRiskManagementPlan(
15+
crn: String,
16+
responseBody: String,
17+
status: HttpStatus = HttpStatus.OK,
18+
) {
19+
stubFor(
20+
get("risks/crn/$crn/risk-management-plan")
21+
.withHeader("Authorization", matching("Bearer ${HmppsAuthMockServer.TOKEN}"))
22+
.willReturn(
23+
aResponse()
24+
.withHeader("Content-Type", "application/json")
25+
.withStatus(status.value())
26+
.withBody(responseBody.trimIndent()),
27+
),
28+
)
29+
}
30+
31+
}

0 commit comments

Comments
 (0)