Skip to content

Commit

Permalink
fix(be): Reverted commit 0bf884c and fixed subject when the email fai… (
Browse files Browse the repository at this point in the history
  • Loading branch information
mamartinezmejia authored Apr 5, 2024
1 parent eb82c4c commit 50ffa1e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -91,11 +90,12 @@ public Mono<String> sendEmail(String templateName,
emailVariables.put("frontend", configuration.getFrontend().getUrl());

final Map<String,Object> variables = new HashMap<>(emailVariables);

String strippedSubject = subject.replaceFirst("^\\[\\w+\\]\\s*", "");

String processedSubject =
configuration.getSecurity().getEnvironment().equalsIgnoreCase("prod")
? subject
: String.format("[%s] %s", configuration.getSecurity().getEnvironment(), subject);
: String.format("[%s] %s", configuration.getSecurity().getEnvironment(), strippedSubject);

log.info("Sending email to {} with subject {}", emailAddress, processedSubject);

Expand Down Expand Up @@ -232,7 +232,7 @@ public Mono<String> sendEmail(ChesRequestDto requestContent, String subject) {
.flatMap(token ->
chesApi
.post()
.uri("/mail")
.uri(configuration.getChes().getUri())
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(Mono.just(request), ChesMailRequest.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void init() {

chesStub
.stubFor(
post("/chess/uri/mail")
post("/chess/uri")
.willReturn(
ok(TestConstants.CHES_SUCCESS_MESSAGE)
.withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void shouldNotSendMailWhenTokenInvalid() {
mockOAuthSuccess();

wireMockExtension
.stubFor(post("/chess/uri/mail").willReturn(unauthorized()));
.stubFor(post("/chess/uri").willReturn(unauthorized()));

service
.sendEmail(new ChesRequestDto(List.of("[email protected]"), "simple body"), "Test")
Expand All @@ -79,7 +79,7 @@ void shouldNotSendMailWhenNoRoleInvalid() {
mockOAuthSuccess();

wireMockExtension
.stubFor(post("/chess/uri/mail").willReturn(forbidden()));
.stubFor(post("/chess/uri").willReturn(forbidden()));

service
.sendEmail(new ChesRequestDto(List.of("[email protected]"), "simple body"), "Test")
Expand All @@ -99,7 +99,7 @@ void shouldSendMailWhenAuth(ChesRequestDto body) {

wireMockExtension
.stubFor(
post("/chess/uri/mail")
post("/chess/uri")
.willReturn(
ok(TestConstants.CHES_SUCCESS_MESSAGE)
.withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -121,7 +121,7 @@ void shouldFailWith422() {

wireMockExtension
.stubFor(
post("/chess/uri/mail")
post("/chess/uri")
.willReturn(
status(422)
.withBody(TestConstants.CHES_422_MESSAGE)
Expand All @@ -144,7 +144,7 @@ void shouldSendMailWithNoBody() {

wireMockExtension
.stubFor(
post("/chess/uri/mail")
post("/chess/uri")
.willReturn(
status(400)
.withBody(TestConstants.CHES_400_MESSAGE)
Expand All @@ -167,7 +167,7 @@ void shouldFailWith500() {

wireMockExtension
.stubFor(
post("/chess/uri/mail")
post("/chess/uri")
.willReturn(
status(500)
.withBody(TestConstants.CHES_500_MESSAGE)
Expand All @@ -191,7 +191,7 @@ void shouldSendMailMultipleDestination() {

wireMockExtension
.stubFor(
post("/chess/uri/mail")
post("/chess/uri")
.willReturn(
ok(TestConstants.CHES_SUCCESS_MESSAGE)
.withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
Expand Down

0 comments on commit 50ffa1e

Please sign in to comment.