Skip to content

Commit

Permalink
Merge pull request #29 from leung018/product-domain-update
Browse files Browse the repository at this point in the history
Validate userId in product domain layer
  • Loading branch information
leung018 authored Dec 20, 2024
2 parents 3bdf0a3 + 8e39796 commit bbee66f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Builder toBuilder() {
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private String id;

private String userId;
@NotBlank private String userId;

@NotBlank private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void shouldIgnoreIdWhenCreateProduct() throws Exception {
@Test
void shouldHandleObjectValidationException_AndIncludeTheProperInfoInTheResponse()
throws Exception {
useNewUserAccessToken();
String userId = useNewUserAccessToken();

CreateProductParams params = CreateProductParams.sample();
params.price = "-1";
Expand All @@ -120,6 +120,7 @@ void shouldHandleObjectValidationException_AndIncludeTheProperInfoInTheResponse(
new Product.Builder()
.name(params.name)
.price(new BigDecimal(params.price))
.userId(userId)
.quantity(params.quantity)
.build();
} catch (ObjectValidationException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ void shouldRaiseExceptionWhenBuild_IfParamsViolateTheValidationConstraints() {

assertThrowValidationException(productBuilder().name(""));
assertThrowValidationException(productBuilder().name(null));

assertThrowValidationException(productBuilder().userId(""));
assertThrowValidationException(productBuilder().userId(null));
}

private void assertThrowValidationException(Product.Builder builder) {
Expand Down

0 comments on commit bbee66f

Please sign in to comment.