Skip to content

Commit

Permalink
[DE-619] Use product date fields in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-nedza committed Nov 27, 2023
1 parent 511397a commit eb2ee67
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

import static com.maxio.advancedbilling.utils.CommonAssertions.assertNotFound;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ProductsControllerArchiveProductTest extends ProductsControllerTestBase {

Expand All @@ -21,15 +23,15 @@ void shouldArchiveProduct() throws IOException, ApiException {
Product product = createProduct();

// when
String timestamp = Instant.now().toString();
ZonedDateTime timestamp = ZonedDateTime.now().minus(5, ChronoUnit.SECONDS);
productsController.archiveProduct(product.getId());

// then
Product archivedProduct = productsController.readProduct(product.getId()).getProduct();
assertAll(
() -> assertThat(archivedProduct.getId()).isEqualTo(product.getId()),
() -> assertThat(archivedProduct.getArchivedAt()).isNotNull(),
() -> assertThat(archivedProduct.getArchivedAt()).isAfterOrEqualTo(timestamp)
() -> assertTrue(archivedProduct.getArchivedAt().isAfter(timestamp))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.IOException;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.List;
Expand All @@ -28,7 +29,7 @@ public class ProductsControllerCreateProductTest extends ProductsControllerTestB
@Test
void shouldCreateProductWhenOnlyRequiredParametersAreProvided() throws IOException, ApiException {
// when
String timestamp = Instant.now().minus(5, ChronoUnit.SECONDS).toString();
ZonedDateTime timestamp = ZonedDateTime.now().minus(5, ChronoUnit.SECONDS);
String handle = "washington-" + RandomStringUtils.randomAlphanumeric(5).toLowerCase();
Product product = productsController
.createProduct(productFamily.getId(), new CreateOrUpdateProductRequest(
Expand Down Expand Up @@ -100,7 +101,7 @@ void shouldCreateProductWhenOnlyRequiredParametersAreProvided() throws IOExcepti
@Test
void shouldCreateProductWhenAllParametersAreProvided() throws IOException, ApiException {
// when
String timestamp = Instant.now().minus(5, ChronoUnit.SECONDS).toString();
ZonedDateTime timestamp = ZonedDateTime.now().minus(5, ChronoUnit.SECONDS);
String handle = "washington-" + RandomStringUtils.randomAlphanumeric(5).toLowerCase();
Product product = productsController
.createProduct(productFamily.getId(), new CreateOrUpdateProductRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -103,8 +104,8 @@ void shouldListProductsFilteringByEndDate() throws IOException, ApiException {
@Test
void shouldListProductsFilteringByStartDateTime() throws IOException, ApiException {
// given
LocalDateTime savedProductCreatedAt = savedProducts.get(0).getCreatedAt();
LocalDateTime startDateTimeFilterExcludeElements = savedProductCreatedAt.plusMinutes(5);
ZonedDateTime savedProductCreatedAt = savedProducts.get(0).getCreatedAt();
ZonedDateTime startDateTimeFilterExcludeElements = savedProductCreatedAt.plusMinutes(5);

// when
List<ProductResponse> productList1 = productsController.listProducts(
Expand All @@ -123,9 +124,9 @@ void shouldListProductsFilteringByStartDateTime() throws IOException, ApiExcepti
@Test
void shouldListProductsFilteringByEndDateTime() throws IOException, ApiException {
// given
LocalDateTime savedProductCreatedAt = savedProducts.get(0).getCreatedAt();
LocalDateTime endDateTimeFilterIncludeElements = savedProductCreatedAt.plusMinutes(5);
LocalDateTime endDateTimeFilterExcludeElements = savedProductCreatedAt.plusMinutes(-5);
ZonedDateTime savedProductCreatedAt = savedProducts.get(0).getCreatedAt();
ZonedDateTime endDateTimeFilterIncludeElements = savedProductCreatedAt.plusMinutes(5);
ZonedDateTime endDateTimeFilterExcludeElements = savedProductCreatedAt.plusMinutes(-5);

// when
List<ProductResponse> productList1 = productsController.listProducts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected Product createProduct() throws IOException, ApiException {
}

protected static Product createProductWithHandle(String handle) throws IOException, ApiException {
Product product = productsController
return productsController
.createProduct(productFamily.getId(), new CreateOrUpdateProductRequest(
new CreateOrUpdateProduct.Builder()
.name("Initial Sample product-" + RandomStringUtils.randomAlphanumeric(5))
Expand All @@ -48,7 +48,6 @@ protected static Product createProductWithHandle(String handle) throws IOExcepti
.build()
))
.getProduct();
return product;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.IOException;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.List;
Expand All @@ -28,7 +29,7 @@ public class ProductsControllerUpdateProductTest extends ProductsControllerTestB
@Test
void shouldUpdateProductWithAllParameters() throws IOException, ApiException {
// when
String timestamp = Instant.now().minus(5, ChronoUnit.SECONDS).toString();
ZonedDateTime timestamp = ZonedDateTime.now().minus(5, ChronoUnit.SECONDS);
Product product = createProduct();

Product updatedProduct = productsController.updateProduct(product.getId(), new CreateOrUpdateProductRequest(
Expand Down

0 comments on commit eb2ee67

Please sign in to comment.