Skip to content

Commit

Permalink
[DE-572] Applied code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
patryk-grudzien-keen committed Nov 30, 2023
1 parent 9aa31bd commit f20c7eb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

Expand Down Expand Up @@ -85,24 +83,8 @@ void shouldReturn422WhenPricePointInRequestIsNull() {
.satisfies(e -> {
assertThat(e.getResponseCode()).isEqualTo(422);
assertThat(e.getErrors())
.extracting(
ProductPricePointErrors::getPricePoint,
ProductPricePointErrors::getInterval,
ProductPricePointErrors::getIntervalUnit,
ProductPricePointErrors::getName,
ProductPricePointErrors::getPrice,
ProductPricePointErrors::getPriceInCents
)
.containsExactlyElementsOf(
Arrays.asList(
"can't be blank",
null,
null,
null,
null,
null
)
);
.usingRecursiveComparison()
.isEqualTo(new ProductPricePointErrors.Builder().pricePoint("can't be blank").build());
});
}

Expand All @@ -115,45 +97,28 @@ void shouldReturn422WhenPricePointRequestIsEmpty() {
.satisfies(e -> {
assertThat(e.getResponseCode()).isEqualTo(422);
assertThat(e.getErrors())
.extracting(
ProductPricePointErrors::getPricePoint,
ProductPricePointErrors::getInterval,
ProductPricePointErrors::getIntervalUnit,
ProductPricePointErrors::getName,
ProductPricePointErrors::getPrice,
ProductPricePointErrors::getPriceInCents
)
.containsExactlyElementsOf(
Arrays.asList(
null,
Collections.singletonList("Recurring Interval: must be greater than or equal to 1."),
Arrays.asList("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."),
Collections.singletonList("Name: cannot be blank."),
null,
null
)
.usingRecursiveComparison()
.isEqualTo(new ProductPricePointErrors.Builder()
.interval(List.of("Recurring Interval: must be greater than or equal to 1."))
.intervalUnit(List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."))
.name(List.of("Name: cannot be blank."))
.build()
);
});
}

@ParameterizedTest
@MethodSource("argsForShouldReturn422WhenRequiredParametersAreMissing")
void shouldReturn422WhenRequiredParametersAreMissing(CreateProductPricePointRequest request, List<List<String>> expectedErrors) {
void shouldReturn422WhenRequiredParametersAreMissing(CreateProductPricePointRequest request, ProductPricePointErrors expectedErrors) {
// when - then
assertThatExceptionOfType(ProductPricePointErrorResponseException.class)
.isThrownBy(() -> PRODUCT_PRICE_POINTS_CONTROLLER.createProductPricePoint(product.getId(), request))
.withMessage("Unprocessable Entity (WebDAV)")
.satisfies(e -> {
assertThat(e.getResponseCode()).isEqualTo(422);
assertThat(e.getErrors())
.extracting(
ProductPricePointErrors::getInterval,
ProductPricePointErrors::getIntervalUnit,
ProductPricePointErrors::getName,
ProductPricePointErrors::getPrice,
ProductPricePointErrors::getPriceInCents
)
.containsExactlyElementsOf(expectedErrors);
.usingRecursiveComparison()
.isEqualTo(expectedErrors);
});
}

Expand All @@ -163,22 +128,20 @@ private static Stream<Arguments> argsForShouldReturn422WhenRequiredParametersAre
new CreateProductPricePointRequest(
new CreateProductPricePoint.Builder().name("").build()
),
Arrays.asList(
List.of("Recurring Interval: must be greater than or equal to 1."),
List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."),
List.of("Name: cannot be blank."),
null, null
)
new ProductPricePointErrors.Builder()
.interval(List.of("Recurring Interval: must be greater than or equal to 1."))
.intervalUnit(List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."))
.name(List.of("Name: cannot be blank."))
.build()
),
Arguments.of(
new CreateProductPricePointRequest(
new CreateProductPricePoint.Builder().name("price point name").build()
),
Arrays.asList(
List.of("Recurring Interval: must be greater than or equal to 1."),
List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."),
null, null, null
)
new ProductPricePointErrors.Builder()
.interval(List.of("Recurring Interval: must be greater than or equal to 1."))
.intervalUnit(List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."))
.build()
),
Arguments.of(
new CreateProductPricePointRequest(
Expand All @@ -187,13 +150,11 @@ private static Stream<Arguments> argsForShouldReturn422WhenRequiredParametersAre
.priceInCents(-100L)
.build()
),
Arrays.asList(
List.of("Recurring Interval: must be greater than or equal to 1."),
List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."),
null,
List.of("Price: must be greater than or equal to 0."),
null
)
new ProductPricePointErrors.Builder()
.interval(List.of("Recurring Interval: must be greater than or equal to 1."))
.intervalUnit(List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."))
.price(List.of("Price: must be greater than or equal to 0."))
.build()
),
Arguments.of(
new CreateProductPricePointRequest(
Expand All @@ -203,13 +164,10 @@ private static Stream<Arguments> argsForShouldReturn422WhenRequiredParametersAre
.interval(0)
.build()
),
Arrays.asList(
List.of("Recurring Interval: must be greater than or equal to 1."),
List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."),
null,
null,
null
)
new ProductPricePointErrors.Builder()
.interval(List.of("Recurring Interval: must be greater than or equal to 1."))
.intervalUnit(List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."))
.build()
),
Arguments.of(
new CreateProductPricePointRequest(
Expand All @@ -218,13 +176,11 @@ private static Stream<Arguments> argsForShouldReturn422WhenRequiredParametersAre
.interval(-1)
.build()
),
Arrays.asList(
List.of("Recurring Interval: must be greater than or equal to 1."),
List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."),
List.of("Name: cannot be blank."),
null,
null
)
new ProductPricePointErrors.Builder()
.interval(List.of("Recurring Interval: must be greater than or equal to 1."))
.intervalUnit(List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."))
.name(List.of("Name: cannot be blank."))
.build()
),
Arguments.of(
new CreateProductPricePointRequest(
Expand All @@ -235,13 +191,9 @@ private static Stream<Arguments> argsForShouldReturn422WhenRequiredParametersAre
.intervalUnit(null)
.build()
),
Arrays.asList(
null,
List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."),
null,
null,
null
)
new ProductPricePointErrors.Builder()
.intervalUnit(List.of("Interval unit: cannot be blank.", "Interval unit: must be 'month' or 'day'."))
.build()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ProductPricePointsControllerListAllTest extends ProductPricePointsBaseTest
private static Product product;
private static ProductPricePoint archivedProductPricePoint;

private static final LinkedList<ProductPricePoint> PRODUCT_PRICE_POINTS_OF_TYPE_CATALOG = new LinkedList<>();
private static final List<ProductPricePoint> PRODUCT_PRICE_POINTS_OF_TYPE_CATALOG = new LinkedList<>();

@BeforeAll
static void beforeAll() throws IOException, ApiException {
Expand Down Expand Up @@ -103,7 +103,9 @@ void shouldReturnListWithAllPricePointsSortedByCreatedAtDesc() throws IOExceptio

// then
assertThat(productPricePoints).hasSize(4);
assertThat(productPricePoints.get(0).getCreatedAt()).isAfter(productPricePoints.get(1).getCreatedAt());
for (int i = 0; i < productPricePoints.size() - 1; i++) {
assertThat(productPricePoints.get(i).getCreatedAt()).isAfter(productPricePoints.get(i + 1).getCreatedAt());
}
}

@Test
Expand Down Expand Up @@ -154,7 +156,7 @@ void shouldReturnEmptyListWhenEndDateTimeFilterDoesNotMatchCreatedAtTimeframe()
}

@Test
void shouldReturnEmptyListWhenIdsFilterContainsIncorrectValues() throws IOException, ApiException {
void shouldReturnEmptyListWhenIdsFilterContainsNonExistentValues() throws IOException, ApiException {
// when
List<ProductPricePoint> productPricePoints = PRODUCT_PRICE_POINTS_CONTROLLER
.listAllProductPricePoints(
Expand Down

0 comments on commit f20c7eb

Please sign in to comment.