Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* PI-2047

* Formatting changes

* PI-2047

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 13e2bd2 commit c3a5050
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock.*
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.MethodOrderer
import org.junit.jupiter.api.Order
Expand All @@ -16,9 +17,7 @@ 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.boot.test.mock.mockito.MockBean
import org.springframework.test.web.servlet.MockMvc
import uk.gov.justice.digital.hmpps.data.generator.ProviderGenerator
import uk.gov.justice.digital.hmpps.datetime.DeliusDateFormatter
import uk.gov.justice.digital.hmpps.datetime.DeliusDateTimeFormatter
import uk.gov.justice.digital.hmpps.datetime.EuropeLondon
import uk.gov.justice.digital.hmpps.integrations.approvedpremesis.*
Expand Down Expand Up @@ -171,6 +170,7 @@ internal class CASIntegrationTest {
val contact = contactRepository.getByExternalReference(eventDetails.eventDetails.urn)

assertThat(contact!!.type.code, equalTo("EAAR"))
assertThat(contact.date, equalTo(eventDetails.eventDetails.arrivedAt.toLocalDate()))
assertThat(contact.teamId, equalTo(ProviderGenerator.DEFAULT_TEAM.id))
assertThat(contact.staffId, equalTo(ProviderGenerator.DEFAULT_STAFF.id))

Expand Down Expand Up @@ -207,8 +207,9 @@ internal class CASIntegrationTest {
Mockito.verify(telemetryService).notificationReceived(event)

val contact = contactRepository.getByExternalReference(eventDetails.eventDetails.urn)

assertThat(contact!!.type.code, equalTo("EADP"))
assertThat(contact.date, equalTo(eventDetails.eventDetails.departedAt.toLocalDate()))

val person = personRepository.findByCrn(event.message.crn())
val address = addressRepository.findAll().filter { it.personId == person?.id }[0]
assertThat(address!!.status.code, equalTo("P"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ data class EventDetails<out T : Cas3Event>(
val timestamp: ZonedDateTime,
val eventType: String,
val eventDetails: T
)
) {
fun occurredAt() = if (eventDetails is OccurredAt) eventDetails.occurredAt else timestamp
}

data class ApplicationSubmitted(
val applicationId: String
Expand Down Expand Up @@ -90,7 +92,7 @@ data class PersonArrived(
val notes: String,
val premises: Address,
override val recordedBy: By?
) : Cas3Event, Recordable {
) : Cas3Event, Recordable, OccurredAt {
override val urn = "urn:hmpps:cas3:person-arrived:$bookingId"
override val noteText =
listOfNotNull(
Expand All @@ -99,6 +101,7 @@ data class PersonArrived(
notes
).joinToString(System.lineSeparator())
override val contactTypeCode = ContactType.PERSON_ARRIVED
override val occurredAt = arrivedAt
}

data class PersonDeparted(
Expand All @@ -111,7 +114,7 @@ data class PersonDeparted(
val reason: String,
val reasonDetail: String?,
override val recordedBy: By?
) : Cas3Event, Recordable {
) : Cas3Event, Recordable, OccurredAt {
override val urn = "urn:hmpps:cas3:person-departed:$bookingId"
override val noteText = listOfNotNull(
"Departure date: ${DeliusDateFormatter.format(departedAt)}",
Expand All @@ -120,6 +123,7 @@ data class PersonDeparted(
notes
).joinToString(System.lineSeparator())
override val contactTypeCode = ContactType.PERSON_DEPARTED
override val occurredAt = departedAt
}

data class Address(
Expand Down Expand Up @@ -150,15 +154,15 @@ data class AddressLines(
val district: String?
)

data class Category(
val description: String
)

data class By(
val staffCode: String,
val probationRegionCode: String
)

interface Recordable {
val recordedBy: By?
}

interface OccurredAt {
val occurredAt: ZonedDateTime
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ContactService(
} else {
contactRepository.save(
newContact(
event.timestamp,
event.occurredAt(),
personId,
event.eventDetails.contactTypeCode,
event.eventDetails.urn,
Expand Down

0 comments on commit c3a5050

Please sign in to comment.