Skip to content

Commit

Permalink
Send booking email to placement request creator
Browse files Browse the repository at this point in the history
If the user who created a request for placement on the application did not originally created the application, they should also receive a booking made email
  • Loading branch information
davidatkinsuk committed Sep 9, 2024
1 parent af1c04a commit e8c8031
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ class Cas1BookingEmailService(
booking,
)

if (applicationSubmittedByUser.email != null) {
emailNotifier.sendEmail(
recipientEmailAddress = applicationSubmittedByUser.email!!,
templateId = notifyConfig.templates.bookingMade,
personalisation = emailPersonalisation,
application = application,
)
}
val applicants = setOfNotNull(
applicationSubmittedByUser.email,
booking.placementRequest?.placementApplication?.createdByUser?.email,
)

emailNotifier.sendEmails(
recipientEmailAddresses = applicants,
templateId = notifyConfig.templates.bookingMade,
personalisation = emailPersonalisation,
application = application,
)

if (booking.premises.emailAddress != null) {
emailNotifier.sendEmail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class PlacementApplicationEntityFactory : Factory<PlacementApplicationEntity> {

fun withDefaults() = apply {
this.createdByUser = { UserEntityFactory().withDefaultProbationRegion().produce() }
this.application = { ApprovedPremisesApplicationEntityFactory().withDefaults().produce() }
}

fun withId(id: UUID) = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ApprovedPremises
import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ApprovedPremisesEntityFactory
import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.BookingEntityFactory
import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.Cas1ApplicationUserDetailsEntityFactory
import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.PlacementApplicationEntityFactory
import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.PlacementRequestEntityFactory
import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.ProbationRegionEntityFactory
import uk.gov.justice.digital.hmpps.approvedpremisesapi.factory.UserEntityFactory
import uk.gov.justice.digital.hmpps.approvedpremisesapi.jpa.entity.ApAreaEntity
Expand All @@ -23,6 +25,7 @@ import uk.gov.justice.digital.hmpps.approvedpremisesapi.unit.service.cas1.Cas1Bo
import uk.gov.justice.digital.hmpps.approvedpremisesapi.unit.service.cas1.Cas1BookingEmailServiceTest.TestConstants.AP_AREA_EMAIL
import uk.gov.justice.digital.hmpps.approvedpremisesapi.unit.service.cas1.Cas1BookingEmailServiceTest.TestConstants.CASE_MANAGER_EMAIL
import uk.gov.justice.digital.hmpps.approvedpremisesapi.unit.service.cas1.Cas1BookingEmailServiceTest.TestConstants.CRN
import uk.gov.justice.digital.hmpps.approvedpremisesapi.unit.service.cas1.Cas1BookingEmailServiceTest.TestConstants.PLACEMENT_APPLICATION_CREATOR_EMAIL
import uk.gov.justice.digital.hmpps.approvedpremisesapi.unit.service.cas1.Cas1BookingEmailServiceTest.TestConstants.PREMISES_EMAIL
import uk.gov.justice.digital.hmpps.approvedpremisesapi.unit.service.cas1.Cas1BookingEmailServiceTest.TestConstants.PREMISES_NAME
import uk.gov.justice.digital.hmpps.approvedpremisesapi.unit.service.cas1.Cas1BookingEmailServiceTest.TestConstants.REGION_NAME
Expand All @@ -36,6 +39,7 @@ class Cas1BookingEmailServiceTest {
private object TestConstants {
const val AP_AREA_EMAIL = "[email protected]"
const val APPLICANT_EMAIL = "[email protected]"
const val PLACEMENT_APPLICATION_CREATOR_EMAIL = "[email protected]"
const val CRN = "CRN123"
const val PREMISES_EMAIL = "[email protected]"
const val PREMISES_NAME = "The Premises Name"
Expand Down Expand Up @@ -111,7 +115,7 @@ class Cas1BookingEmailServiceTest {

@SuppressWarnings("CyclomaticComplexMethod")
@Test
fun `bookingMade sends email to applicant and premises email addresses when defined, when length of stay whole number of weeks`() {
fun `bookingMade sends email to applicant, premises email addresses when defined, when length of stay whole number of weeks`() {
val applicant = UserEntityFactory()
.withUnitTestControlProbationRegion()
.withEmail(APPLICANT_EMAIL)
Expand Down Expand Up @@ -191,6 +195,73 @@ class Cas1BookingEmailServiceTest {
application,
)
}

@SuppressWarnings("CyclomaticComplexMethod")
@Test
fun `bookingMade sends email to applicant, placement application creator and premises email addresses for request for placements`() {
val applicant = UserEntityFactory()
.withUnitTestControlProbationRegion()
.withEmail(APPLICANT_EMAIL)
.produce()

val (application, booking) = createApplicationAndBooking(
applicant,
premises,
arrivalDate = LocalDate.of(2023, 2, 1),
departureDate = LocalDate.of(2023, 2, 14),
)

booking.placementRequest = PlacementRequestEntityFactory()
.withDefaults()
.withPlacementApplication(
PlacementApplicationEntityFactory()
.withDefaults()
.withCreatedByUser(
UserEntityFactory()
.withUnitTestControlProbationRegion()
.withEmail(PLACEMENT_APPLICATION_CREATOR_EMAIL)
.produce(),
)
.produce(),
)
.produce()

service.bookingMade(application, booking)

mockEmailNotificationService.assertEmailRequestCount(3)

val personalisation = mapOf(
"apName" to PREMISES_NAME,
"applicationUrl" to "http://frontend/applications/${application.id}",
"bookingUrl" to "http://frontend/premises/${premises.id}/bookings/${booking.id}",
"crn" to CRN,
"startDate" to "2023-02-01",
"endDate" to "2023-02-14",
"lengthStay" to 2,
"lengthStayUnit" to "weeks",
)

mockEmailNotificationService.assertEmailRequested(
APPLICANT_EMAIL,
notifyConfig.templates.bookingMade,
personalisation,
application,
)

mockEmailNotificationService.assertEmailRequested(
PLACEMENT_APPLICATION_CREATOR_EMAIL,
notifyConfig.templates.bookingMade,
personalisation,
application,
)

mockEmailNotificationService.assertEmailRequested(
PREMISES_EMAIL,
notifyConfig.templates.bookingMadePremises,
personalisation,
application,
)
}
}

@Nested
Expand Down

0 comments on commit e8c8031

Please sign in to comment.