-
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-718] DE-1045 SDK tests for reason and referral codes (#163)
* [DE-718] DE-1045 SDK tests for reason and referral codes * [DE-718] DE-1045 Fix error model in updateReasonCode and listReasonCodes
- Loading branch information
1 parent
20ee38b
commit 42b966b
Showing
11 changed files
with
556 additions
and
2 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
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
86 changes: 86 additions & 0 deletions
86
...va/com/maxio/advancedbilling/controllers/reasoncodes/ReasonCodesControllerCreateTest.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,86 @@ | ||
package com.maxio.advancedbilling.controllers.reasoncodes; | ||
|
||
import com.maxio.advancedbilling.TestClient; | ||
import com.maxio.advancedbilling.controllers.ReasonCodesController; | ||
import com.maxio.advancedbilling.exceptions.ApiException; | ||
import com.maxio.advancedbilling.models.CreateReasonCode; | ||
import com.maxio.advancedbilling.models.CreateReasonCodeRequest; | ||
import com.maxio.advancedbilling.models.ReasonCode; | ||
import com.maxio.advancedbilling.utils.TestFixtures; | ||
import com.maxio.advancedbilling.utils.TestTeardown; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.time.ZonedDateTime; | ||
|
||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertThatErrorListResponse; | ||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertUnauthorized; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ReasonCodesControllerCreateTest { | ||
private static final ReasonCodesController REASON_CODES_CONTROLLER = TestClient.createClient().getReasonCodesController(); | ||
|
||
@AfterAll | ||
static void deleteReasonCodes() throws IOException, ApiException { | ||
new TestTeardown().deleteReasonCodes(); | ||
} | ||
|
||
@Test | ||
void shouldCreateReasonCode() throws IOException, ApiException { | ||
// when | ||
ReasonCode response = REASON_CODES_CONTROLLER.createReasonCode(new CreateReasonCodeRequest(new CreateReasonCode( | ||
"NOT_INTERESTED", "I'm not interested in this product.", 1 | ||
))).getReasonCode(); | ||
|
||
// when | ||
assertThat(response.getId()).isNotNull(); | ||
assertThat(response.getSiteId()).isEqualTo(TestFixtures.SITE_ID); | ||
assertThat(response.getCode()).isEqualTo("NOT_INTERESTED"); | ||
assertThat(response.getPosition()).isEqualTo(1); | ||
assertThat(response.getDescription()).isEqualTo("I'm not interested in this product."); | ||
assertThat(response.getCreatedAt()) | ||
.isNotNull() | ||
.isBefore(ZonedDateTime.now()); | ||
assertThat(response.getUpdatedAt()) | ||
.isEqualTo(response.getCreatedAt()); | ||
|
||
ReasonCode readResponse = REASON_CODES_CONTROLLER.readReasonCode(response.getId()).getReasonCode(); | ||
assertThat(response) | ||
.usingRecursiveComparison() | ||
.isEqualTo(readResponse); | ||
} | ||
|
||
@Test | ||
void shouldThrowExceptionIfPropertyIsMissing() { | ||
// when - then | ||
assertThatErrorListResponse(() -> REASON_CODES_CONTROLLER.createReasonCode( | ||
new CreateReasonCodeRequest(new CreateReasonCode()))) | ||
.hasErrorCode(422) | ||
.hasErrors("Code: cannot be blank.", "Description: cannot be blank.") | ||
.hasMessage("HTTP Response Not OK. Status code: 422. " + | ||
"Response: '{errors:[Code: cannot be blank.,Description: cannot be blank.]}'."); | ||
} | ||
|
||
@Test | ||
void shouldThrowExceptionIfCodeExists() throws IOException, ApiException { | ||
// given | ||
CreateReasonCodeRequest request = new CreateReasonCodeRequest(new CreateReasonCode("existing", "existing", 1)); | ||
assertThat(REASON_CODES_CONTROLLER.createReasonCode(request).getReasonCode()).isNotNull(); | ||
|
||
// when - then | ||
assertThatErrorListResponse(() -> REASON_CODES_CONTROLLER.createReasonCode(request)) | ||
.hasErrorCode(422) | ||
.hasErrors("Code: This code is already in use.") | ||
.hasMessage("HTTP Response Not OK. Status code: 422. " + | ||
"Response: '{errors:[Code: This code is already in use.]}'."); | ||
} | ||
|
||
@Test | ||
void shouldThrowExceptionOnInvalidCredentials() { | ||
// when - then | ||
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getReasonCodesController() | ||
.createReasonCode(new CreateReasonCodeRequest(new CreateReasonCode("code", "desc", 1))) | ||
); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...va/com/maxio/advancedbilling/controllers/reasoncodes/ReasonCodesControllerDeleteTest.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,58 @@ | ||
package com.maxio.advancedbilling.controllers.reasoncodes; | ||
|
||
import com.maxio.advancedbilling.TestClient; | ||
import com.maxio.advancedbilling.controllers.ReasonCodesController; | ||
import com.maxio.advancedbilling.exceptions.ApiException; | ||
import com.maxio.advancedbilling.models.CreateReasonCode; | ||
import com.maxio.advancedbilling.models.CreateReasonCodeRequest; | ||
import com.maxio.advancedbilling.models.OkResponse; | ||
import com.maxio.advancedbilling.models.ReasonCode; | ||
import com.maxio.advancedbilling.utils.TestTeardown; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertNotFound; | ||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertUnauthorized; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ReasonCodesControllerDeleteTest { | ||
private static final ReasonCodesController REASON_CODES_CONTROLLER = TestClient.createClient().getReasonCodesController(); | ||
|
||
@AfterAll | ||
static void deleteReasonCodes() throws IOException, ApiException { | ||
new TestTeardown().deleteReasonCodes(); | ||
} | ||
|
||
@Test | ||
void shouldDeleteReasonCode() throws IOException, ApiException { | ||
// given | ||
ReasonCode createCodeResponse = REASON_CODES_CONTROLLER.createReasonCode(new CreateReasonCodeRequest(new CreateReasonCode( | ||
"NOT_INTERESTED", "I'm not interested in this product.", 1 | ||
))).getReasonCode(); | ||
ReasonCode readResponse = REASON_CODES_CONTROLLER.readReasonCode(createCodeResponse.getId()).getReasonCode(); | ||
assertThat(createCodeResponse) | ||
.usingRecursiveComparison() | ||
.isEqualTo(readResponse); | ||
|
||
// when | ||
OkResponse response = REASON_CODES_CONTROLLER.deleteReasonCode(createCodeResponse.getId()); | ||
assertThat(response.getOk()).isEqualTo("ok"); | ||
|
||
assertNotFound(() -> REASON_CODES_CONTROLLER.readReasonCode(createCodeResponse.getId())); | ||
} | ||
|
||
@Test | ||
void shouldThrowExceptionIfCodeDoesNotExists() { | ||
// when - then | ||
assertNotFound(() -> REASON_CODES_CONTROLLER.deleteReasonCode(1)); | ||
} | ||
|
||
@Test | ||
void shouldThrowExceptionOnInvalidCredentials() { | ||
// when - then | ||
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getReasonCodesController() | ||
.deleteReasonCode(1)); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
...java/com/maxio/advancedbilling/controllers/reasoncodes/ReasonCodesControllerListTest.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,109 @@ | ||
package com.maxio.advancedbilling.controllers.reasoncodes; | ||
|
||
import com.maxio.advancedbilling.TestClient; | ||
import com.maxio.advancedbilling.controllers.ReasonCodesController; | ||
import com.maxio.advancedbilling.exceptions.ApiException; | ||
import com.maxio.advancedbilling.models.CreateReasonCode; | ||
import com.maxio.advancedbilling.models.CreateReasonCodeRequest; | ||
import com.maxio.advancedbilling.models.ListReasonCodesInput; | ||
import com.maxio.advancedbilling.models.ReasonCodeResponse; | ||
import com.maxio.advancedbilling.utils.TestTeardown; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertThatErrorListResponse; | ||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertUnauthorized; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ReasonCodesControllerListTest { | ||
private static final ReasonCodesController REASON_CODES_CONTROLLER = TestClient.createClient().getReasonCodesController(); | ||
private static final List<ReasonCodeResponse> EXISTING_CODES = new ArrayList<>(); | ||
|
||
@BeforeEach | ||
void createReasonCodes() throws IOException, ApiException { | ||
new TestTeardown().deleteReasonCodes(); | ||
EXISTING_CODES.clear(); | ||
for (int i = 0; i < 10; ++i) { | ||
ReasonCodeResponse response = REASON_CODES_CONTROLLER.createReasonCode( | ||
new CreateReasonCodeRequest( | ||
new CreateReasonCode("CODE_" + i, "Description_" + i, i) | ||
)); | ||
EXISTING_CODES.add(response); | ||
} | ||
} | ||
|
||
@AfterEach | ||
void deleteReasonCodes() throws IOException, ApiException { | ||
new TestTeardown().deleteReasonCodes(); | ||
} | ||
|
||
@Test | ||
void shouldListAllReasonCodes() throws IOException, ApiException { | ||
// when | ||
List<ReasonCodeResponse> reasonCodeResponses = REASON_CODES_CONTROLLER.listReasonCodes(new ListReasonCodesInput()); | ||
|
||
// then | ||
assertThat(reasonCodeResponses) | ||
.hasSize(10) | ||
.usingRecursiveFieldByFieldElementComparator() | ||
.containsExactlyElementsOf(EXISTING_CODES); | ||
} | ||
|
||
@Test | ||
void shouldListReasonCodesWithPaging() throws IOException, ApiException { | ||
// when | ||
List<ReasonCodeResponse> firstPage = REASON_CODES_CONTROLLER.listReasonCodes(new ListReasonCodesInput(1, 2)); | ||
List<ReasonCodeResponse> secondPage = REASON_CODES_CONTROLLER.listReasonCodes(new ListReasonCodesInput(2, 2)); | ||
List<ReasonCodeResponse> bigPage = REASON_CODES_CONTROLLER.listReasonCodes(new ListReasonCodesInput(1, 8)); | ||
|
||
// then | ||
assertThat(firstPage) | ||
.hasSize(2) | ||
.usingRecursiveFieldByFieldElementComparator() | ||
.containsExactlyElementsOf(EXISTING_CODES.subList(0, 2)); | ||
assertThat(secondPage) | ||
.hasSize(2) | ||
.usingRecursiveFieldByFieldElementComparator() | ||
.containsExactlyElementsOf(EXISTING_CODES.subList(2, 4)); | ||
assertThat(bigPage) | ||
.hasSize(8) | ||
.usingRecursiveFieldByFieldElementComparator() | ||
.containsExactlyElementsOf(EXISTING_CODES.subList(0, 8)); | ||
} | ||
|
||
@Test | ||
void shouldReturnEmptyList() throws IOException, ApiException { | ||
// given | ||
new TestTeardown().deleteReasonCodes(); | ||
|
||
// when | ||
List<ReasonCodeResponse> reasonCodes = REASON_CODES_CONTROLLER.listReasonCodes(new ListReasonCodesInput()); | ||
|
||
// then | ||
assertThat(reasonCodes) | ||
.isNotNull() | ||
.isEmpty(); | ||
} | ||
|
||
@Test | ||
void shouldThrowExceptionIfPageIsInvalid() { | ||
// when - then | ||
assertThatErrorListResponse(() -> REASON_CODES_CONTROLLER.listReasonCodes( | ||
new ListReasonCodesInput(0, 2))) | ||
.hasErrorCode(422) | ||
.hasErrors("invalid page: 0") | ||
.hasMessage("HTTP Response Not OK. Status code: 422. Response: '{errors:[invalid page: 0]}'."); | ||
} | ||
|
||
@Test | ||
void shouldThrowExceptionOnInvalidCredentials() { | ||
// when - then | ||
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getReasonCodesController() | ||
.listReasonCodes(new ListReasonCodesInput())); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...java/com/maxio/advancedbilling/controllers/reasoncodes/ReasonCodesControllerReadTest.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,74 @@ | ||
package com.maxio.advancedbilling.controllers.reasoncodes; | ||
|
||
import com.maxio.advancedbilling.TestClient; | ||
import com.maxio.advancedbilling.controllers.ReasonCodesController; | ||
import com.maxio.advancedbilling.exceptions.ApiException; | ||
import com.maxio.advancedbilling.models.CreateReasonCode; | ||
import com.maxio.advancedbilling.models.CreateReasonCodeRequest; | ||
import com.maxio.advancedbilling.models.ReasonCode; | ||
import com.maxio.advancedbilling.utils.TestFixtures; | ||
import com.maxio.advancedbilling.utils.TestTeardown; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.time.ZonedDateTime; | ||
|
||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertNotFound; | ||
import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertUnauthorized; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ReasonCodesControllerReadTest { | ||
private static final ReasonCodesController REASON_CODES_CONTROLLER = TestClient.createClient().getReasonCodesController(); | ||
|
||
@AfterEach | ||
void deleteReasonCodes() throws IOException, ApiException { | ||
new TestTeardown().deleteReasonCodes(); | ||
} | ||
|
||
@Test | ||
void shouldReadReasonCode() throws IOException, ApiException { | ||
// given | ||
ReasonCode createResponse = REASON_CODES_CONTROLLER.createReasonCode(new CreateReasonCodeRequest(new CreateReasonCode( | ||
"NOT_INTERESTED", "I'm not interested in this product.", 1 | ||
))).getReasonCode(); | ||
|
||
// when | ||
ReasonCode response = REASON_CODES_CONTROLLER.readReasonCode(createResponse.getId()).getReasonCode(); | ||
|
||
// then | ||
assertThat(response.getId()).isNotNull(); | ||
assertThat(response.getSiteId()).isEqualTo(TestFixtures.SITE_ID); | ||
assertThat(response.getCode()).isEqualTo("NOT_INTERESTED"); | ||
assertThat(response.getPosition()).isEqualTo(1); | ||
assertThat(response.getDescription()).isEqualTo("I'm not interested in this product."); | ||
assertThat(response.getCreatedAt()) | ||
.isNotNull() | ||
.isBefore(ZonedDateTime.now()); | ||
assertThat(response.getUpdatedAt()) | ||
.isEqualTo(response.getCreatedAt()); | ||
|
||
ReasonCode readResponse = REASON_CODES_CONTROLLER.readReasonCode(response.getId()).getReasonCode(); | ||
assertThat(response) | ||
.usingRecursiveComparison() | ||
.isEqualTo(readResponse); | ||
} | ||
|
||
@Test | ||
void shouldThrowExceptionIfCodeDoesNotExist() { | ||
// when - then | ||
assertNotFound(() -> REASON_CODES_CONTROLLER.readReasonCode(1)); | ||
} | ||
|
||
@Test | ||
void shouldThrowExceptionOnInvalidCredentials() throws IOException, ApiException { | ||
// given | ||
ReasonCode createResponse = REASON_CODES_CONTROLLER.createReasonCode(new CreateReasonCodeRequest(new CreateReasonCode( | ||
"NOT_INTERESTED", "I'm not interested in this product.", 1 | ||
))).getReasonCode(); | ||
|
||
// when - then | ||
assertUnauthorized(() -> TestClient.createInvalidCredentialsClient().getReasonCodesController() | ||
.readReasonCode(createResponse.getId())); | ||
} | ||
} |
Oops, something went wrong.