Skip to content

Commit

Permalink
[DE-555] Product endpoints test (#32)
Browse files Browse the repository at this point in the history
* [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
maciej-nedza authored Nov 24, 2023
1 parent 07a8df4 commit c6f70c5
Show file tree
Hide file tree
Showing 17 changed files with 932 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<packaging>jar</packaging>
<name>AdvancedBillingTests</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxio.advancedbilling.controllers;
package com.maxio.advancedbilling.controllers.customers;

import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.CustomersController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.exceptions.CustomerErrorResponseException;
import com.maxio.advancedbilling.models.CreateCustomer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxio.advancedbilling.controllers;
package com.maxio.advancedbilling.controllers.customers;

import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.CustomersController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.CreateCustomer;
import com.maxio.advancedbilling.models.CreateCustomerRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxio.advancedbilling.controllers;
package com.maxio.advancedbilling.controllers.customers;

import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.CustomersController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.BasicDateField;
import com.maxio.advancedbilling.models.CreateCustomer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.maxio.advancedbilling.controllers;
package com.maxio.advancedbilling.controllers.customers;

import com.maxio.advancedbilling.AdvancedBillingClient;
import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.CustomersController;
import com.maxio.advancedbilling.controllers.PaymentProfilesController;
import com.maxio.advancedbilling.controllers.ProductFamiliesController;
import com.maxio.advancedbilling.controllers.ProductsController;
import com.maxio.advancedbilling.controllers.SubscriptionsController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.CreateCustomer;
import com.maxio.advancedbilling.models.CreateCustomerRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxio.advancedbilling.controllers;
package com.maxio.advancedbilling.controllers.customers;

import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.CustomersController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.CreateCustomer;
import com.maxio.advancedbilling.models.CreateCustomerRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxio.advancedbilling.controllers;
package com.maxio.advancedbilling.controllers.customers;

import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.CustomersController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.exceptions.CustomerErrorResponseException;
import com.maxio.advancedbilling.models.CreateCustomer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.maxio.advancedbilling.controllers;
package com.maxio.advancedbilling.controllers.productpricepoints;

import com.maxio.advancedbilling.AdvancedBillingClient;
import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.controllers.ProductFamiliesController;
import com.maxio.advancedbilling.controllers.ProductPricePointsController;
import com.maxio.advancedbilling.controllers.ProductsController;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.CreateOrUpdateProduct;
import com.maxio.advancedbilling.models.CreateOrUpdateProductRequest;
Expand Down
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));
}

}
Loading

0 comments on commit c6f70c5

Please sign in to comment.