Skip to content

Commit

Permalink
PI-1441 - add feature flag check
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj committed Oct 18, 2023
1 parent 5b3c429 commit 09a3b58
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.service

import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.converter.NotificationConverter
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent
import uk.gov.justice.digital.hmpps.message.Notification
import uk.gov.justice.digital.hmpps.messaging.NotificationHandler
Expand All @@ -11,13 +12,16 @@ import uk.gov.justice.digital.hmpps.telemetry.TelemetryService
class CvlHandler(
override val converter: NotificationConverter<HmppsDomainEvent>,
private val telemetryService: TelemetryService,
private val licenceActivatedHandler: LicenceActivatedHandler
private val licenceActivatedHandler: LicenceActivatedHandler,
private val featureFlags: FeatureFlags
) : NotificationHandler<HmppsDomainEvent> {

override fun handle(notification: Notification<HmppsDomainEvent>) {
val eventType = (notification.eventType ?: notification.message.eventType).let { DomainEventType.of(it) }
if (!featureFlags.enabled("cvl-licence-activated")) {
return
}
val results =
when (eventType) {
when (val eventType = (notification.eventType ?: notification.message.eventType).let { DomainEventType.of(it) }) {
is DomainEventType.LicenceActivated -> licenceActivatedHandler.licenceActivated(notification.message)
else -> listOf(
ActionResult.Ignored(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.service

import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
Expand All @@ -12,6 +13,7 @@ import org.mockito.kotlin.any
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import uk.gov.justice.digital.hmpps.converter.NotificationConverter
import uk.gov.justice.digital.hmpps.flags.FeatureFlags
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent
import uk.gov.justice.digital.hmpps.message.MessageAttributes
import uk.gov.justice.digital.hmpps.message.Notification
Expand All @@ -28,9 +30,17 @@ internal class CvlHandlerTest {
@Mock
internal lateinit var licenceActivatedHandler: LicenceActivatedHandler

@Mock
internal lateinit var featureFlags: FeatureFlags

@InjectMocks
internal lateinit var handler: CvlHandler

@BeforeEach
fun setUp() {
whenever(featureFlags.enabled("cvl-licence-activated")).thenReturn(true)
}

@Test
fun `unexpected event types are ignored`() {
val notification = Notification(
Expand Down

0 comments on commit 09a3b58

Please sign in to comment.