@@ -1566,6 +1566,139 @@ class HankeCompletionServiceITest(
15661566 }
15671567 }
15681568
1569+ @Nested
1570+ inner class SendUnmodifiedDraftReminderIfNecessary {
1571+ @Test
1572+ fun `does nothing when hanke has already been sent this reminder` () {
1573+ val hanke =
1574+ hankeFactory.builder().saveEntity(HankeStatus .DRAFT ) {
1575+ it.sentReminders + = HankeReminder .DRAFT_COMPLETION_15
1576+ }
1577+
1578+ hankeCompletionService.sendUnmodifiedDraftReminderIfNecessary(
1579+ hanke.id,
1580+ HankeReminder .DRAFT_COMPLETION_15 ,
1581+ )
1582+
1583+ assertThat(greenMail.receivedMessages).isEmpty()
1584+ val result = hankeRepository.getReferenceById(hanke.id)
1585+ assertThat(result.sentReminders).containsExactly(HankeReminder .DRAFT_COMPLETION_15 )
1586+ }
1587+
1588+ @Test
1589+ fun `marks reminder as sent and sends emails for DRAFT_COMPLETION_15` () {
1590+ val hanke =
1591+ hankeFactory.builder().withNoAreas().saveWithYhteystiedot {
1592+ omistaja(Kayttooikeustaso .KAIKKI_OIKEUDET )
1593+ rakennuttaja(Kayttooikeustaso .KAIKKIEN_MUOKKAUS )
1594+ toteuttaja(Kayttooikeustaso .KATSELUOIKEUS )
1595+ }
1596+ hanke.status = HankeStatus .DRAFT
1597+ hankeRepository.save(hanke)
1598+
1599+ hankeCompletionService.sendUnmodifiedDraftReminderIfNecessary(
1600+ hanke.id,
1601+ HankeReminder .DRAFT_COMPLETION_15 ,
1602+ )
1603+
1604+ val result = hankeRepository.getReferenceById(hanke.id)
1605+ assertThat(result.sentReminders).containsExactly(HankeReminder .DRAFT_COMPLETION_15 )
1606+
1607+ val emails = greenMail.receivedMessages
1608+ assertThat(emails).hasSize(3 )
1609+ val recipients = emails.map { it.allRecipients.single().toString() }
1610+ assertThat(recipients)
1611+ .containsExactlyInAnyOrder(
1612+ " pertti@perustaja.test" ,
1613+ " olivia.omistaja@mail.com" ,
1614+ " rane.rakennuttaja@mail.com" ,
1615+ )
1616+
1617+ val email = emails.first()
1618+ assertThat(email.subject)
1619+ .contains(
1620+ " Haitaton: Luonnos-tilainen hankkeesi ${hanke.hankeTunnus} on ollut pitkään muokkaamattomana"
1621+ )
1622+ assertThat(email.textBody())
1623+ .contains(
1624+ " Hankkeesi ${hanke.nimi} (${hanke.hankeTunnus} ) on luonnos-tilassa" ,
1625+ " 165 vuorokauteen" ,
1626+ " 180 vuorokautta" ,
1627+ )
1628+ }
1629+
1630+ @Test
1631+ fun `marks reminder as sent and sends emails for DRAFT_COMPLETION_5` () {
1632+ val hanke =
1633+ hankeFactory.builder().withNoAreas().saveWithYhteystiedot {
1634+ omistaja(Kayttooikeustaso .KAIKKI_OIKEUDET )
1635+ rakennuttaja(Kayttooikeustaso .KAIKKIEN_MUOKKAUS )
1636+ }
1637+ hanke.status = HankeStatus .DRAFT
1638+ hankeRepository.save(hanke)
1639+
1640+ hankeCompletionService.sendUnmodifiedDraftReminderIfNecessary(
1641+ hanke.id,
1642+ HankeReminder .DRAFT_COMPLETION_5 ,
1643+ )
1644+
1645+ val result = hankeRepository.getReferenceById(hanke.id)
1646+ assertThat(result.sentReminders).containsExactly(HankeReminder .DRAFT_COMPLETION_5 )
1647+
1648+ val emails = greenMail.receivedMessages
1649+ assertThat(emails).hasSize(3 )
1650+ val recipients = emails.map { it.allRecipients.single().toString() }
1651+ assertThat(recipients)
1652+ .containsExactlyInAnyOrder(
1653+ " pertti@perustaja.test" ,
1654+ " olivia.omistaja@mail.com" ,
1655+ " rane.rakennuttaja@mail.com" ,
1656+ )
1657+
1658+ val email = emails.first()
1659+ assertThat(email.subject)
1660+ .contains(
1661+ " Haitaton: Luonnos-tilainen hankkeesi ${hanke.hankeTunnus} on ollut pitkään muokkaamattomana"
1662+ )
1663+ assertThat(email.textBody())
1664+ .contains(
1665+ " Hankkeesi ${hanke.nimi} (${hanke.hankeTunnus} ) on luonnos-tilassa" ,
1666+ " 175 vuorokauteen" ,
1667+ " 180 vuorokautta" ,
1668+ )
1669+ }
1670+
1671+ @Test
1672+ fun `sends emails only to users with EDIT permissions` () {
1673+ val hanke =
1674+ hankeFactory.builder().withNoAreas().saveWithYhteystiedot {
1675+ omistaja(Kayttooikeustaso .KAIKKI_OIKEUDET )
1676+ rakennuttaja(Kayttooikeustaso .KAIKKIEN_MUOKKAUS )
1677+ toteuttaja(Kayttooikeustaso .KATSELUOIKEUS )
1678+ muuYhteystieto(Kayttooikeustaso .HANKEMUOKKAUS )
1679+ toteuttaja(Kayttooikeustaso .HAKEMUSASIOINTI )
1680+ }
1681+ hanke.status = HankeStatus .DRAFT
1682+ hankeRepository.save(hanke)
1683+
1684+ hankeCompletionService.sendUnmodifiedDraftReminderIfNecessary(
1685+ hanke.id,
1686+ HankeReminder .DRAFT_COMPLETION_15 ,
1687+ )
1688+
1689+ val emails = greenMail.receivedMessages
1690+ val recipients = emails.map { it.allRecipients.single().toString() }
1691+ assertThat(recipients).hasSize(4 )
1692+ assertThat(recipients)
1693+ .containsExactlyInAnyOrder(
1694+ " olivia.omistaja@mail.com" ,
1695+ " rane.rakennuttaja@mail.com" ,
1696+ " anssi.asianhoitaja@mail.com" ,
1697+ " pertti@perustaja.test" ,
1698+ )
1699+ }
1700+ }
1701+
15691702 companion object {
15701703
15711704 @JvmField
0 commit comments