Skip to content

Commit

Permalink
[DE-526] Java test CRUD for customer endpoints (read) (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
patryk-grudzien-keen authored Nov 6, 2023
1 parent e8d33da commit 42b0a8d
Showing 1 changed file with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.maxio.advancedbilling.controllers;

import com.maxio.advancedbilling.TestClient;
import com.maxio.advancedbilling.exceptions.ApiException;
import com.maxio.advancedbilling.models.CreateCustomer;
import com.maxio.advancedbilling.models.CreateCustomerRequest;
import com.maxio.advancedbilling.models.Customer;
import com.maxio.advancedbilling.models.CustomerResponse;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

class CustomersControllerReadTest {

private static final CustomersController CUSTOMERS_CONTROLLER = TestClient.createClient().getCustomersController();

private static Customer TEST_CUSTOMER;

@BeforeAll
static void beforeAll() throws IOException, ApiException {
TEST_CUSTOMER = CUSTOMERS_CONTROLLER
.createCustomer(new CreateCustomerRequest()
.toBuilder()
.customer(new CreateCustomer()
.toBuilder()
.firstName("Cathryn")
.lastName("Washington")
.email("[email protected]")
.reference(RandomStringUtils.randomAlphanumeric(10))
.build()
)
.build()
)
.getCustomer();
}

@Test
void shouldReturnCustomerWhenReadByExistingChargifyID() throws IOException, ApiException {
// given
Integer chargifyId = TEST_CUSTOMER.getId();

// when
Customer customerReadByChargifyID = CUSTOMERS_CONTROLLER.readCustomer(chargifyId).getCustomer();

// then
assertCustomerAllProperties(customerReadByChargifyID);
}

@Test
void shouldReturnNullWhenReadByNotExistingChargifyID() throws IOException, ApiException {
// given
int notExistingChargifyId = 12345;

// when
CustomerResponse customerResponse = CUSTOMERS_CONTROLLER.readCustomer(notExistingChargifyId);

// then
assertThat(customerResponse).isNull();
}

@Test
void shouldReturnCustomerWhenReadByExistingReference() throws IOException, ApiException {
// given
String reference = TEST_CUSTOMER.getReference();

// when
Customer customerReadByReference = CUSTOMERS_CONTROLLER.readCustomerByReference(reference).getCustomer();

// then
assertCustomerAllProperties(customerReadByReference);
}

@Test
void shouldReturnNullWhenReadByNotExistingReference() throws IOException, ApiException {
// given
String notExistingReference = "not-existing-reference";

// when
CustomerResponse customerResponse = CUSTOMERS_CONTROLLER.readCustomerByReference(notExistingReference);

// then
assertThat(customerResponse).isNull();
}

private void assertCustomerAllProperties(Customer customer) {
assertAll(
() -> assertThat(customer.getFirstName()).isEqualTo("Cathryn"),
() -> assertThat(customer.getLastName()).isEqualTo("Washington"),
() -> assertThat(customer.getEmail()).isEqualTo("[email protected]"),

() -> assertThat(customer.getId()).isNotNull(),
() -> assertThat(customer.getCreatedAt()).isNotNull(),
() -> assertThat(customer.getUpdatedAt()).isNotNull(),

() -> assertThat(customer.getCcEmails()).isNull(),
() -> assertThat(customer.getOrganization()).isNull(),
() -> assertThat(customer.getReference()).isNotNull(),
() -> assertThat(customer.getAddress()).isNull(),
() -> assertThat(customer.getAddress2()).isNull(),
() -> assertThat(customer.getCity()).isNull(),
() -> assertThat(customer.getState()).isNull(),
() -> assertThat(customer.getStateName()).isNull(),
() -> assertThat(customer.getZip()).isNull(),
() -> assertThat(customer.getCountry()).isNull(),
() -> assertThat(customer.getCountryName()).isNull(),
() -> assertThat(customer.getPhone()).isNull(),
() -> assertThat(customer.getVerified()).isFalse(),
() -> assertThat(customer.getPortalCustomerCreatedAt()).isNull(),
() -> assertThat(customer.getPortalInviteLastSentAt()).isNull(),
() -> assertThat(customer.getPortalInviteLastAcceptedAt()).isNull(),
() -> assertThat(customer.getTaxExempt()).isFalse(),
() -> assertThat(customer.getVatNumber()).isNull(),
() -> assertThat(customer.getParentId()).isNull(),
() -> assertThat(customer.getLocale()).isNull(),
() -> assertThat(customer.getDefaultSubscriptionGroupUid()).isNull()
);
}
}

0 comments on commit 42b0a8d

Please sign in to comment.