diff --git a/services/mailservice.yaml b/services/mailservice.yaml index f074e5622..a0dc976d3 100644 --- a/services/mailservice.yaml +++ b/services/mailservice.yaml @@ -71,6 +71,8 @@ components: example: "max@mustermann.de" language: $ref: '#/components/schemas/LanguageCode' + dialect: + $ref: '#/components/schemas/Dialect' templateData: type: array items: @@ -116,3 +118,10 @@ components: so, sq, sr, ss, st, su, sv, sw, ta, te, tg, th, ti, tk, tl, tn, to, tr, ts, tt, tw, ty, ug, uk, ur, uz, ve, vi, vo, wa, wo, xh, yi, yo, za, zh, zu ] + + Dialect: + type: string + default: formal + enum: [ + formal, informal + ] diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java index 4f296d43a..592254001 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java @@ -269,6 +269,7 @@ public void sendReassignRequestNotification(String rcGroupId, TenantData tenantD .receiverEmailAddress(user.getEmail()) .receiverLanguageCode(user.getLanguageCode()) .receiverUsername(user.getUsername()) + .receiverDialect(user.getDialect()) .tenantTemplateSupplier(tenantTemplateSupplier) .applicationBaseUrl(applicationBaseUrl) .multiTenancyEnabled(multiTenancyEnabled) diff --git a/src/main/java/de/caritas/cob/userservice/api/model/Consultant.java b/src/main/java/de/caritas/cob/userservice/api/model/Consultant.java index baa0107c1..c1190b1ff 100644 --- a/src/main/java/de/caritas/cob/userservice/api/model/Consultant.java +++ b/src/main/java/de/caritas/cob/userservice/api/model/Consultant.java @@ -20,6 +20,7 @@ import javax.persistence.Lob; import javax.persistence.OneToMany; import javax.persistence.Table; +import javax.persistence.Transient; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Builder; @@ -42,6 +43,7 @@ import org.hibernate.search.annotations.TokenFilterDef; import org.hibernate.search.annotations.TokenizerDef; import org.springframework.lang.Nullable; +import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect; /** Represents a consultant */ @Entity @@ -252,6 +254,12 @@ public boolean isInAgency(long agencyId) { .contains(agencyId); } + @JsonIgnore + @Transient + public Dialect getDialect() { + return isLanguageFormal() ? Dialect.FORMAL: Dialect.INFORMAL; + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/src/main/java/de/caritas/cob/userservice/api/model/User.java b/src/main/java/de/caritas/cob/userservice/api/model/User.java index f3c9453fb..f3377ccb0 100644 --- a/src/main/java/de/caritas/cob/userservice/api/model/User.java +++ b/src/main/java/de/caritas/cob/userservice/api/model/User.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.model; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.neovisionaries.i18n.LanguageCode; import java.time.LocalDateTime; import java.util.Objects; @@ -13,6 +14,7 @@ import javax.persistence.Lob; import javax.persistence.OneToMany; import javax.persistence.Table; +import javax.persistence.Transient; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Getter; @@ -27,6 +29,7 @@ import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect; /** Represents a user */ @Entity @@ -150,4 +153,10 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(userId); } + + @JsonIgnore + @Transient + public Dialect getDialect() { + return isLanguageFormal() ? Dialect.FORMAL: Dialect.INFORMAL; + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplier.java index 22f55593d..255b92d6d 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplier.java @@ -110,6 +110,9 @@ private MailDTO mailOf(Consultant consultant, String postCode) { .template(TEMPLATE_NEW_DIRECT_ENQUIRY_NOTIFICATION) .email(consultant.getEmail()) .language(fromValue(consultant.getLanguageCode().toString())) - .templateData(templateAttributes); + .templateData(templateAttributes) + .dialect(consultant.getDialect()); } + + } diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplier.java index 97d9064d7..83ccf8f1e 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplier.java @@ -129,6 +129,7 @@ private MailDTO mailOf(Consultant consultant, String postCode, String agency) { .template(TEMPLATE_NEW_ENQUIRY_NOTIFICATION) .email(consultant.getEmail()) .language(language) + .dialect(consultant.getDialect()) .templateData(templateAttributes); } } diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplier.java index e3bf929f5..333f94e74 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplier.java @@ -56,8 +56,7 @@ public List generateEmails() throws RocketChatGetGroupMembersException return emptyList(); } - private List buildFeedbackMessageMailsForExistingSession() - throws RocketChatGetGroupMembersException { + private List buildFeedbackMessageMailsForExistingSession() { if (nonNull(session.getConsultant())) { return buildFeedbackMessageMailsForExistingConsultant(); } @@ -69,8 +68,7 @@ private List buildFeedbackMessageMailsForExistingSession() return emptyList(); } - private List buildFeedbackMessageMailsForExistingConsultant() - throws RocketChatGetGroupMembersException { + private List buildFeedbackMessageMailsForExistingConsultant() { Optional sendingConsultantOptional = consultantService.getConsultant(userId); if (sendingConsultantOptional.isPresent()) { Consultant sendingConsultant = sendingConsultantOptional.get(); @@ -81,15 +79,14 @@ private List buildFeedbackMessageMailsForExistingConsultant() return emptyList(); } - private List buildMailsDependingOnAuthor(Consultant sendingConsultant) - throws RocketChatGetGroupMembersException { + private List buildMailsDependingOnAuthor(Consultant sendingConsultant) { var receivingConsultant = session.getConsultant(); if (areUsersEqual(userId, receivingConsultant)) { return buildNotificationMailsForAllOtherConsultants(sendingConsultant); } - if (receivingConsultant.getNotifyNewFeedbackMessageFromAdviceSeeker() - && didAnotherConsultantWrite() + if (Boolean.TRUE.equals(receivingConsultant.getNotifyNewFeedbackMessageFromAdviceSeeker() + && didAnotherConsultantWrite()) && isLoggedOut(receivingConsultant)) { var mail = buildMailForAssignedConsultant(sendingConsultant, receivingConsultant); @@ -190,6 +187,7 @@ private MailDTO mailOf(Consultant recipient, String nameSender, String nameUser) .template(TEMPLATE_NEW_FEEDBACK_MESSAGE_NOTIFICATION) .email(recipient.getEmail()) .language(language) + .dialect(recipient.getDialect()) .templateData( asList( new TemplateDataDTO().key("name_sender").value(nameSender), diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplier.java index 75faa49cd..298eb94e5 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplier.java @@ -28,6 +28,7 @@ import de.caritas.cob.userservice.api.service.consultingtype.ReleaseToggle; import de.caritas.cob.userservice.api.service.consultingtype.ReleaseToggleService; import de.caritas.cob.userservice.consultingtypeservice.generated.web.model.NotificationsDTO; +import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect; import de.caritas.cob.userservice.mailservice.generated.web.model.MailDTO; import de.caritas.cob.userservice.mailservice.generated.web.model.TemplateDataDTO; import java.util.ArrayList; @@ -188,6 +189,7 @@ private MailDTO buildMailDtoForNewMessageNotificationConsultant( return new MailDTO() .template(TEMPLATE_NEW_MESSAGE_NOTIFICATION_CONSULTANT) .email(recipient.getEmail()) + .dialect(recipient.getDialect()) .language(languageOf(recipient.getLanguageCode())) .templateData(templateAttributes); } @@ -232,7 +234,7 @@ private List buildMailForAskerList() { asker.getEmail(), asker.getLanguageCode(), usernameTranscoder.decodeUsername(consultantUsername), - usernameTranscoder.decodeUsername(asker.getUsername())); + usernameTranscoder.decodeUsername(asker.getUsername()), asker.getDialect()); return singletonList(mailDTO); } @@ -262,7 +264,8 @@ private boolean isAdviceSeekerWithEmail() { } private MailDTO buildMailDtoForNewMessageNotificationAsker( - String email, LanguageCode languageCode, String consultantName, String askerName) { + String email, LanguageCode languageCode, String consultantName, String askerName, + Dialect askerDialect) { var templateAttributes = new ArrayList(); templateAttributes.add(new TemplateDataDTO().key("consultantName").value(consultantName)); templateAttributes.add(new TemplateDataDTO().key("askerName").value(askerName)); @@ -275,6 +278,7 @@ private MailDTO buildMailDtoForNewMessageNotificationAsker( return new MailDTO() .template(TEMPLATE_NEW_MESSAGE_NOTIFICATION_ASKER) + .dialect(askerDialect) .email(email) .language(languageOf(languageCode)) .templateData(templateAttributes); diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentConfirmationEmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentConfirmationEmailSupplier.java index 0c5439802..19f31fa5e 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentConfirmationEmailSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentConfirmationEmailSupplier.java @@ -51,6 +51,7 @@ private MailDTO buildMailDtoForReassignRequestNotification() { .template(TEMPLATE_REASSIGN_CONFIRMATION_NOTIFICATION) .email(receiverConsultant.getEmail()) .language(languageOf(receiverConsultant.getLanguageCode())) + .dialect(receiverConsultant.getDialect()) .templateData(templateAttributes); } diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentRequestEmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentRequestEmailSupplier.java index 37240277f..00b9208d4 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentRequestEmailSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentRequestEmailSupplier.java @@ -9,6 +9,7 @@ import java.util.List; import javax.transaction.Transactional; import lombok.Builder; +import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect; @Builder public class ReassignmentRequestEmailSupplier implements EmailSupplier { @@ -16,6 +17,8 @@ public class ReassignmentRequestEmailSupplier implements EmailSupplier { private final String receiverEmailAddress; private final LanguageCode receiverLanguageCode; private final String receiverUsername; + + private final Dialect receiverDialect; private final String applicationBaseUrl; private final TenantTemplateSupplier tenantTemplateSupplier; private final boolean multiTenancyEnabled; @@ -40,6 +43,7 @@ private MailDTO buildMailDtoForReassignRequestNotification() { return new MailDTO() .template(TEMPLATE_REASSIGN_REQUEST_NOTIFICATION) .email(receiverEmailAddress) + .dialect(receiverDialect) .language(languageOf(receiverLanguageCode)) .templateData(templateAttributes); } diff --git a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java index a709e8585..40bbbe9f3 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewDirectEnquiryEmailSupplierTest.java @@ -20,6 +20,7 @@ import de.caritas.cob.userservice.api.port.out.ConsultantAgencyRepository; import de.caritas.cob.userservice.api.service.consultingtype.ReleaseToggle; import de.caritas.cob.userservice.api.service.consultingtype.ReleaseToggleService; +import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect; import de.caritas.cob.userservice.mailservice.generated.web.model.LanguageCode; import de.caritas.cob.userservice.mailservice.generated.web.model.MailDTO; import java.util.List; @@ -91,6 +92,7 @@ public void generateEmails_Should_ReturnExpectedMailDTO_When_PresentConsultantHa assertThat(generatedMail.getTemplate(), is(TEMPLATE_NEW_DIRECT_ENQUIRY_NOTIFICATION)); assertThat(generatedMail.getEmail(), is("email@email.com")); assertThat(generatedMail.getLanguage(), is(LanguageCode.DE)); + assertThat(generatedMail.getDialect(), is(MAIN_CONSULTANT.getDialect())); var templateData = generatedMail.getTemplateData(); assertThat(templateData, hasSize(3)); @@ -143,11 +145,12 @@ public void generateEmails_Should_ReturnExpectedMailDTO_When_PresentConsultantHa assertThat(generatedMail.getTemplate(), is(TEMPLATE_NEW_DIRECT_ENQUIRY_NOTIFICATION)); assertThat(generatedMail.getEmail(), is("email@email.com")); assertThat(generatedMail.getLanguage(), is(LanguageCode.DE)); - + assertThat(generatedMail.getDialect(), is(MAIN_CONSULTANT.getDialect())); var templateData = generatedMail.getTemplateData(); assertThat(templateData, hasSize(3)); assertThat(templateData.get(0).getKey(), is("name")); assertThat(templateData.get(0).getValue(), is("first name last name")); + assertThat(templateData.get(1).getKey(), is("plz")); assertThat(templateData.get(1).getValue(), is(POSTCODE)); assertThat(templateData.get(2).getKey(), is("url")); diff --git a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplierTest.java b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplierTest.java index 81babb3d6..ba3b0bd45 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplierTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplierTest.java @@ -6,10 +6,6 @@ import static de.caritas.cob.userservice.api.testHelper.TestConstants.GROUP_MEMBER_DTO_LIST; import static de.caritas.cob.userservice.api.testHelper.TestConstants.GROUP_MEMBER_USER_1; import static de.caritas.cob.userservice.api.testHelper.TestConstants.USER; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.atLeastOnce; @@ -18,6 +14,7 @@ import static org.mockito.Mockito.when; import static org.powermock.reflect.Whitebox.setInternalState; import static org.springframework.test.util.ReflectionTestUtils.setField; +import static org.assertj.core.api.Assertions.assertThat; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -88,7 +85,7 @@ public void generateEmails_Should_ReturnEmptyListAndLogError_When_SessionIsNull( keycloakService) .generateEmails(); - assertThat(generatedMails, hasSize(0)); + assertThat(generatedMails).isEmpty(); verify(logger).error(anyString(), anyString()); } @@ -98,7 +95,7 @@ public void generateEmails_Should_ReturnEmptyLisAndLogError_When_NoValidConsulta List generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(0)); + assertThat(generatedMails).isEmpty(); verify(logger).error(anyString(), anyString()); } @@ -110,7 +107,7 @@ public void generateEmails_Should_ReturnEmptyLisAndLogError_When_NoValidConsulta List generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(0)); + assertThat(generatedMails).isEmpty(); verify(logger).error(anyString(), anyString()); } @@ -124,7 +121,7 @@ public void generateEmails_Should_ReturnEmptyLisAndLogError_When_NoValidConsulta List generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(0)); + assertThat(generatedMails).isEmpty(); verify(logger).error(anyString(), anyString()); } @@ -139,7 +136,7 @@ public void generateEmails_Should_ReturnEmptyLisAndLogError_When_NoValidConsulta List generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(0)); + assertThat(generatedMails).isEmpty(); verify(logger, atLeastOnce()).error(anyString(), anyString(), anyString()); } @@ -157,23 +154,23 @@ public void generateEmails_Should_ReturnEmptyLisAndLogError_When_NoValidConsulta List generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(4)); + assertThat(generatedMails).hasSize(4); MailDTO generatedMail = generatedMails.get(0); - assertThat(generatedMail.getTemplate(), is(TEMPLATE_NEW_FEEDBACK_MESSAGE_NOTIFICATION)); - assertThat(generatedMail.getEmail(), is("email@email.com")); + assertThat(generatedMail.getTemplate()).isEqualTo(TEMPLATE_NEW_FEEDBACK_MESSAGE_NOTIFICATION); + assertThat(generatedMail.getEmail()).isEqualTo("email@email.com"); assertThat( - generatedMail.getLanguage(), - is(de.caritas.cob.userservice.mailservice.generated.web.model.LanguageCode.DE)); + generatedMail.getLanguage()).isEqualTo( + de.caritas.cob.userservice.mailservice.generated.web.model.LanguageCode.DE); List templateData = generatedMail.getTemplateData(); - assertThat(templateData, hasSize(4)); - assertThat(templateData.get(0).getKey(), is("name_sender")); - assertThat(templateData.get(0).getValue(), is("vorname nachname")); - assertThat(templateData.get(1).getKey(), is("name_recipient")); - assertThat(templateData.get(1).getValue(), is("first name last name")); - assertThat(templateData.get(2).getKey(), is("name_user")); - assertThat(templateData.get(2).getValue(), is("username")); - assertThat(templateData.get(3).getKey(), is("url")); - assertThat(templateData.get(3).getValue(), is("applicationBaseUrl")); + assertThat(templateData).hasSize(4); + assertThat(templateData.get(0).getKey()).isEqualTo("name_sender"); + assertThat(templateData.get(0).getValue()).isEqualTo(("vorname nachname")); + assertThat(templateData.get(1).getKey()).isEqualTo("name_recipient"); + assertThat(templateData.get(1).getValue()).isEqualTo("first name last name"); + assertThat(templateData.get(2).getKey()).isEqualTo("name_user"); + assertThat(templateData.get(2).getValue()).isEqualTo(("username")); + assertThat(templateData.get(3).getKey()).isEqualTo("url"); + assertThat(templateData.get(3).getValue()).isEqualTo("applicationBaseUrl"); } @Test @@ -197,7 +194,7 @@ public void generateEmails_Should_ReturnExpectedMail_When_ConsultantsFeedbackTog var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(1)); + assertThat(generatedMails).hasSize(1); } @Test @@ -219,7 +216,7 @@ public void generateEmails_Should_ReturnNoMail_When_ConsultantsFeedbackToggleIsO var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(0)); + assertThat(generatedMails).isEmpty(); } @Test @@ -244,7 +241,7 @@ public void generateEmails_Should_ReturnExpectedMail_When_ConsultantIsOffline() var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(1)); + assertThat(generatedMails).hasSize(1); } @Test @@ -267,7 +264,7 @@ public void generateEmails_Should_ReturnNoMail_When_ConsultantIsOnline() var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, empty()); + assertThat(generatedMails).isEmpty(); } @Test @@ -279,7 +276,7 @@ public void generateEmails_Should_ReturnEmptyList_When_SessionConsultantIsAbsent List generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(0)); + assertThat(generatedMails).isEmpty(); } @Test @@ -292,23 +289,23 @@ public void generateEmails_Should_ReturnExpectedMail_When_AnotherConsultantWrote List generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(1)); + assertThat(generatedMails).hasSize(1); MailDTO generatedMail = generatedMails.get(0); - assertThat(generatedMail.getTemplate(), is(TEMPLATE_NEW_FEEDBACK_MESSAGE_NOTIFICATION)); - assertThat(generatedMail.getEmail(), is("email@email.com")); + assertThat(generatedMail.getTemplate()).isEqualTo(TEMPLATE_NEW_FEEDBACK_MESSAGE_NOTIFICATION); + assertThat(generatedMail.getEmail()).isEqualTo("email@email.com"); assertThat( - generatedMail.getLanguage(), - is(de.caritas.cob.userservice.mailservice.generated.web.model.LanguageCode.DE)); + generatedMail.getLanguage()).isEqualTo( + de.caritas.cob.userservice.mailservice.generated.web.model.LanguageCode.DE); List templateData = generatedMail.getTemplateData(); - assertThat(templateData, hasSize(4)); - assertThat(templateData.get(0).getKey(), is("name_sender")); - assertThat(templateData.get(0).getValue(), is("first name last name")); - assertThat(templateData.get(1).getKey(), is("name_recipient")); - assertThat(templateData.get(1).getValue(), is("first name last name")); - assertThat(templateData.get(2).getKey(), is("name_user")); - assertThat(templateData.get(2).getValue(), is("username")); - assertThat(templateData.get(3).getKey(), is("url")); - assertThat(templateData.get(3).getValue(), is("applicationBaseUrl")); + assertThat(templateData).hasSize(4); + assertThat(templateData.get(0).getKey()).isEqualTo("name_sender"); + assertThat(templateData.get(0).getValue()).isEqualTo("first name last name"); + assertThat(templateData.get(1).getKey()).isEqualTo("name_recipient"); + assertThat(templateData.get(1).getValue()).isEqualTo(("first name last name")); + assertThat(templateData.get(2).getKey()).isEqualTo(("name_user")); + assertThat(templateData.get(2).getValue()).isEqualTo(("username")); + assertThat(templateData.get(3).getKey()).isEqualTo(("url")); + assertThat(templateData.get(3).getValue()).isEqualTo(("applicationBaseUrl")); } @Test @@ -322,7 +319,8 @@ public void generateEmails_Should_ReturnExpectedMail_When_AnotherConsultantWrote var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(1)); + assertThat(generatedMails).hasSize(1); + assertThat(generatedMails.get(0).getDialect()).isEqualTo(CONSULTANT_2.getDialect()); } @Test @@ -335,7 +333,7 @@ public void generateEmails_Should_ReturnNoMail_When_AnotherConsultantWroteAndFee var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(0)); + assertThat(generatedMails).isEmpty(); } @Test @@ -350,7 +348,7 @@ public void generateEmails_Should_ReturnNoMail_When_AnotherConsultantWroteAndFee var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(1)); + assertThat(generatedMails).hasSize(1); } @Test @@ -363,7 +361,7 @@ public void generateEmails_Should_ReturnNoMail_When_AnotherConsultantWroteAndCon var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, empty()); + assertThat(generatedMails).isEmpty(); } @Test @@ -381,7 +379,7 @@ public void generateEmails_Should_FilterNonMainConsultantsNorSessionAssignees() var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(0)); + assertThat(generatedMails).isEmpty(); } @Test @@ -400,7 +398,7 @@ public void generateEmails_Should_NotFilter_WhenConsultantsAreMain() throws Exce var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(4)); + assertThat(generatedMails).hasSize(4); } @Test @@ -418,7 +416,8 @@ public void generateEmails_Should_NotFilter_WhenConsultantsAreSessionAssigned() var generatedMails = newFeedbackEmailSupplier.generateEmails(); - assertThat(generatedMails, hasSize(4)); + assertThat(generatedMails).hasSize(4); + assertThat(generatedMails).extracting("dialect").containsOnly(CONSULTANT_2.getDialect()); } private Consultant givenAConsultant() throws JsonProcessingException { diff --git a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplierTest.java b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplierTest.java index 9c77d3997..23db51ef4 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplierTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplierTest.java @@ -161,6 +161,7 @@ public void generateEmails_Should_ReturnEmptyList_When_NoUserRoleIsAvailable() { assertThat(generatedMail.getTemplate(), is(TEMPLATE_NEW_MESSAGE_NOTIFICATION_CONSULTANT)); assertThat(generatedMail.getEmail(), is("email@email.com")); assertThat(generatedMail.getLanguage(), is(LanguageCode.DE)); + assertThat(generatedMail.getDialect(), is(CONSULTANT.getDialect())); List templateData = generatedMail.getTemplateData(); assertThat(templateData, hasSize(3)); assertThat(templateData.get(0).getKey(), is("name")); diff --git a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentConfirmationEmailSupplierTest.java b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentConfirmationEmailSupplierTest.java index e01d700d7..6b50c2ed2 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentConfirmationEmailSupplierTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentConfirmationEmailSupplierTest.java @@ -36,6 +36,7 @@ void generateEmails_Should_returnMailWithExpectedData() { var language = mail.getLanguage(); assertThat(language, is(notNullValue())); assertThat(language.toString(), is(receiverConsultant.getLanguageCode().toString())); + assertThat(mail.getDialect(), is(receiverConsultant.getDialect())); assertThat(mail.getTemplateData(), hasSize(3)); assertThat(mail.getTemplateData().get(0).getKey(), is("name_recipient")); diff --git a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentRequestEmailSupplierTest.java b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentRequestEmailSupplierTest.java index 43c8e41f9..0be558dcb 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentRequestEmailSupplierTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/ReassignmentRequestEmailSupplierTest.java @@ -7,6 +7,7 @@ import static org.hamcrest.Matchers.notNullValue; import com.neovisionaries.i18n.LanguageCode; +import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect; import org.jeasy.random.EasyRandom; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -27,6 +28,7 @@ void generateEmails_Should_returnMailWithExpectedData() { .receiverLanguageCode(receiverLanguageCode) .applicationBaseUrl("base") .receiverUsername("receiverUsername") + .receiverDialect(Dialect.INFORMAL) .build(); var mails = reassignmentSupplier.generateEmails(); @@ -36,6 +38,7 @@ void generateEmails_Should_returnMailWithExpectedData() { assertThat(mail.getEmail(), is("receiverMail")); assertThat(mail.getTemplate(), is(TEMPLATE_REASSIGN_REQUEST_NOTIFICATION)); assertThat(mail.getLanguage(), is(notNullValue())); + assertThat(mail.getDialect(), is(Dialect.INFORMAL)); assertThat(mail.getLanguage().toString(), is(receiverLanguageCode.toString())); assertThat(mail.getTemplateData(), hasSize(2)); assertThat(mail.getTemplateData().get(0).getKey(), is("name_recipient"));