diff --git a/src/main/java/pl/gov/coi/pomocua/ads/messages/MessageResource.java b/src/main/java/pl/gov/coi/pomocua/ads/messages/MessageResource.java index aea5420f..542b4705 100644 --- a/src/main/java/pl/gov/coi/pomocua/ads/messages/MessageResource.java +++ b/src/main/java/pl/gov/coi/pomocua/ads/messages/MessageResource.java @@ -36,10 +36,9 @@ public class MessageResource { private final CaptchaValidator captchaValidator; @PostMapping - public ResponseEntity sendMessage(@Valid @RequestBody SendMessageDTO messageDefinition, - @RequestParam(value = "recaptcha-response", required = false) final String recaptchaResponse) { + public ResponseEntity sendMessage(@Valid @RequestBody SendMessageDTO messageDefinition) { - if (!captchaValidator.validate(recaptchaResponse)) { + if (!captchaValidator.validate(messageDefinition.recaptchaResponse)) { throw new CaptchaException(); } diff --git a/src/main/java/pl/gov/coi/pomocua/ads/messages/SendMessageDTO.java b/src/main/java/pl/gov/coi/pomocua/ads/messages/SendMessageDTO.java index 1e5b1711..344e3059 100644 --- a/src/main/java/pl/gov/coi/pomocua/ads/messages/SendMessageDTO.java +++ b/src/main/java/pl/gov/coi/pomocua/ads/messages/SendMessageDTO.java @@ -11,20 +11,26 @@ public final class SendMessageDTO { @NotNull public final Long offerId; + public final String text; + @NotEmpty @Email(regexp = EMAIL_REGEX) public final String replyEmail; + @NotNull @AssertTrue(message = "{terms-and-conditions.validation}") public final boolean tosApproved; + public final String recaptchaResponse; + public SendMessageDTO(Long offerId, String text, String replyEmail, - boolean tosApproved) { + boolean tosApproved, String recaptchaResponse) { this.offerId = offerId; this.text = text; this.replyEmail = replyEmail; this.tosApproved = tosApproved; + this.recaptchaResponse = recaptchaResponse; } diff --git a/src/test/java/pl/gov/coi/pomocua/ads/messages/MessageResourceTest.java b/src/test/java/pl/gov/coi/pomocua/ads/messages/MessageResourceTest.java index 5d42b9fd..dae56b98 100644 --- a/src/test/java/pl/gov/coi/pomocua/ads/messages/MessageResourceTest.java +++ b/src/test/java/pl/gov/coi/pomocua/ads/messages/MessageResourceTest.java @@ -87,7 +87,8 @@ void shouldSendEmailToOfferCreator() throws Exception { offer.id, "message body", "reply@email.invalid", - true + true, + "" ), Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); @@ -136,7 +137,8 @@ void shouldFailWhenEmailPrefixIsIncorrect() { offer.id, "message body", ".email@message@text.test", - true + true, + "" ), Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); @@ -152,7 +154,8 @@ void shouldFailWhenEmailPrefixIsIncorrect_andWhenHeaderLanguageIsPL_expectPolish offer.id, "message body", ".email@message@text.test", - true + true, + "" ), headers); ResponseEntity response = restTemplate.postForEntity("/api/message", entity, ErrorResponse.class); @@ -175,7 +178,8 @@ void shouldFailWhenEmailPrefixIsIncorrect_andWhenHeaderLanguageIsEn_expectEnglis offer.id, "message body", ".email@message@text.test", - true + true, + "" ), headers); ResponseEntity response = restTemplate.postForEntity("/api/message", entity, ErrorResponse.class); @@ -196,7 +200,8 @@ void shouldFailWhenEmailSuffixIsIncorrect() { offer.id, "message body", "email@invalid", - true + true, + "" ), Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); @@ -210,7 +215,8 @@ void shouldFailWithoutAcceptingToS() { offer.id, "abc", "reply@email.invalid", - false + false, + "" ), Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); @@ -221,7 +227,8 @@ void shouldFailWithoutOfferId() { null, "abc", "reply@email.invalid", - true + true, + "" ), Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); @@ -235,7 +242,8 @@ void shouldFailWithoutEmail() { offer.id, "text", "", - true + true, + "" ), Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); @@ -248,7 +256,8 @@ void shouldFailWhenOfferAuthorDoesNotExist() { offer.id, "text", "reply@email.invalid", - true + true, + "" ), Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); @@ -261,7 +270,8 @@ void shouldFailForNotExistingOffer() { 1L, "text", "reply@email.invalid", - true + true, + "" ), Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);