Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FSADT1-1497): Adjust character limit of Street address field #1149

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading