diff --git a/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java b/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java index a3135c4e9b..89ace74b06 100644 --- a/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java +++ b/backend/src/main/java/ca/bc/gov/app/service/ches/ChesService.java @@ -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; @@ -91,11 +90,12 @@ public Mono sendEmail(String templateName, emailVariables.put("frontend", configuration.getFrontend().getUrl()); final Map 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); @@ -232,7 +232,7 @@ public Mono 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) diff --git a/backend/src/test/java/ca/bc/gov/app/controller/ches/ChesControllerIntegrationTest.java b/backend/src/test/java/ca/bc/gov/app/controller/ches/ChesControllerIntegrationTest.java index 81b877f96e..49d8707d96 100644 --- a/backend/src/test/java/ca/bc/gov/app/controller/ches/ChesControllerIntegrationTest.java +++ b/backend/src/test/java/ca/bc/gov/app/controller/ches/ChesControllerIntegrationTest.java @@ -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) diff --git a/backend/src/test/java/ca/bc/gov/app/service/ches/ChesServiceIntegrationTest.java b/backend/src/test/java/ca/bc/gov/app/service/ches/ChesServiceIntegrationTest.java index 8dfb19b13c..ae21455bc8 100644 --- a/backend/src/test/java/ca/bc/gov/app/service/ches/ChesServiceIntegrationTest.java +++ b/backend/src/test/java/ca/bc/gov/app/service/ches/ChesServiceIntegrationTest.java @@ -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("jhon@mail.ca"), "simple body"), "Test") @@ -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("jhon@mail.ca"), "simple body"), "Test") @@ -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) @@ -121,7 +121,7 @@ void shouldFailWith422() { wireMockExtension .stubFor( - post("/chess/uri/mail") + post("/chess/uri") .willReturn( status(422) .withBody(TestConstants.CHES_422_MESSAGE) @@ -144,7 +144,7 @@ void shouldSendMailWithNoBody() { wireMockExtension .stubFor( - post("/chess/uri/mail") + post("/chess/uri") .willReturn( status(400) .withBody(TestConstants.CHES_400_MESSAGE) @@ -167,7 +167,7 @@ void shouldFailWith500() { wireMockExtension .stubFor( - post("/chess/uri/mail") + post("/chess/uri") .willReturn( status(500) .withBody(TestConstants.CHES_500_MESSAGE) @@ -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)