Skip to content

Commit

Permalink
Merge pull request #2849 from ministryofjustice/APS-1825-booking-made…
Browse files Browse the repository at this point in the history
…-domain-event-change

APS-1825. Added characteristics to booking made domain event and schema version 2.
  • Loading branch information
vbala-moj authored Jan 22, 2025
2 parents d1bdbd4 + 8bcc473 commit d7c4e49
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ enum class DomainEventType(
Cas1EventType.bookingMade.value,
"An Approved Premises booking has been made",
TimelineEventType.approvedPremisesBookingMade,
schemaVersions = listOf(
DEFAULT_DOMAIN_EVENT_SCHEMA_VERSION,
DomainEventSchemaVersion(2, "Added characteristics field"),
),
),
APPROVED_PREMISES_PERSON_ARRIVED(
DomainEventCas.CAS1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ class Cas1BookingDomainEventService(
} else {
null
},
schemaVersion = 2,
data = BookingMadeEnvelope(
id = domainEventId,
timestamp = bookingCreatedAt.toInstant(),
Expand Down Expand Up @@ -378,6 +379,7 @@ class Cas1BookingDomainEventService(
releaseType = releaseType,
sentenceType = sentenceType,
situation = situation,
characteristics = bookingInfo.characteristics,
),
),
metadata = mapOfNonNullValues(
Expand Down Expand Up @@ -485,6 +487,7 @@ class Cas1BookingDomainEventService(
val arrivalDate: LocalDate,
val departureDate: LocalDate,
val isSpaceBooking: Boolean,
val characteristics: List<Cas1SpaceCharacteristic>? = null,
)

private fun BookingEntity.toBookingInfo() = BookingInfo(
Expand All @@ -505,6 +508,7 @@ class Cas1BookingDomainEventService(
arrivalDate = canonicalArrivalDate,
departureDate = canonicalDepartureDate,
isSpaceBooking = true,
characteristics = criteria.toCas1SpaceCharacteristics(),
)

private data class CancellationInfo(
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/static/domain-events-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,10 @@ components:
type: string
situation:
type: string
characteristics:
type: array
items:
$ref: '#/components/schemas/Cas1SpaceCharacteristic'
required:
- applicationId
- applicationUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class Cas1BookingCas1DomainEventServiceTest {
.withCanonicalDepartureDate(LocalDate.of(2025, 12, 12))
.withPremises(premises)
.withCreatedAt(createdAt)
.withCriteria(CharacteristicEntityFactory().withModelScope("room").withPropertyName("hasEnSuite").produce())
.produce()

val placementRequest = PlacementRequestEntityFactory()
Expand Down Expand Up @@ -150,6 +151,7 @@ class Cas1BookingCas1DomainEventServiceTest {
assertThat(domainEvent.occurredAt).isEqualTo(createdAt.toInstant())
assertThat(domainEvent.data.eventType).isEqualTo(EventType.bookingMade)
assertThat(domainEvent.data.timestamp).isEqualTo(createdAt.toInstant())
assertThat(domainEvent.schemaVersion).isEqualTo(2)

val data = domainEvent.data.eventDetails
assertThat(data.createdAt).isEqualTo(createdAt.toInstant())
Expand All @@ -170,6 +172,7 @@ class Cas1BookingCas1DomainEventServiceTest {
assertThat(data.releaseType).isEqualTo(application.releaseType)
assertThat(data.sentenceType).isEqualTo(application.sentenceType)
assertThat(data.situation).isEqualTo(application.situation)
assertThat(data.characteristics).isEqualTo(listOf(Cas1SpaceCharacteristic.hasEnSuite))

assertThat(domainEvent.metadata).isEqualTo(mapOf(MetaDataName.CAS1_PLACEMENT_REQUEST_ID to placementRequest.id.toString()))
}
Expand Down Expand Up @@ -286,6 +289,7 @@ class Cas1BookingCas1DomainEventServiceTest {
assertThat(data.releaseType).isEqualTo(application.releaseType)
assertThat(data.sentenceType).isEqualTo(application.sentenceType)
assertThat(data.situation).isEqualTo(application.situation)
assertThat(data.characteristics).isNull()

assertThat(domainEvent.metadata).isEqualTo(mapOf(MetaDataName.CAS1_PLACEMENT_REQUEST_ID to placementRequest.id.toString()))
}
Expand Down

0 comments on commit d7c4e49

Please sign in to comment.