Skip to content

Commit

Permalink
PI-2694 Add support for a CRN exception list
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl committed Dec 19, 2024
1 parent 5145797 commit c3a7fb1
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import java.util.concurrent.CompletionException
class AwsNotificationListener(
private val handler: NotificationHandler<*>,
private val objectMapper: ObjectMapper,
@Value("\${messaging.consumer.sensitive-event-types:[]}") private val sensitiveEventTypes: List<String>,
@Value("\${messaging.consumer.queue}") private val queueName: String
) {
@SentryTransaction(operation = "messaging")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AwsNotificationListenerTest {

@BeforeEach
fun setUp() {
listener = AwsNotificationListener(handler, objectMapper, listOf("my-sensitive-event-type"), "my-queue")
listener = AwsNotificationListener(handler, objectMapper, "my-queue")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.justice.digital.hmpps

import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.eq
Expand Down Expand Up @@ -39,21 +40,32 @@ internal class IntegrationTest {
@MockBean
lateinit var telemetryService: TelemetryService

@Test
fun `returns csv report`() {
@BeforeEach
fun setup() {
whenever(upwAppointmentRepository.getUnpaidWorkAppointments(any(), eq("N56"))).thenReturn(
listOf(
object : UnpaidWorkAppointment {
override val firstName = "Test"
override val mobileNumber = "07000000000"
override val mobileNumber = "07000000001"
override val appointmentDate = "01/01/2000"
override val crn = "A123456"
override val crn = "A000001"
override val eventNumbers = "1"
override val upwAppointmentIds = "123, 456"
},
object : UnpaidWorkAppointment {
override val firstName = "Test"
override val mobileNumber = "07000000002"
override val appointmentDate = "01/01/2000"
override val crn = "A000002"
override val eventNumbers = "1"
override val upwAppointmentIds = "789"
}
)
)
}

@Test
fun `returns csv report`() {
mockMvc
.perform(get("/upw-appointments.csv?providerCode=N56").withToken())
.andExpect(status().is2xxSuccessful)
Expand All @@ -62,7 +74,8 @@ internal class IntegrationTest {
content().string(
"""
firstName,mobileNumber,appointmentDate,crn,eventNumbers,upwAppointmentIds
Test,07000000000,01/01/2000,A123456,1,"123, 456"
Test,07000000001,01/01/2000,A000001,1,"123, 456"
Test,07000000002,01/01/2000,A000002,1,789
""".trimIndent()
)
Expand All @@ -71,30 +84,21 @@ internal class IntegrationTest {

@Test
fun `sends messages to govuk notify`() {
whenever(upwAppointmentRepository.getUnpaidWorkAppointments(any(), eq("N56"))).thenReturn(
listOf(
object : UnpaidWorkAppointment {
override val firstName = "Test"
override val mobileNumber = "07000000000"
override val appointmentDate = "01/01/2000"
override val crn = "A123456"
override val eventNumbers = "1"
override val upwAppointmentIds = "123, 456"
}
)
)

unpaidWorkAppointmentsService.sendUnpaidWorkAppointmentReminders("N56")

verify(notificationClient).sendSms(
"cd713c1b-1b27-45a0-b493-37a34666635a",
"07000000000",
"07000000001",
mapOf("FirstName" to "Test", "NextWorkSession" to "01/01/2000"),
"A123456:01/01/2000:123, 456"
"A000001:01/01/2000:123, 456"
)
verify(telemetryService).trackEvent(
"UnpaidWorkAppointmentReminderSent",
mapOf("crn" to "A000001", "upwAppointmentIds" to "123, 456")
)
verify(telemetryService).trackEvent(
"SentUnpaidWorkAppointmentReminder",
mapOf("crn" to "A123456", "upwAppointmentIds" to "123, 456")
"UnpaidWorkAppointmentReminderNotSent",
mapOf("crn" to "A000002", "upwAppointmentIds" to "789")
)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package uk.gov.justice.digital.hmpps

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.runApplication
import uk.gov.justice.digital.hmpps.properties.UpwAppointmentRemindersJobProperties

@SpringBootApplication
@EnableConfigurationProperties(UpwAppointmentRemindersJobProperties::class)
class App

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package uk.gov.justice.digital.hmpps.properties

import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties(prefix = "jobs.unpaid-work-appointment-reminders")
class UpwAppointmentRemindersJobProperties(
val enabled: Boolean = false,
val provider: String? = null,
val excludedCrns: List<String> = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package uk.gov.justice.digital.hmpps.service

import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.properties.UpwAppointmentRemindersJobProperties
import uk.gov.justice.digital.hmpps.repository.UpwAppointmentRepository
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService
import uk.gov.service.notify.NotificationClient
import java.time.LocalDate

@Service
class UnpaidWorkAppointmentsService(
private val properties: UpwAppointmentRemindersJobProperties,
private val upwAppointmentRepository: UpwAppointmentRepository,
private val notificationClient: NotificationClient,
private val telemetryService: TelemetryService,
Expand All @@ -17,14 +19,19 @@ class UnpaidWorkAppointmentsService(
fun sendUnpaidWorkAppointmentReminders(providerCode: String) {
upwAppointmentRepository.getUnpaidWorkAppointments(LocalDate.now().plusDays(2), providerCode)
.forEach {
notificationClient.sendSms(
templateId,
it.mobileNumber,
mapOf("FirstName" to it.firstName, "NextWorkSession" to it.appointmentDate),
"${it.crn}:${it.appointmentDate}:${it.upwAppointmentIds}"
)
telemetryService.trackEvent(
"SentUnpaidWorkAppointmentReminder",
if (it.crn !in properties.excludedCrns) {
notificationClient.sendSms(
templateId,
it.mobileNumber,
mapOf("FirstName" to it.firstName, "NextWorkSession" to it.appointmentDate),
"${it.crn}:${it.appointmentDate}:${it.upwAppointmentIds}"
)
telemetryService.trackEvent(
"UnpaidWorkAppointmentReminderSent",
mapOf("crn" to it.crn, "upwAppointmentIds" to it.upwAppointmentIds)
)
} else telemetryService.trackEvent(
"UnpaidWorkAppointmentReminderNotSent",
mapOf("crn" to it.crn, "upwAppointmentIds" to it.upwAppointmentIds)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ logging.level:
spring.config.activate.on-profile: integration-test
spring.datasource.url: jdbc:h2:mem:./test;MODE=Oracle;DEFAULT_NULL_ORDERING=HIGH

jobs.unpaid-work-appointment-reminders.excluded-crns: [ "A000002" ]

---
spring.config.activate.on-profile: oracle
spring:
Expand Down

0 comments on commit c3a7fb1

Please sign in to comment.