Skip to content

Commit

Permalink
[DE-613] Fix product price points tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-nedza committed Dec 4, 2023
1 parent 550d094 commit b435679
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import com.maxio.advancedbilling.models.ProductPricePoint;
import com.maxio.advancedbilling.models.ProductPricePointResponse;
import com.maxio.advancedbilling.models.ProductResponse;
import com.maxio.advancedbilling.models.containers.ArchiveProductPricePointPricePointId;
import com.maxio.advancedbilling.models.containers.ArchiveProductPricePointProductId;
import com.maxio.advancedbilling.models.containers.CreateProductPricePointProductId;
import org.junit.jupiter.api.BeforeAll;

import java.io.IOException;
Expand Down Expand Up @@ -81,7 +84,7 @@ protected static ProductPricePointResponse createProductPricePointWithDelay(long
}

return PRODUCT_PRICE_POINTS_CONTROLLER
.createProductPricePoint(productId, new CreateProductPricePointRequest(createProductPricePoint));
.createProductPricePoint(CreateProductPricePointProductId.fromNumber(productId), new CreateProductPricePointRequest(createProductPricePoint));
}

protected static CreateProductPricePoint.Builder defaultBuilder() {
Expand All @@ -105,8 +108,8 @@ protected static void archiveAllSitePricePointsExcludingDefault() throws IOExcep
while (!sitePricePointsExcludingDefault.isEmpty()) {
for (ProductPricePoint pricePoint : sitePricePointsExcludingDefault) {
PRODUCT_PRICE_POINTS_CONTROLLER.archiveProductPricePoint(
pricePoint.getProductId(),
pricePoint.getId()
ArchiveProductPricePointProductId.fromNumber(pricePoint.getProductId()),
ArchiveProductPricePointPricePointId.fromNumber(pricePoint.getId())
);
}
sitePricePointsExcludingDefault = listAllSitePricePointsPerPage200ExcludingDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.maxio.advancedbilling.models.Product;
import com.maxio.advancedbilling.models.ProductPricePoint;
import com.maxio.advancedbilling.models.ProductPricePointErrors;
import com.maxio.advancedbilling.models.containers.CreateProductPricePointProductId;
import com.maxio.advancedbilling.utils.CommonAssertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -112,7 +113,8 @@ void shouldReturn422WhenPricePointRequestIsEmpty() {
void shouldReturn422WhenRequiredParametersAreMissing(CreateProductPricePointRequest request, ProductPricePointErrors expectedErrors) {
// when - then
assertThatExceptionOfType(ProductPricePointErrorResponseException.class)
.isThrownBy(() -> PRODUCT_PRICE_POINTS_CONTROLLER.createProductPricePoint(product.getId(), request))
.isThrownBy(() -> PRODUCT_PRICE_POINTS_CONTROLLER
.createProductPricePoint(CreateProductPricePointProductId.fromNumber(product.getId()), request))
.withMessage("Unprocessable Entity (WebDAV)")
.satisfies(e -> {
assertThat(e.getResponseCode()).isEqualTo(422);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.maxio.advancedbilling.models.Product;
import com.maxio.advancedbilling.models.ProductPricePoint;
import com.maxio.advancedbilling.models.SortingDirection;
import com.maxio.advancedbilling.models.containers.ArchiveProductPricePointPricePointId;
import com.maxio.advancedbilling.models.containers.ArchiveProductPricePointProductId;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -46,8 +48,13 @@ static void beforeAll() throws IOException, ApiException {
}

archivedProductPricePoint = PRODUCT_PRICE_POINTS_CONTROLLER.archiveProductPricePoint(
product.getId(),
createProductPricePoint(product.getId(), defaultBuilder().name("archived-test-price-point-%s".formatted(randomAlphabetic(5))).build()).getPricePoint().getId()
ArchiveProductPricePointProductId.fromNumber(product.getId()),
ArchiveProductPricePointPricePointId.fromNumber(
createProductPricePoint(product.getId(),
defaultBuilder()
.name("archived-test-price-point-%s".formatted(randomAlphabetic(5)))
.build()).getPricePoint().getId()
)
)
.getPricePoint();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.maxio.advancedbilling.models.PricePointType;
import com.maxio.advancedbilling.models.Product;
import com.maxio.advancedbilling.models.ProductPricePoint;
import com.maxio.advancedbilling.models.containers.ListProductPricePointsInputProductId;
import com.maxio.advancedbilling.utils.CommonAssertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -31,15 +32,17 @@ void beforeEach() throws IOException, ApiException {
void shouldReturn404WhenProductNotExists() {
// when - then
CommonAssertions.assertNotFound(() -> PRODUCT_PRICE_POINTS_CONTROLLER
.listProductPricePoints(new ListProductPricePointsInput.Builder(12345).build())
.listProductPricePoints(new ListProductPricePointsInput
.Builder(ListProductPricePointsInputProductId.fromNumber(12345)).build())
);
}

@Test
void shouldReturnListWithOriginalPricePointOnly() throws IOException, ApiException {
// when
List<ProductPricePoint> productPricePoints = PRODUCT_PRICE_POINTS_CONTROLLER
.listProductPricePoints(new ListProductPricePointsInput.Builder(product.getId()).build())
.listProductPricePoints(new ListProductPricePointsInput
.Builder(ListProductPricePointsInputProductId.fromNumber(product.getId())).build())
.getPricePoints();

// then
Expand Down Expand Up @@ -83,7 +86,8 @@ void shouldReturnListWithAllPricePoints() throws IOException, ApiException {

// when
List<ProductPricePoint> productPricePoints = PRODUCT_PRICE_POINTS_CONTROLLER
.listProductPricePoints(new ListProductPricePointsInput.Builder(product.getId()).build())
.listProductPricePoints(new ListProductPricePointsInput
.Builder(ListProductPricePointsInputProductId.fromNumber(product.getId())).build())
.getPricePoints();

// then
Expand All @@ -106,23 +110,23 @@ void shouldReturnListWithPagedPricePoints() throws IOException, ApiException {
// when
List<ProductPricePoint> productPricePointsPage1 = PRODUCT_PRICE_POINTS_CONTROLLER
.listProductPricePoints(new ListProductPricePointsInput.Builder()
.productId(product.getId())
.productId(ListProductPricePointsInputProductId.fromNumber(product.getId()))
.page(1)
.perPage(2)
.build()
)
.getPricePoints();
List<ProductPricePoint> productPricePointsPage2 = PRODUCT_PRICE_POINTS_CONTROLLER
.listProductPricePoints(new ListProductPricePointsInput.Builder()
.productId(product.getId())
.productId(ListProductPricePointsInputProductId.fromNumber(product.getId()))
.page(2)
.perPage(2)
.build()
)
.getPricePoints();
List<ProductPricePoint> productPricePointsPage3 = PRODUCT_PRICE_POINTS_CONTROLLER
.listProductPricePoints(new ListProductPricePointsInput.Builder()
.productId(product.getId())
.productId(ListProductPricePointsInputProductId.fromNumber(product.getId()))
.page(3)
.perPage(2)
.build()
Expand All @@ -146,7 +150,7 @@ void shouldReturnListUsingTypeFilter() throws IOException, ApiException {
// when - then
List<ProductPricePoint> pricePointsOfDefaultType = PRODUCT_PRICE_POINTS_CONTROLLER
.listProductPricePoints(new ListProductPricePointsInput.Builder()
.productId(product.getId())
.productId(ListProductPricePointsInputProductId.fromNumber(product.getId()))
.filterType(Collections.singletonList(PricePointType.ENUM_DEFAULT))
.build()
)
Expand All @@ -158,7 +162,7 @@ void shouldReturnListUsingTypeFilter() throws IOException, ApiException {

List<ProductPricePoint> pricePointsOfCatalogType = PRODUCT_PRICE_POINTS_CONTROLLER
.listProductPricePoints(new ListProductPricePointsInput.Builder()
.productId(product.getId())
.productId(ListProductPricePointsInputProductId.fromNumber(product.getId()))
.filterType(Collections.singletonList(PricePointType.CATALOG))
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.maxio.advancedbilling.models.Product;
import com.maxio.advancedbilling.models.ProductPricePoint;
import com.maxio.advancedbilling.models.ProductResponse;
import com.maxio.advancedbilling.models.containers.CreateProductPricePointProductId;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -42,7 +43,8 @@ static void setupProducts() throws IOException, ApiException {
.priceInCents(22).name("Price point to promote").build()
);
ProductPricePoint pricePoint = productPricePointsController
.createProductPricePoint(productWithChangedPricePoint.getId(), createProductPricePointRequest)
.createProductPricePoint(CreateProductPricePointProductId.fromNumber(productWithChangedPricePoint.getId()),
createProductPricePointRequest)
.getPricePoint();
productPricePointsController.promoteProductPricePointToDefault(productWithChangedPricePoint.getId(), pricePoint.getId());
productWithChangedPricePoint = productsController.readProduct(productWithChangedPricePoint.getId()).getProduct();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
Expand Down

0 comments on commit b435679

Please sign in to comment.