Skip to content

Commit

Permalink
PI-1599 addeded .updated meessage processing (#2478)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevomcallister authored Nov 1, 2023
1 parent b04023f commit 894e761
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"eventType": "accommodation.cas3.booking.cancelled.updated",
"version": 1,
"description": "A cas3 booking has been cancelled",
"detailUrl": "http://localhost:{wiremock.port}/cas3-api/events/booking-cancelled/12345",
"occurredAt": "2022-12-04T10:42:43+00:00",
"additionalInformation": {
"applicationId": "68df9f6c-3fcb-4ec6-8fcf-96551cd9b080"
},
"personReference": {
"identifiers": [
{
"type": "CRN",
"value": "A000001"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"eventType": "accommodation.cas3.person.arrived.updated",
"version": 1,
"description": "A cas3 person has arrived",
"detailUrl": "http://localhost:{wiremock.port}/cas3-api/events/person-arrived/12345",
"occurredAt": "2022-12-04T10:42:43+00:00",
"additionalInformation": {
"applicationId": "68df9f6c-3fcb-4ec6-8fcf-96551cd9b080"
},
"personReference": {
"identifiers": [
{
"type": "CRN",
"value": "A000001"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"eventType": "accommodation.cas3.person.departed",
"eventType": "accommodation.cas3.person.departed.updated",
"version": 1,
"description": "A cas3 person departed",
"detailUrl": "http://localhost:{wiremock.port}/cas3-api/events/person-departed/12345",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": "364145f9-0af8-488e-9901-b4c46cd9ba37",
"timestamp": "2022-12-30T14:53:44",
"eventType": "accommodation.cas3.booking.cancelled.updated",
"eventDetails": {
"applicationId": "68df9f6c-3fcb-4ec6-8fcf-96551cd9b080",
"applicationUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/booking/68df9f6c-3fcb-4ec6-8fcf-96551cd9b080",
"personReference": {
"crn": "A000001",
"noms": "A0001AA"
},
"bookingId": "14c80733-4b6d-4f35-b724-66955aac320c",
"bookingUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/someURLtoTheBooking",
"cancellationReason": "Not appropriate",
"cancellationContext": "Suitability"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"id": "364145f9-0af8-488e-9901-b4c46cd9ba37",
"timestamp": "2022-12-30T14:53:44",
"eventType": "accommodation.cas3.person.arrived.updated",
"eventDetails": {
"applicationId": "68df9f6c-3fcb-4ec6-8fcf-96551cd9b080",
"applicationUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/booking/68df9f6c-3fcb-4ec6-8fcf-96551cd9b080",
"personReference": {
"crn": "A000001",
"noms": "A0001AA"
},
"bookingId": "14c80733-4b6d-4f35-b724-66955aac320e",
"bookingUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/someURLtoTheBooking",
"premises": {
"addressLine1": "12 Church Street",
"addressLine2": "",
"postcode": "BB1 1BB",
"town": "Bimbly Town",
"region": "Bibbinghammcshireshire"
},
"arrivedAt": "2022-11-30T12:00:00",
"notes": "person arrived"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "364145f9-0af8-488e-9901-b4c46cd9ba37",
"timestamp": "2022-12-30T14:53:44",
"eventType": "accommodation.cas3.person-departed ",
"eventType": "accommodation.cas3.person.departed.updated",
"eventDetails": {
"applicationId": "68df9f6c-3fcb-4ec6-8fcf-96551cd9b080",
"applicationUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/booking/68df9f6c-3fcb-4ec6-8fcf-96551cd9b080",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "364145f9-0af8-488e-9901-b4c46cd9ba37",
"timestamp": "2022-11-30T14:53:44",
"eventType": "accommodation.cas3.person-departed ",
"eventType": "accommodation.cas3.person.departed ",
"eventDetails": {
"applicationId": "68df9f6c-3fcb-4ec6-8fcf-96551cd9b080",
"applicationUrl": "https://approved-premises-dev.hmpps.service.justice.gov.uk/booking/68df9f6c-3fcb-4ec6-8fcf-96551cd9b080",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,32 @@
"status": 200,
"bodyFileName": "cas3-person-departed-update.json"
}
},
{
"request": {
"method": "GET",
"urlPath": "/cas3-api/events/booking-cancelled/12345"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"bodyFileName": "cas3-booking-cancelled-update.json"
}
},
{
"request": {
"method": "GET",
"urlPath": "/cas3-api/events/person-arrived/12345"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"bodyFileName": "cas3-person-arrived-update.json"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package uk.gov.justice.digital.hmpps

import com.fasterxml.jackson.databind.ObjectMapper
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock.aResponse
import com.github.tomakehurst.wiremock.client.WireMock.get
import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.junit.jupiter.api.MethodOrderer
import org.junit.jupiter.api.Order
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestMethodOrder
import org.mockito.Mockito
Expand All @@ -30,6 +34,7 @@ import uk.gov.justice.digital.hmpps.messaging.crn
import uk.gov.justice.digital.hmpps.resourceloader.ResourceLoader
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService
import uk.gov.justice.digital.hmpps.telemetry.notificationReceived
import java.time.ZonedDateTime

@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = RANDOM_PORT)
Expand Down Expand Up @@ -63,6 +68,7 @@ internal class CASIntegrationTest {
lateinit var objectMapper: ObjectMapper

@Test
@Order(1)
fun `referral submitted message is processed correctly`() {
val eventName = "referral-submitted"
val event = prepEvent(eventName, wireMockServer.port())
Expand All @@ -79,23 +85,34 @@ internal class CASIntegrationTest {
}

@Test
@Order(2)
fun `booking cancelled message is processed correctly`() {
val eventName = "booking-cancelled"
val event = prepEvent(eventName, wireMockServer.port())
val eventDetails = ResourceLoader.file<EventDetails<BookingCancelled>>("cas3-$eventName")
val eventDetailsCopy = eventDetails.copy(timestamp = ZonedDateTime.now().minusSeconds(3))
wireMockServer.stubFor(
get(urlEqualTo("/cas3-api/events/booking-cancelled/1234"))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(objectMapper.writeValueAsString(eventDetailsCopy))
)
)

// When it is received
channelManager.getChannel(queueName).publishAndWait(event)

// Then it is logged to telemetry
Mockito.verify(telemetryService).notificationReceived(event)

val eventDetails = ResourceLoader.file<EventDetails<BookingCancelled>>("cas3-$eventName")
val contact = contactRepository.getByExternalReference(eventDetails.eventDetails.urn)

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EACA"))
}

@Test
@Order(3)
fun `booking confirmed message is processed correctly`() {
val eventName = "booking-confirmed"
val event = prepEvent(eventName, wireMockServer.port())
Expand All @@ -113,6 +130,7 @@ internal class CASIntegrationTest {
}

@Test
@Order(4)
fun `booking provisionally made message is processed correctly`() {
val eventName = "booking-provisionally-made"
val event = prepEvent(eventName, wireMockServer.port())
Expand All @@ -130,17 +148,27 @@ internal class CASIntegrationTest {
}

@Test
@Order(5)
fun `person arrived message is processed correctly`() {
val eventName = "person-arrived"
val event = prepEvent(eventName, wireMockServer.port())
val eventDetails = ResourceLoader.file<EventDetails<PersonArrived>>("cas3-$eventName")
val eventDetailsCopy = eventDetails.copy(timestamp = ZonedDateTime.now().minusSeconds(3))
wireMockServer.stubFor(
get(urlEqualTo("/cas3-api/events/person-arrived/1234"))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(objectMapper.writeValueAsString(eventDetailsCopy))
)
)

// When it is received
channelManager.getChannel(queueName).publishAndWait(event)

// Then it is logged to telemetry
Mockito.verify(telemetryService).notificationReceived(event)

val eventDetails = ResourceLoader.file<EventDetails<PersonArrived>>("cas3-$eventName")
val contact = contactRepository.getByExternalReference(eventDetails.eventDetails.urn)

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EAAR"))
Expand All @@ -156,17 +184,27 @@ internal class CASIntegrationTest {
}

@Test
@Order(6)
fun `person departed message is processed correctly`() {
val eventName = "person-departed"
val event = prepEvent(eventName, wireMockServer.port())
val eventDetails = ResourceLoader.file<EventDetails<PersonDeparted>>("cas3-$eventName")
val eventDetailsCopy = eventDetails.copy(timestamp = ZonedDateTime.now().minusSeconds(3))
wireMockServer.stubFor(
get(urlEqualTo("/cas3-api/events/person-departed/1234"))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(objectMapper.writeValueAsString(eventDetailsCopy))
)
)

// When it is received
channelManager.getChannel(queueName).publishAndWait(event)

// Then it is logged to telemetry
Mockito.verify(telemetryService).notificationReceived(event)

val eventDetails = ResourceLoader.file<EventDetails<PersonDeparted>>("cas3-$eventName")
val contact = contactRepository.getByExternalReference(eventDetails.eventDetails.urn)

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EADP"))
Expand All @@ -176,19 +214,100 @@ internal class CASIntegrationTest {
}

@Test
@Order(7)
fun `person departed message update is processed correctly`() {
val eventName = "person-departed-update"
val event = prepEvent(eventName, wireMockServer.port())
val existingEventDetails = ResourceLoader.file<EventDetails<PersonDeparted>>("cas3-person-departed")
val existingContact = contactRepository.getByExternalReference(existingEventDetails.eventDetails.urn)
val existingNotes = existingContact!!.notes
val eventDetails = ResourceLoader.file<EventDetails<PersonDeparted>>("cas3-$eventName")
val eventDetailsCopy = eventDetails.copy(timestamp = ZonedDateTime.now())
wireMockServer.stubFor(
get(urlEqualTo("/cas3-api/events/person-departed/12345"))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(objectMapper.writeValueAsString(eventDetailsCopy))
)
)

// When it is received
channelManager.getChannel(queueName).publishAndWait(event)

// Then it is logged to telemetry
Mockito.verify(telemetryService).notificationReceived(event)
val eventDetails = ResourceLoader.file<EventDetails<PersonDeparted>>("cas3-$eventName")
val contact = contactRepository.getByExternalReference(eventDetails.eventDetails.urn)

MatcherAssert.assertThat(contact!!.type.code, Matchers.equalTo("EADP"))
MatcherAssert.assertThat(contact.notes, Matchers.equalTo(eventDetails.eventDetails.noteText))
MatcherAssert.assertThat(
contact!!.notes,
Matchers.equalTo(eventDetails.eventDetails.noteText + System.lineSeparator() + existingNotes)
)
}

@Test
@Order(8)
fun `person arrived updated message is processed correctly`() {
val eventName = "person-arrived-update"
val event = prepEvent(eventName, wireMockServer.port())
val existingEventDetails = ResourceLoader.file<EventDetails<PersonArrived>>("cas3-person-arrived-update")
val existingContact = contactRepository.getByExternalReference(existingEventDetails.eventDetails.urn)
val existingNotes = existingContact!!.notes
val eventDetails = ResourceLoader.file<EventDetails<PersonArrived>>("cas3-$eventName")
val eventDetailsCopy = eventDetails.copy(timestamp = ZonedDateTime.now())
wireMockServer.stubFor(
get(urlEqualTo("/cas3-api/events/person-arrived/12345"))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(objectMapper.writeValueAsString(eventDetailsCopy))
)
)

// When it is received
channelManager.getChannel(queueName).publishAndWait(event)

// Then it is logged to telemetry
Mockito.verify(telemetryService).notificationReceived(event)

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

MatcherAssert.assertThat(
contact!!.notes,
Matchers.equalTo(eventDetails.eventDetails.noteText + System.lineSeparator() + existingNotes)
)
}

@Test
@Order(9)
fun `booking cancelled updated message is processed correctly`() {
val eventName = "booking-cancelled-update"
val event = prepEvent(eventName, wireMockServer.port())
val existingEventDetails = ResourceLoader.file<EventDetails<BookingCancelled>>("cas3-booking-cancelled-update")
val existingContact = contactRepository.getByExternalReference(existingEventDetails.eventDetails.urn)
val existingNotes = existingContact!!.notes
val eventDetails = ResourceLoader.file<EventDetails<BookingCancelled>>("cas3-$eventName")
val eventDetailsCopy = eventDetails.copy(timestamp = ZonedDateTime.now())
wireMockServer.stubFor(
get(urlEqualTo("/cas3-api/events/booking-cancelled/12345"))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(objectMapper.writeValueAsString(eventDetailsCopy))
)
)

// When it is received
channelManager.getChannel(queueName).publishAndWait(event)

// Then it is logged to telemetry
Mockito.verify(telemetryService).notificationReceived(event)

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

MatcherAssert.assertThat(
contact!!.notes,
Matchers.equalTo(eventDetails.eventDetails.noteText + System.lineSeparator() + existingNotes)
)
}
}
Loading

0 comments on commit 894e761

Please sign in to comment.