Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-2103: Added get by nsiId #4115

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.SEXUAL
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.TITLE
import uk.gov.justice.digital.hmpps.integrations.delius.entity.ReferenceData
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.*
import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Staff
import java.time.LocalDate
import java.time.ZonedDateTime

Expand Down Expand Up @@ -131,13 +132,13 @@ object PersonGenerator {
id = IdGenerator.getAndIncrement()
)

fun generatePersonManager(person: Person) =
fun generatePersonManager(person: Person, staff: Staff? = StaffGenerator.ALLOCATED) =
PersonManager(
id = IdGenerator.getAndIncrement(),
trustProviderFlag = false,
person = person,
team = TeamGenerator.DEFAULT,
staff = StaffGenerator.ALLOCATED,
staff = staff,
provider = ProviderGenerator.DEFAULT,
date = ZonedDateTime.now().minusDays(2),
allocationReason = DEFAULT_ALLOCATION_REASON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ object StaffGenerator {
val ALLOCATED = generate("N01ABBA")
val OFFICER = generateOfficer()
val STAFF_USER = generateStaffUser()
fun generate(code: String, id: Long = IdGenerator.getAndIncrement(), grade: ReferenceData? = null) =
Staff(code, "Bob", "Micheal", "Smith", CourtGenerator.PROBATION_AREA, grade, null, id = id)
fun generate(
code: String,
id: Long = IdGenerator.getAndIncrement(),
grade: ReferenceData? = null,
user: StaffUser? = null
) =
Staff(code, "Bob", "Micheal", "Smith", CourtGenerator.PROBATION_AREA, grade, user = user, id = id)

fun generateStaffUser() = StaffUser(ALLOCATED, "JoeBloggs", IdGenerator.getAndIncrement())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"nsiId": 0,
"nsiType": {
"code": "NSITYPE",
"description": "NSI Type desc"
},
"nsiOutcome": {
"code": "BRE01",
"description": "this NSI is in breach"
},
"requirement": {
"requirementId": 93,
"requirementNotes": "notes",
"commencementDate": "2024-01-01",
"startDate": "2024-01-02",
"terminationDate": "2024-01-03",
"expectedStartDate": "2024-01-04",
"expectedEndDate": "2024-01-05",
"createdDatetime": "2023-12-31T12:00:00Z",
"active": true,
"requirementTypeSubCategory": {
"code": "Sub",
"description": "Sub cat"
},
"requirementTypeMainCategory": {
"code": "Main",
"description": "Main cat"
},
"adRequirementTypeMainCategory": {
"code": "AdMain",
"description": "AdMain cat"
},
"adRequirementTypeSubCategory": {
"code": "AdSub",
"description": "AdSub cat"
},
"terminationReason": {
"code": "R1",
"description": "Released"
},
"length": 3,
"lengthUnit": "months",
"restrictive": false,
"softDeleted": false
},
"nsiStatus": {
"code": "SLI01",
"description": "Active"
},
"statusDateTime": "2024-07-01T12:00:00+01:00",
"actualStartDate": "2024-07-26",
"expectedStartDate": "2024-01-01",
"actualEndDate": "2024-07-26",
"expectedEndDate": "2024-07-25",
"referralDate": "2024-07-27",
"length": 7,
"lengthUnit": "Months",
"nsiManagers": [
{
"probationArea": {
"probationAreaId": 78,
"code": "N52",
"description": "West Midlands Region",
"organisation": {
"code": "ORG1",
"description": "Org 1"
}
},
"team": {
"code": "T1",
"description": "Team1",
"telephone": "123",
"localDeliveryUnit": {
"code": "London",
"description": "LN1"
},
"district": {
"code": "London",
"description": "LN1"
},
"borough": {
"code": "LN1",
"description": "Default"
},
"teamType": {
"code": "London",
"description": "LN1"
},
"startDate": "2024-07-26"
},
"staff": {
"username": "JoeBloggs",
"staffCode": "N01ABBA",
"staffIdentifier": 80,
"staff": {
"forenames": "Bob Micheal",
"surname": "Smith"
},
"teams": [],
"probationArea": {
"probationAreaId": 78,
"code": "N52",
"description": "West Midlands Region",
"organisation": {
"code": "ORG1",
"description": "Org 1"
}
}
},
"startDate": "2024-07-26"
},
{
"probationArea": {
"probationAreaId": 78,
"code": "N52",
"description": "West Midlands Region",
"organisation": {
"code": "ORG1",
"description": "Org 1"
}
},
"team": {
"code": "T1",
"description": "Team1",
"telephone": "123",
"localDeliveryUnit": {
"code": "London",
"description": "LN1"
},
"district": {
"code": "London",
"description": "LN1"
},
"borough": {
"code": "LN1",
"description": "Default"
},
"teamType": {
"code": "London",
"description": "LN1"
},
"startDate": "2024-07-26"
},
"staff": {
"username": "JoeBloggs",
"staffCode": "N01ABBA",
"staffIdentifier": 80,
"staff": {
"forenames": "Bob Micheal",
"surname": "Smith"
},
"teams": [],
"probationArea": {
"probationAreaId": 78,
"code": "N52",
"description": "West Midlands Region",
"organisation": {
"code": "ORG1",
"description": "Org 1"
}
}
},
"startDate": "2024-07-19",
"endDate": "2024-07-25"
}
],
"notes": "notes",
"intendedProvider": {
"probationAreaId": 78,
"code": "N52",
"description": "West Midlands Region",
"organisation": {
"code": "ORG1",
"description": "Org 1"
}
},
"active": true,
"softDeleted": false,
"externalReference": "external ref"
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
"bodyFileName": "get_nsi_C123456.json"
}
},
{
"request": {
"method": "GET",
"urlPathTemplate": "/secure/offenders/crn/{crn}/convictions/{convictionId}/nsis/{nsiId}"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"bodyFileName": "get_single_nsi_C123456.json"
}
},
{
"request": {
"method": "GET",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class ConvictionByCrnAndEventIdIntegrationTest {
mockMvc
.perform(get("/probation-case/A123456/convictions/1").withToken())
.andExpect(status().isNotFound)
.andExpect(jsonPath("$.message").value("Person with crn of A123456 not found"))
.andExpect(jsonPath("$.developerMessage").value("Person with crn of A123456 not found"))
}

@Test
Expand All @@ -61,7 +61,7 @@ internal class ConvictionByCrnAndEventIdIntegrationTest {
mockMvc
.perform(get("/probation-case/$crn/convictions/3").withToken())
.andExpect(status().isNotFound)
.andExpect(jsonPath("$.message").value("Conviction with ID 3 for Offender with crn C123456 not found"))
.andExpect(jsonPath("$.developerMessage").value("Conviction with ID 3 for Offender with crn C123456 not found"))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal class ConvictionByCrnIntegrationTest {
mockMvc
.perform(get("/probation-case/A123456/convictions").withToken())
.andExpect(status().isNotFound)
.andExpect(jsonPath("$.message").value("Person with crn of A123456 not found"))
.andExpect(jsonPath("$.developerMessage").value("Person with crn of A123456 not found"))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.gov.justice.digital.hmpps

import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -12,12 +14,14 @@ import org.springframework.test.web.servlet.result.MockMvcResultHandlers
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import uk.gov.justice.digital.hmpps.api.model.*
import uk.gov.justice.digital.hmpps.api.resource.advice.ErrorResponse
import uk.gov.justice.digital.hmpps.data.generator.NsiManagerGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.RequirementsGenerator
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.BREACH_NSIS
import uk.gov.justice.digital.hmpps.integrations.delius.provider.entity.Staff
import uk.gov.justice.digital.hmpps.integrations.delius.service.toNsi
import uk.gov.justice.digital.hmpps.integrations.delius.service.toProbationArea
import uk.gov.justice.digital.hmpps.integrations.delius.service.toTeam
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson
Expand Down Expand Up @@ -55,7 +59,7 @@ internal class NsisByCrnAndConvictionIdIntegrationTest {
.withToken()
)
.andExpect(status().isNotFound)
.andExpect(jsonPath("$.message").value("Person with crn of A123456 not found"))
.andExpect(jsonPath("$.developerMessage").value("Person with crn of A123456 not found"))
}

@Test
Expand All @@ -69,7 +73,7 @@ internal class NsisByCrnAndConvictionIdIntegrationTest {
.withToken()
)
.andExpect(status().isNotFound)
.andExpect(jsonPath("$.message").value("Conviction with ID 3 for Offender with crn C123456 not found"))
.andExpect(jsonPath("$.developerMessage").value("Conviction with ID 3 for Offender with crn C123456 not found"))
}

@Test
Expand Down Expand Up @@ -146,4 +150,33 @@ internal class NsisByCrnAndConvictionIdIntegrationTest {
probationArea.toProbationArea(false),
grade?.keyValueOf()
)

@Test
fun `nsi by nsiId`() {
val crn = PersonGenerator.CURRENTLY_MANAGED.crn
val expectedNsi = BREACH_NSIS.toNsi()
val actualNsi = mockMvc
.perform(
get("/probation-case/$crn/convictions/${BREACH_NSIS.eventId}/nsis/${BREACH_NSIS.id}")
.withToken()
)
.andExpect(status().isOk)
.andReturn().response.contentAsJson<Nsi>()

MatcherAssert.assertThat(actualNsi.nsiOutcome, equalTo(expectedNsi.nsiOutcome))
}

@Test
fun `nsi by nsiId not found`() {
val crn = PersonGenerator.CURRENTLY_MANAGED.crn
val response = mockMvc
.perform(
get("/probation-case/$crn/convictions/${BREACH_NSIS.eventId}/nsis/999")
.withToken()
)
.andExpect(status().isNotFound)
.andReturn().response.contentAsJson<ErrorResponse>()

MatcherAssert.assertThat(response.developerMessage, equalTo("NSI with id 999 not found"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
import org.springframework.http.HttpStatus
import org.springframework.test.context.TestPropertySource
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import org.springframework.test.web.servlet.result.isEqualTo
import software.amazon.awssdk.utils.ImmutableMap
import uk.gov.justice.digital.hmpps.advice.ErrorResponse
import uk.gov.justice.digital.hmpps.api.model.*
import uk.gov.justice.digital.hmpps.api.resource.advice.ErrorResponse
import uk.gov.justice.digital.hmpps.data.generator.AreaGenerator.PARTITION_AREA
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator.ADDRESS
Expand All @@ -33,6 +34,7 @@ import java.time.LocalDate

@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = RANDOM_PORT)
@TestPropertySource(properties = ["lao-access.ignore-exclusions = false", "lao-access.ignore-restrictions = true"])
internal class OffenderIntegrationTest {
@Autowired
lateinit var mockMvc: MockMvc
Expand Down Expand Up @@ -336,7 +338,7 @@ internal class OffenderIntegrationTest {
.andExpect(status().isEqualTo(HttpStatus.FORBIDDEN.value()))
.andReturn().response.contentAsJson<ErrorResponse>()

assertThat(resp.message, equalTo(PersonGenerator.EXCLUDED_CASE.exclusionMessage))
assertThat(resp.developerMessage, equalTo(PersonGenerator.EXCLUDED_CASE.exclusionMessage))
}

@Test
Expand All @@ -353,7 +355,7 @@ internal class OffenderIntegrationTest {
.andExpect(status().isEqualTo(HttpStatus.FORBIDDEN.value()))
.andReturn().response.contentAsJson<ErrorResponse>()

assertThat(resp.message, equalTo(PersonGenerator.EXCLUDED_CASE.exclusionMessage))
assertThat(resp.developerMessage, equalTo(PersonGenerator.EXCLUDED_CASE.exclusionMessage))
}

@Test
Expand Down
Loading