-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DE-572] + [DE-599] Java CRUD for Product Price Points endpoints part…
… 1 & 2 (#45)
- Loading branch information
1 parent
46bae5e
commit 56dd6a8
Showing
12 changed files
with
903 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...vancedbilling/controllers/productpricepoints/ProductPricePointsControllerArchiveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.maxio.advancedbilling.controllers.productpricepoints; | ||
|
||
import com.maxio.advancedbilling.exceptions.ApiException; | ||
import com.maxio.advancedbilling.exceptions.ErrorListResponseException; | ||
import com.maxio.advancedbilling.models.Product; | ||
import com.maxio.advancedbilling.models.ProductPricePoint; | ||
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; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static com.maxio.advancedbilling.utils.CommonAssertions.assertNotFound; | ||
import static com.maxio.advancedbilling.utils.CommonAssertions.assertUnprocessableEntity; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ProductPricePointsControllerArchiveTest extends ProductPricePointsBaseTest { | ||
|
||
private static Product product; | ||
|
||
@BeforeAll | ||
static void beforeAll() throws IOException, ApiException { | ||
product = createProduct(); | ||
} | ||
|
||
@Test | ||
void shouldReturn404WhenProductNotExists() { | ||
// when - then | ||
assertNotFound(() -> PRODUCT_PRICE_POINTS_CONTROLLER.archiveProductPricePoint( | ||
ArchiveProductPricePointProductId.fromNumber(12345), | ||
ArchiveProductPricePointPricePointId.fromNumber(product.getProductPricePointId()) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void shouldReturn404WhenProductPricePointNotExists() { | ||
// when - then | ||
assertNotFound(() -> PRODUCT_PRICE_POINTS_CONTROLLER.archiveProductPricePoint( | ||
ArchiveProductPricePointProductId.fromNumber(product.getId()), | ||
ArchiveProductPricePointPricePointId.fromNumber(12345) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void shouldReturn422WhenArchivingDefaultProductPricePoint() { | ||
// when - then | ||
assertUnprocessableEntity( | ||
ErrorListResponseException.class, | ||
() -> PRODUCT_PRICE_POINTS_CONTROLLER.archiveProductPricePoint( | ||
ArchiveProductPricePointProductId.fromNumber(product.getId()), | ||
ArchiveProductPricePointPricePointId.fromNumber(product.getProductPricePointId()) | ||
), | ||
e -> assertThat(e.getErrors()) | ||
.usingRecursiveComparison() | ||
.isEqualTo(List.of("Cannot archive the default price point.")) | ||
|
||
); | ||
} | ||
|
||
@Test | ||
void shouldArchiveNonDefaultProductPricePointById() throws IOException, ApiException { | ||
// given | ||
ProductPricePoint savedProductPricePoint = createProductPricePoint( | ||
product.getId(), defaultBuilder().name("price-point-name").build() | ||
).getPricePoint(); | ||
|
||
// when | ||
ProductPricePoint archivedPricePoint = PRODUCT_PRICE_POINTS_CONTROLLER | ||
.archiveProductPricePoint( | ||
ArchiveProductPricePointProductId.fromNumber(product.getId()), | ||
ArchiveProductPricePointPricePointId.fromNumber(savedProductPricePoint.getId()) | ||
) | ||
.getPricePoint(); | ||
|
||
// then | ||
assertThat(archivedPricePoint.getArchivedAt()).isNotNull(); | ||
} | ||
|
||
@Test | ||
void shouldArchiveNonDefaultProductPricePointByHandle() throws IOException, ApiException { | ||
// given | ||
ProductPricePoint savedProductPricePoint = createProductPricePoint( | ||
product.getId(), defaultBuilder().name("price-point-name").handle("handle-123").build() | ||
).getPricePoint(); | ||
|
||
// when | ||
ProductPricePoint archivedPricePoint = PRODUCT_PRICE_POINTS_CONTROLLER | ||
.archiveProductPricePoint( | ||
ArchiveProductPricePointProductId.fromString("handle:" + product.getHandle()), | ||
ArchiveProductPricePointPricePointId.fromString("handle:" + savedProductPricePoint.getHandle()) | ||
) | ||
.getPricePoint(); | ||
|
||
// then | ||
assertThat(archivedPricePoint.getArchivedAt()).isNotNull(); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...cedbilling/controllers/productpricepoints/ProductPricePointsControllerBulkCreateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.maxio.advancedbilling.controllers.productpricepoints; | ||
|
||
import com.maxio.advancedbilling.exceptions.ApiException; | ||
import com.maxio.advancedbilling.models.BulkCreateProductPricePointsRequest; | ||
import com.maxio.advancedbilling.models.CreateProductPricePoint; | ||
import com.maxio.advancedbilling.models.Product; | ||
import com.maxio.advancedbilling.models.ProductPricePoint; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import static com.maxio.advancedbilling.utils.CommonAssertions.assertNotFound; | ||
import static com.maxio.advancedbilling.utils.CommonAssertions.assertUnprocessableEntity; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ProductPricePointsControllerBulkCreateTest extends ProductPricePointsBaseTest { | ||
|
||
private static Product product; | ||
|
||
@BeforeAll | ||
static void beforeAll() throws IOException, ApiException { | ||
product = createProduct(); | ||
} | ||
|
||
@Test | ||
void shouldReturn201AndCreatePricePoints() throws IOException, ApiException { | ||
// when | ||
List<ProductPricePoint> pricePoints = PRODUCT_PRICE_POINTS_CONTROLLER | ||
.createProductPricePoints( | ||
product.getId(), | ||
new BulkCreateProductPricePointsRequest(List.of( | ||
defaultBuilder().name("price-point-name-1").build(), | ||
defaultBuilder().name("price-point-name-2").build() | ||
)) | ||
) | ||
.getPricePoints(); | ||
|
||
// then | ||
assertThat(pricePoints) | ||
.hasSize(3) | ||
.extracting(ProductPricePoint::getName) | ||
.containsExactlyInAnyOrder("Original", "price-point-name-1", "price-point-name-2"); | ||
} | ||
|
||
@Test | ||
void shouldReturn404WhenCreatingPricePointsForNotExistingProduct() { | ||
// when - then | ||
assertNotFound(() -> PRODUCT_PRICE_POINTS_CONTROLLER | ||
.createProductPricePoints(12345, new BulkCreateProductPricePointsRequest()) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("argsForShouldReturn201WithDefaultProductPricePointOnlyWhenRequestIsNullOrContainsNullOrEmptyList") | ||
void shouldReturn201WithDefaultProductPricePointOnlyWhenRequestIsNullOrContainsNullOrEmptyList(BulkCreateProductPricePointsRequest request) | ||
throws IOException, ApiException { | ||
// when | ||
List<ProductPricePoint> pricePoints = PRODUCT_PRICE_POINTS_CONTROLLER | ||
.createProductPricePoints(createProduct().getId(), request) // new different product | ||
.getPricePoints(); | ||
|
||
// then | ||
assertThat(pricePoints) | ||
.hasSize(1) | ||
.extracting(ProductPricePoint::getName) | ||
.containsExactly("Original"); | ||
} | ||
|
||
private static Stream<Arguments> argsForShouldReturn201WithDefaultProductPricePointOnlyWhenRequestIsNullOrContainsNullOrEmptyList() { | ||
return Stream.of( | ||
Arguments.of((Object) null), | ||
Arguments.of(new BulkCreateProductPricePointsRequest(null)), | ||
Arguments.of(new BulkCreateProductPricePointsRequest(List.of())) | ||
); | ||
} | ||
|
||
@Test | ||
void shouldReturn422WhenRequestContainsListWithoutRequiredFields() { | ||
// when - then | ||
assertUnprocessableEntity( | ||
ApiException.class, | ||
() -> PRODUCT_PRICE_POINTS_CONTROLLER.createProductPricePoints( | ||
product.getId(), | ||
new BulkCreateProductPricePointsRequest(List.of( | ||
new CreateProductPricePoint(), | ||
new CreateProductPricePoint() | ||
)) | ||
), | ||
e -> assertThat(e.getHttpContext().getResponse().getBody()).isEqualTo("{\"price_points[0].interval\":[\"Recurring Interval: must be greater than or equal to 1.\"],\"price_points[0].interval_unit\":[\"Interval unit: cannot be blank.\",\"Interval unit: must be 'month' or 'day'.\"],\"price_points[0].name\":[\"Name: cannot be blank.\"],\"price_points[1].interval\":[\"Recurring Interval: must be greater than or equal to 1.\"],\"price_points[1].interval_unit\":[\"Interval unit: cannot be blank.\",\"Interval unit: must be 'month' or 'day'.\"],\"price_points[1].name\":[\"Name: cannot be blank.\"]}") | ||
); | ||
} | ||
} |
Oops, something went wrong.