Skip to content

Commit

Permalink
Merge pull request #130 from cabinetoffice/release/10.0
Browse files Browse the repository at this point in the history
DRAFT: release/10.0
  • Loading branch information
dominicwest authored Apr 2, 2024
2 parents c54384e + a16ddac commit 93b11cc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class CreateGrantBeneficiaryDto {
private Boolean locationSco;
private Boolean locationWal;
private Boolean locationNir;
private Boolean locationLon;
private Boolean locationOutUk;

@NotNull(message = "Select 'Yes, answer the equality questions' or 'No, skip the equality questions'")
private Boolean hasProvidedAdditionalAnswers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class GetGrantBeneficiaryDto {
private Boolean locationSco;
private Boolean locationWal;
private Boolean locationNir;
private Boolean locationLon;
private Boolean locationOutUk;
private Boolean hasProvidedAdditionalAnswers;
private Boolean ageGroup1;
private Boolean ageGroup2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public class GrantBeneficiary {
@Column
private Boolean locationNir;

@Column
private Boolean locationLon;

@Column
private Boolean locationOutUk;

@Column
private Boolean hasProvidedAdditionalAnswers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ private void createGrantBeneficiary(final Submission submission) {
.locationSco(containsLocation(locations, "Scotland"))
.locationWal(containsLocation(locations, "Wales"))
.locationNir(containsLocation(locations, "Northern Ireland"))
.locationLon(containsLocation(locations, "London"))
.locationOutUk(containsLocation(locations, "Outside of the UK"))
.gapId(submission.getGapId())
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,46 +102,48 @@ private ValidationResult validate(CreateQuestionResponseDto submittedQuestion, S
}
}

if (validation.getMinLength() != null &&
submittedQuestion.getResponse().length() < validation.getMinLength()) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, String.format("Answer must be %s characters or more", validation.getMinLength()));
return result;
}
if (!singleResponseIsEmpty) {
if (validation.getMinLength() != null &&
submittedQuestion.getResponse().length() < validation.getMinLength()) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, String.format("Answer must be %s characters or more", validation.getMinLength()));
return result;
}

if (validation.getMaxLength() != null &&
submittedQuestion.getResponse().length() > validation.getMaxLength()) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, String.format("Answer must be %s characters or less", validation.getMaxLength()));
return result;
}
if (validation.getMaxLength() != null &&
submittedQuestion.getResponse().length() > validation.getMaxLength()) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, String.format("Answer must be %s characters or less", validation.getMaxLength()));
return result;
}

if (validation.getMinWords() != null &&
getNumberOfWords(submittedQuestion.getResponse()) < validation.getMinWords()) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, String.format("Answer must be %s words or more", validation.getMinWords()));
return result;
}
if (validation.getMinWords() != null &&
getNumberOfWords(submittedQuestion.getResponse()) < validation.getMinWords()) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, String.format("Answer must be %s words or more", validation.getMinWords()));
return result;
}

if (validation.getMaxWords() != null &&
getNumberOfWords(submittedQuestion.getResponse()) > validation.getMaxWords()) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, String.format("Answer must be %s words or less", validation.getMaxWords()));
return result;
}
if (validation.getMaxWords() != null &&
getNumberOfWords(submittedQuestion.getResponse()) > validation.getMaxWords()) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, String.format("Answer must be %s words or less", validation.getMaxWords()));
return result;
}

if (validation.getGreaterThanZero() != null &&
validation.getGreaterThanZero()) {
try {
if (Float.parseFloat(submittedQuestion.getResponse()) <= 0F) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, "Answer must have a value greater than zero");
if (validation.getGreaterThanZero() != null &&
validation.getGreaterThanZero()) {
try {
if (Float.parseFloat(submittedQuestion.getResponse()) <= 0F) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, "Answer must have a value greater than zero");
return result;
}
} catch (final NumberFormatException e) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, "Answer must only include numeric values/ decimal");
return result;
}
} catch (final NumberFormatException e) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, "Answer must only include numeric values/ decimal");
return result;
}
}

if (!singleResponseIsEmpty && containsSpecialCharacters(submittedQuestion.getResponse())) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, "Answer must only include letters, numbers, and special characters such as hyphens, spaces and apostrophes");
return result;
if (containsSpecialCharacters(submittedQuestion.getResponse())) {
result.addError(ValidationConstants.SINGLE_RESPONSE_FIELD, "Answer must only include letters, numbers, and special characters such as hyphens, spaces and apostrophes");
return result;
}
}

result.setValid(Boolean.TRUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SubmissionServiceTest {
final String amount = "1000";
final String companiesHouseNo = "1234";
final String charityNo = "1234";
final String[] beneficiaryLocation = new String[]{"South West England", "Midlands", "Scotland"};
final String[] beneficiaryLocation = new String[]{"South West England", "Midlands", "Scotland", "London"};
final String userId = "75ab5fbd-0682-4d3d-a467-01c7a447f07c";
private final String CHRISTMAS_2022_MIDDAY = "2022-12-25T12:00:00.00z";
private final Clock clock = Clock.fixed(Instant.parse(CHRISTMAS_2022_MIDDAY), ZoneId.of("UTC"));
Expand Down Expand Up @@ -1350,6 +1350,8 @@ void submit_CreatesGrantBeneficiary() {
assertThat(capturedBeneficiary.getLocationMidEng()).isTrue();
assertThat(capturedBeneficiary.getLocationSeEng()).isFalse();
assertThat(capturedBeneficiary.getLocationNwEng()).isFalse();
assertThat(capturedBeneficiary.getLocationLon()).isTrue();
assertThat(capturedBeneficiary.getLocationOutUk()).isFalse();
assertThat(capturedBeneficiary.getGapId()).isEqualTo(submission.getGapId());
}

Expand Down

0 comments on commit 93b11cc

Please sign in to comment.