Skip to content

Commit

Permalink
feat(FSADT1-1497): Adjust character limit of Street address field (#1149
Browse files Browse the repository at this point in the history
)

Co-authored-by: Paulo Gomes da Cruz Junior <paulo.cruz@gov.bc.ca>
  • Loading branch information
mamartinezmejia and paulushcgcj authored Sep 12, 2024
1 parent e84b738 commit b07650f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ public Mono<ValidationError> validate(ClientAddressDto target, Integer index) {
return Mono.just(
new ValidationError(fieldName, "You must enter a street address or PO box number."));
}

if (!US7ASCII_PATTERN.matcher(fieldValue).matches()) {
return Mono.just(new ValidationError(fieldName,
String.format("%s has an invalid character.", fieldValue)));
}

if (StringUtils.length(fieldValue) < 4) {
return Mono.just(new ValidationError(fieldName, "The address must be between 4 and 40 characters."));
}

if (StringUtils.length(fieldValue) > 40) {
return Mono.just(new ValidationError(fieldName, "This field has a 40 character limit."));
return Mono.just(new ValidationError(fieldName, "The address must be between 4 and 40 characters."));
}

return Mono.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ private Mono<ValidationError> validateAddressField(String content, String fieldN
return Mono.just(
new ValidationError(fieldName, String.format("%s has an invalid character.", content)));
}

if (StringUtils.length(content) < 4) {
return Mono.just(new ValidationError(fieldName, "The address must be between 4 and 40 characters."));
}

if (StringUtils.length(content) > 40) {
return Mono.just(new ValidationError(fieldName, "This field has a 40 character limit."));
return Mono.just(new ValidationError(fieldName, "The address must be between 4 and 40 characters."));
}
}
return Mono.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public Mono<ValidationError> validate(ClientAddressDto target, Integer index) {
if (StringUtils.length(target.locationName()) > 40) {
return Mono.just(new ValidationError(fieldName, "This field has a 40 character limit."));
}

return Mono.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,12 @@ public static Stream<Arguments> validSources() {
}

private static Stream<Arguments> validation() {
return
Stream.of(
Arguments.of(StringUtils.EMPTY, "You must enter a street address or PO box number."),
Arguments.of("1234 Mainé St", "1234 Mainé St has an invalid character."),
Arguments.of("Avenida Bailarina Selma Parada 505, Sala 12 Conjunto 5",
"This field has a 40 character limit."),
Arguments.of("1234 Main St", StringUtils.EMPTY)
);
return Stream.of(
Arguments.of(StringUtils.EMPTY, "You must enter a street address or PO box number."),
Arguments.of("1234 Mainé St", "1234 Mainé St has an invalid character."),
Arguments.of("Avenida Bailarina Selma Parada 505, Sala 12 Conjunto 5",
"The address must be between 4 and 40 characters."),
Arguments.of("1234 Main St", StringUtils.EMPTY));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,31 @@ void shouldValidate(
}

private static Stream<Arguments> validation() {
return
Stream.of(
Arguments.of(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY,
StringUtils.EMPTY),
Arguments.of(StringUtils.EMPTY, "Something", "One",
"You must enter the first complementary address."),
Arguments.of("Something é", StringUtils.EMPTY, "One",
"Something é has an invalid character."),
Arguments.of("Potato".repeat(10), StringUtils.EMPTY, "One",
"This field has a 40 character limit."),
Arguments.of("Potato", "Something é", "Two", "Something é has an invalid character."),
Arguments.of("Potato", "Potato".repeat(10), "Two",
"This field has a 40 character limit.")
);
return Stream.of(
Arguments.of(StringUtils.EMPTY,
StringUtils.EMPTY,
StringUtils.EMPTY,
StringUtils.EMPTY),
Arguments.of(StringUtils.EMPTY,
"Something",
"One",
"You must enter the first complementary address."),
Arguments.of("Something é",
StringUtils.EMPTY,
"One",
"Something é has an invalid character."),
Arguments.of("Potato".repeat(10),
StringUtils.EMPTY,
"One",
"The address must be between 4 and 40 characters."),
Arguments.of("Potato",
"Something é",
"Two",
"Something é has an invalid character."),
Arguments.of("Potato",
"Potato".repeat(10),
"Two",
"The address must be between 4 and 40 characters."));
}

}
6 changes: 3 additions & 3 deletions frontend/src/helpers/validators/BCeIDFormValidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ formFieldValidations["location.addresses.*.city"] = [
];
formFieldValidations["location.addresses.*.streetAddress"] = [
isNotEmpty("Please provide a valid address or PO Box"),
isMinSize("The address must be between 5 and 40 characters")(5),
isMaxSize("The address must be between 5 and 40 characters")(40),
isMinSize("The address must be between 4 and 40 characters")(4),
isMaxSize("The address must be between 4 and 40 characters")(40),
isAscii("address"),
];
formFieldValidations[
Expand Down Expand Up @@ -129,4 +129,4 @@ export const addValidation = (
};

export const getValidations = (key: string): ((value: any) => string)[] =>
key ? formFieldValidations[key] || [] : [];
key ? formFieldValidations[key] || [] : [];
6 changes: 3 additions & 3 deletions frontend/src/helpers/validators/StaffFormValidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ fieldValidations["location.addresses.*.city"] = [
];
fieldValidations["location.addresses.*.streetAddress"] = [
isNotEmpty("Please provide a valid address or PO Box"),
isMinSize("The address must be between 5 and 40 characters")(5),
isMaxSize("The address must be between 5 and 40 characters")(40),
isMinSize("The address must be between 4 and 40 characters")(4),
isMaxSize("The address must be between 4 and 40 characters")(40),
isAscii("address"),
];
fieldValidations[
Expand Down Expand Up @@ -337,4 +337,4 @@ export const validate = (
return globalValidate.apply(this, args);
};

export const runValidation = globalRunValidation;
export const runValidation = globalRunValidation;

0 comments on commit b07650f

Please sign in to comment.