Skip to content

Commit

Permalink
PI-2400: Sent reports without values to app insights (#4080)
Browse files Browse the repository at this point in the history
* PI-2400: Sent reports without values to app insights
  • Loading branch information
pmcphee77 authored Jul 30, 2024
1 parent 9412145 commit 0b1af66
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.RELIGI
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.SECOND_NATIONALITY
import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator.SEXUAL_ORIENTATION
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 java.time.LocalDate
import java.time.ZonedDateTime
Expand Down Expand Up @@ -56,25 +57,32 @@ object PersonGenerator {
id: Long = IdGenerator.getAndIncrement(),
currentDisposal: Boolean = false,
currentExclusion: Boolean = false,
currentRestriction: Boolean = false
currentRestriction: Boolean = false,
emailAddress: String? = "[email protected]",
secondName: String? = "MiddleName",
thirdName: String? = "OtherMiddleName",
mobileNumber: String? = "07876545678",
telephoneNumber: String? = "0161786567",
title: ReferenceData? = TITLE,
currentTier: ReferenceData? = DEFAULT_TIER
) =
Person(
id = id,
crn = crn,
softDeleted = softDeleted,
emailAddress = "[email protected]",
emailAddress = emailAddress,
currentDisposal = currentDisposal,
currentExclusion = currentExclusion,
currentRestriction = currentRestriction,
currentHighestRiskColour = "RED",
dateOfBirth = LocalDate.of(1977, 8, 12),
partitionArea = PARTITION_AREA,
allowSms = true,
mobileNumber = "07876545678",
telephoneNumber = "0161786567",
mobileNumber = mobileNumber,
telephoneNumber = telephoneNumber,
forename = "TestForename",
secondName = "MiddleName",
thirdName = "OtherMiddleName",
secondName = secondName,
thirdName = thirdName,
gender = GENDER_MALE,
surname = "TestSurname",
preferredName = "Other name",
Expand All @@ -98,11 +106,11 @@ object PersonGenerator {
immigrationNumber = "IMA123",
mostRecentPrisonerNumber = "PRS123",
previousSurname = "Previous",
title = TITLE,
title = title,
offenderManagers = emptyList(),
restrictionMessage = "restrictionMessage",
exclusionMessage = "exclusionMessage",
currentTier = DEFAULT_TIER
currentTier = currentTier
)

fun generatePrisonManager(person: Person) = PrisonManager(
Expand Down Expand Up @@ -139,14 +147,14 @@ object PersonGenerator {
providerEmployee = ProviderEmployeeGenerator.PROVIDER_EMPLOYEE
)

fun generatePersonAlias(person: Person) =
fun generatePersonAlias(person: Person, secondName: String? = "Reg", thirdName: String? = "Xavier") =
OffenderAlias(
aliasID = IdGenerator.getAndIncrement(),
personId = person.id,
dateOfBirth = LocalDate.of(1968, 1, 1),
firstName = "Bob",
secondName = "Reg",
thirdName = "Xavier",
secondName = secondName,
thirdName = thirdName,
surname = "Potts",
gender = GENDER_MALE,
softDeleted = false
Expand Down Expand Up @@ -174,24 +182,25 @@ object PersonGenerator {
finishDate = end,
)

fun generateAddress(personId: Long, softDeleted: Boolean) = PersonAddress(
id = IdGenerator.getAndIncrement(),
personId = personId,
type = DEFAULT_ADDRESS_TYPE,
status = DEFAULT_ADDRESS_STATUS,
streetName = "A Street",
town = "A town",
county = "A county",
postcode = "NE209XL",
telephoneNumber = "089876765",
buildingName = "The building",
district = "A District",
addressNumber = "20",
noFixedAbode = false,
typeVerified = true,
startDate = LocalDate.now().minusDays(1),
endDate = null,
softDeleted = softDeleted,
createdDatetime = ZonedDateTime.now().minusDays(1),
)
fun generateAddress(personId: Long, softDeleted: Boolean, type: ReferenceData? = DEFAULT_ADDRESS_TYPE) =
PersonAddress(
id = IdGenerator.getAndIncrement(),
personId = personId,
type = type,
status = DEFAULT_ADDRESS_STATUS,
streetName = "A Street",
town = "A town",
county = "A county",
postcode = "NE209XL",
telephoneNumber = "089876765",
buildingName = "The building",
district = "A District",
addressNumber = "20",
noFixedAbode = false,
typeVerified = true,
startDate = LocalDate.now().minusDays(1),
endDate = null,
softDeleted = softDeleted,
createdDatetime = ZonedDateTime.now().minusDays(1),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ internal class OffenderIntegrationTest {
assertThat(detailResponse.offenderAliases?.get(0)?.dateOfBirth, equalTo(LocalDate.of(1968, 1, 1)))
assertThat(detailResponse.offenderAliases?.get(0)?.firstName, equalTo("Bob"))
assertThat(
detailResponse.offenderManagers[0].providerEmployee,
detailResponse.offenderManagers?.get(0)?.providerEmployee,
equalTo(Human("ProvEmpForename1 ProvEmpForename2", "ProvEmpSurname"))
)
assertThat(detailResponse.offenderManagers[0].trustOfficer, equalTo(Human("Off1 Off2", "OffSurname")))
assertThat(detailResponse.offenderManagers?.get(0)?.trustOfficer, equalTo(Human("Off1 Off2", "OffSurname")))
assertThat(
detailResponse.offenderManagers[0].probationArea.description,
detailResponse.offenderManagers?.get(0)?.probationArea?.description,
equalTo(ProviderGenerator.DEFAULT.description)
)
assertThat(
detailResponse.offenderManagers[0].staff,
detailResponse.offenderManagers?.get(0)?.staff,
equalTo(
StaffHuman(
ALLOCATED.code,
Expand All @@ -240,10 +240,16 @@ internal class OffenderIntegrationTest {
)
)
)
assertThat(detailResponse.offenderManagers[0].allocationReason, equalTo(DEFAULT_ALLOCATION_REASON.keyValueOf()))
assertThat(detailResponse.offenderManagers[0].partitionArea, equalTo(PARTITION_AREA.area))
assertThat(detailResponse.offenderManagers[0].team!!.code.trim(), equalTo(TeamGenerator.DEFAULT.code.trim()))
assertThat(detailResponse.offenderManagers[0].team!!.description, equalTo(TeamGenerator.DEFAULT.description))
assertThat(
detailResponse.offenderManagers?.get(0)?.allocationReason,
equalTo(DEFAULT_ALLOCATION_REASON.keyValueOf())
)
assertThat(detailResponse.offenderManagers?.get(0)?.partitionArea, equalTo(PARTITION_AREA.area))
assertThat(
detailResponse.offenderManagers?.get(0)?.team!!.code.trim(),
equalTo(TeamGenerator.DEFAULT.code.trim())
)
assertThat(detailResponse.offenderManagers!![0].team!!.description, equalTo(TeamGenerator.DEFAULT.description))
assertThat(detailResponse.offenderProfile.religion, equalTo(RELIGION.description))
assertThat(detailResponse.offenderProfile.remandStatus, equalTo("Remand Status"))
assertThat(detailResponse.offenderProfile.riskColour, equalTo("RED"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ internal class ProxyIntegrationTest {
).andExpect(status().is2xxSuccessful).andReturn().response.contentAsJson<CompareReport>()

assertThat(res.endPointName, equalTo("CONVICTION_REQUIREMENTS"))
assertThat(res.success, equalTo(true))
assertThat(res.success, equalTo(false))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ package uk.gov.justice.digital.hmpps

import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.eq
import org.mockito.kotlin.verify
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.scheduling.concurrent.ThreadPoolTaskExecutor
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.telemetry.TelemetryService
import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken

@AutoConfigureMockMvc
Expand All @@ -21,9 +26,15 @@ internal class ProxyToNewIntegrationTest {
@Autowired
lateinit var mockMvc: MockMvc

@Autowired
lateinit var taskExecutor: ThreadPoolTaskExecutor

@MockBean
lateinit var featureFlags: FeatureFlags

@MockBean
lateinit var telemetryService: TelemetryService

@BeforeEach
fun setup() {
whenever(featureFlags.enabled("ccd-offender-detail-enabled")).thenReturn(true)
Expand All @@ -32,10 +43,14 @@ internal class ProxyToNewIntegrationTest {

@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"))

whileTrue { taskExecutor.threadPoolExecutor.completedTaskCount == 0L }
verify(telemetryService).trackEvent(eq("ComparisonFailureEvent"), any(), any())
}

@Test
Expand All @@ -45,4 +60,8 @@ internal class ProxyToNewIntegrationTest {
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$.contactDetails.emailAddresses[0]").value("[email protected]"))
}

private fun whileTrue(action: () -> Boolean) {
while (action.invoke());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal class RequirementsByEventIdIntegrationTest {
requirement.terminationDate,
requirement.expectedStartDate,
requirement.expectedEndDate,
requirement.createdDatetime,
requirement.createdDatetime.toLocalDateTime(),
requirement.active,
requirement.subCategory?.let { KeyValue(it.code, it.description) },
requirement.mainCategory?.let { KeyValue(it.code, it.description) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class OffenderDetailSummary(
val dateOfBirth: LocalDate,
val firstName: String,
val gender: String,
val middleNames: List<String>,
val middleNames: List<String>? = null,
val offenderId: Long,
val offenderProfile: OffenderProfile,
val otherIds: OtherIds,
Expand All @@ -37,11 +37,11 @@ data class OffenderDetail(
val dateOfBirth: LocalDate,
val firstName: String,
val gender: String,
val middleNames: List<String>,
val middleNames: List<String>? = null,
val offenderId: Long,
val offenderProfile: OffenderProfile,
val offenderAliases: List<OffenderAlias>?,
val offenderManagers: List<OffenderManager>,
val offenderManagers: List<OffenderManager>? = null,
val otherIds: OtherIds,
val partitionArea: String,
val currentTier: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ data class Sentence(
val terminationDate: LocalDate? = null,
val terminationReason: String? = null,
val sentenceType: KeyValue,
val additionalSentences: List<AdditionalSentence>,
val additionalSentences: List<AdditionalSentence>? = null,
val failureToComplyLimit: Long?,
val cja2003Order: Boolean,
val legacyOrder: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package uk.gov.justice.digital.hmpps.api.model.conviction
import io.swagger.v3.oas.annotations.media.Schema
import uk.gov.justice.digital.hmpps.api.model.KeyValue
import java.time.LocalDate
import java.time.ZonedDateTime
import java.time.LocalDateTime

data class ConvictionRequirements(
val requirements: List<Requirement>
Expand All @@ -19,7 +19,7 @@ data class Requirement(
val terminationDate: LocalDate?,
val expectedStartDate: LocalDate?,
val expectedEndDate: LocalDate?,
val createdDatetime: ZonedDateTime,
val createdDatetime: LocalDateTime,
@Schema(description = "Is the requirement currently active")
val active: Boolean,
val requirementTypeSubCategory: KeyValue?,
Expand Down
Loading

0 comments on commit 0b1af66

Please sign in to comment.