-
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-555] Product endpoints test (#32)
* [DE-555] Tests for product endpoints * [DE-555] Product endpoints test fixes * [DE-555] Moved test packages * [DE-555] Product endpoints test fixes * [DE-555] Fix typo and use containsExactlyInAnyOrder * [DE-555] Review fixes * [DE-555] Code review suggestions
- Loading branch information
1 parent
07a8df4
commit c6f70c5
Showing
17 changed files
with
932 additions
and
10 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
3 changes: 2 additions & 1 deletion
3
...ollers/CustomersControllerCreateTest.java → ...tomers/CustomersControllerCreateTest.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
3 changes: 2 additions & 1 deletion
3
...ollers/CustomersControllerDeleteTest.java → ...tomers/CustomersControllerDeleteTest.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
3 changes: 2 additions & 1 deletion
3
...rs/CustomersControllerListOrFindTest.java → ...rs/CustomersControllerListOrFindTest.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
7 changes: 6 additions & 1 deletion
7
...omersControllerListSubscriptionsTest.java → ...omersControllerListSubscriptionsTest.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
3 changes: 2 additions & 1 deletion
3
...trollers/CustomersControllerReadTest.java → ...ustomers/CustomersControllerReadTest.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
3 changes: 2 additions & 1 deletion
3
...ollers/CustomersControllerUpdateTest.java → ...tomers/CustomersControllerUpdateTest.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
5 changes: 4 additions & 1 deletion
5
...ProductPricePointsControllerListTest.java → ...ProductPricePointsControllerListTest.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
62 changes: 62 additions & 0 deletions
62
.../com/maxio/advancedbilling/controllers/products/ProductsControllerArchiveProductTest.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,62 @@ | ||
package com.maxio.advancedbilling.controllers.products; | ||
|
||
import com.maxio.advancedbilling.exceptions.ApiException; | ||
import com.maxio.advancedbilling.exceptions.ErrorListResponseException; | ||
import com.maxio.advancedbilling.models.Product; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
|
||
import static com.maxio.advancedbilling.utils.CommonAssertions.assertNotFound; | ||
import static com.maxio.advancedbilling.utils.TimeUtils.parseStringTimestamp; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
public class ProductsControllerArchiveProductTest extends ProductsControllerTestBase { | ||
|
||
@Test | ||
void shouldArchiveProduct() throws IOException, ApiException { | ||
// given | ||
Product product = createProduct(); | ||
|
||
// when | ||
String timestamp = Instant.now().toString(); | ||
productsController.archiveProduct(product.getId()); | ||
|
||
// then | ||
Product archivedProduct = productsController.readProduct(product.getId()).getProduct(); | ||
assertAll( | ||
() -> assertThat(archivedProduct.getId()).isEqualTo(product.getId()), | ||
() -> assertThat(archivedProduct.getArchivedAt()).isNotNull(), | ||
() -> assertThat(parseStringTimestamp(archivedProduct.getArchivedAt())).isAfterOrEqualTo(timestamp) | ||
); | ||
} | ||
|
||
@Test | ||
void shouldNotArchiveSameProductTwice() throws IOException, ApiException { | ||
// given | ||
Product product = createProduct(); | ||
|
||
// when | ||
productsController.archiveProduct(product.getId()); | ||
|
||
// then | ||
assertThatExceptionOfType(ErrorListResponseException.class) | ||
.isThrownBy(() -> productsController.archiveProduct(product.getId()) | ||
) | ||
.withMessage("Unprocessable Entity (WebDAV)") | ||
.satisfies(e -> { | ||
assertThat(e.getResponseCode()).isEqualTo(422); | ||
assertThat(e.getErrors()).containsExactlyInAnyOrder("Product cannot be archived."); | ||
}); | ||
} | ||
|
||
@Test | ||
void shouldNotArchiveNotOwnedProduct() { | ||
// when-then | ||
assertNotFound(() -> productsController.archiveProduct(99999999)); | ||
} | ||
|
||
} |
Oops, something went wrong.