Skip to content

Commit 8b5e236

Browse files
Prevent publishing of excluded events (#222)
1 parent bc61475 commit 8b5e236

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/externalmovementsapi/domain/tap/authorisation/TemporaryAbsenceAuthorisation.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,7 @@ class TemporaryAbsenceAuthorisation(
206206
appliedActions = listOf()
207207
}
208208

209-
override fun domainEvents(): Set<DomainEvent<*>> {
210-
val events = appliedActions.mapNotNull { it.domainEvent(this) }.toSet()
211-
appliedActions = emptyList()
212-
return events
213-
}
209+
override fun domainEvents(): Set<DomainEvent<*>> = appliedActions.mapNotNull { it.domainEvent(this) }.toSet()
214210

215211
fun applyPrisonPerson(action: ChangePrisonPerson, person: (String) -> PersonSummary) {
216212
this.person = person(action.personIdentifier)

src/main/kotlin/uk/gov/justice/digital/hmpps/externalmovementsapi/domain/tap/movement/TemporaryAbsenceMovement.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,7 @@ class TemporaryAbsenceMovement(
144144
appliedActions = listOf()
145145
}
146146

147-
override fun domainEvents(): Set<DomainEvent<*>> {
148-
val events = appliedActions.mapNotNull { it.domainEvent(this) }.toSet()
149-
appliedActions = emptyList()
150-
return events
151-
}
147+
override fun domainEvents(): Set<DomainEvent<*>> = appliedActions.mapNotNull { it.domainEvent(this) }.toSet()
152148

153149
override fun initialEvent(): DomainEvent<*> = when (direction) {
154150
Direction.OUT -> TemporaryAbsenceStarted(person.identifier, id, occurrence?.id)

src/main/kotlin/uk/gov/justice/digital/hmpps/externalmovementsapi/domain/tap/occurrence/TemporaryAbsenceOccurrence.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,7 @@ class TemporaryAbsenceOccurrence(
238238
appliedActions = listOf()
239239
}
240240

241-
override fun domainEvents(): Set<DomainEvent<*>> {
242-
val events = appliedActions.mapNotNull { it.domainEvent(this) }.toSet()
243-
appliedActions = emptyList()
244-
return events
245-
}
241+
override fun domainEvents(): Set<DomainEvent<*>> = appliedActions.mapNotNull { it.domainEvent(this) }.toSet()
246242

247243
override fun excludeFromPublish(): Set<String> = setOf(
248244
TemporaryAbsenceStarted.EVENT_TYPE,

src/test/kotlin/uk/gov/justice/digital/hmpps/externalmovementsapi/integration/tap/occurrence/ChangeOccurrenceCommentsIntTest.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import uk.gov.justice.digital.hmpps.externalmovementsapi.context.ExternalMovemen
1414
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.IdGenerator.newUuid
1515
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.tap.authorisation.TemporaryAbsenceAuthorisation
1616
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.tap.occurrence.TemporaryAbsenceOccurrence
17+
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.tap.referencedata.AuthorisationStatus
18+
import uk.gov.justice.digital.hmpps.externalmovementsapi.domain.tap.referencedata.OccurrenceStatus
1719
import uk.gov.justice.digital.hmpps.externalmovementsapi.events.HmppsDomainEvent
1820
import uk.gov.justice.digital.hmpps.externalmovementsapi.events.TemporaryAbsenceAuthorisationCommentsChanged
1921
import uk.gov.justice.digital.hmpps.externalmovementsapi.events.TemporaryAbsenceCommentsChanged
@@ -94,6 +96,43 @@ class ChangeOccurrenceCommentsIntTest(
9496
)
9597
}
9698

99+
@Test
100+
fun `200 ok single tap occurrence comments updated - no publish`() {
101+
val auth = givenTemporaryAbsenceAuthorisation(temporaryAbsenceAuthorisation(status = AuthorisationStatus.Code.PENDING))
102+
val occurrence = givenTemporaryAbsenceOccurrence(temporaryAbsenceOccurrence(auth))
103+
assertThat(occurrence.status.code).isEqualTo(OccurrenceStatus.Code.PENDING.name)
104+
105+
val request = action()
106+
val res = applyOccurrenceComments(occurrence.id, request).successResponse<AuditHistory>().content.single()
107+
assertThat(res.domainEvents).containsExactly(TemporaryAbsenceCommentsChanged.EVENT_TYPE)
108+
assertThat(res.reason).isEqualTo(request.reason)
109+
assertThat(res.changes).containsExactly(AuditedAction.Change("comments", occurrence.comments, request.comments))
110+
111+
val saved = requireNotNull(findTemporaryAbsenceOccurrence(occurrence.id))
112+
assertThat(saved.comments).isEqualTo(request.comments)
113+
assertThat(saved.authorisation.comments).isEqualTo(request.comments)
114+
115+
verifyAudit(
116+
saved,
117+
RevisionType.MOD,
118+
setOf(
119+
TemporaryAbsenceOccurrence::class.simpleName!!,
120+
TemporaryAbsenceAuthorisation::class.simpleName!!,
121+
HmppsDomainEvent::class.simpleName!!,
122+
),
123+
ExternalMovementContext.get().copy(username = DEFAULT_USERNAME, reason = request.reason),
124+
)
125+
126+
// TODO: Check these are not published
127+
verifyEvents(
128+
saved,
129+
setOf(
130+
TemporaryAbsenceCommentsChanged(occurrence.authorisation.person.identifier, occurrence.id),
131+
TemporaryAbsenceAuthorisationCommentsChanged(auth.person.identifier, auth.id),
132+
),
133+
)
134+
}
135+
97136
@Test
98137
fun `200 ok repeat tap occurrence comments updated successfully`() {
99138
val auth = givenTemporaryAbsenceAuthorisation(temporaryAbsenceAuthorisation(repeat = true))

0 commit comments

Comments
 (0)