-
Notifications
You must be signed in to change notification settings - Fork 0
[DE-1072] Test coupon subcodes and coupon misc #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
49acf73
[DE-610] Create component price points tests
maciej-nedza 64da7a4
Automated commit message
maxio-sdk 457f5b9
Merge branch 'publish' of github.com:maxio-com/ab-java-sdk into creat…
maciej-nedza c017ec3
[DE-1072] Test for coupons subcodes and misc
maciej-nedza d04d3fe
Merge branch 'main' of github.com:maxio-com/ab-java-sdk into create-c…
maciej-nedza 80bdcd1
Merge branch 'main' into create-components-price-points-tests
patryk-grudzien-keen 23fae78
[DE-1072] Review suggestions
maciej-nedza f7aef57
Merge branch 'create-components-price-points-tests' of github.com:max…
maciej-nedza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
.../maxio/advancedbilling/controllers/coupons/CouponsControllerCouponCurrencyPricesTest.java
This file contains hidden or 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,101 @@ | ||
| package com.maxio.advancedbilling.controllers.coupons; | ||
|
|
||
| import com.maxio.advancedbilling.TestClientProvider; | ||
| import com.maxio.advancedbilling.exceptions.ApiException; | ||
| import com.maxio.advancedbilling.models.Coupon; | ||
| import com.maxio.advancedbilling.models.CouponCurrency; | ||
| import com.maxio.advancedbilling.models.CouponCurrencyRequest; | ||
| import com.maxio.advancedbilling.models.UpdateCouponCurrency; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertNotFound; | ||
| import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertThatErrorStringMapResponse; | ||
| import static com.maxio.advancedbilling.utils.assertions.CommonAssertions.assertUnauthorized; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class CouponsControllerCouponCurrencyPricesTest extends CouponsControllerTestBase { | ||
|
|
||
| private Coupon coupon; | ||
|
|
||
| @BeforeAll | ||
| void setupResources() throws IOException, ApiException { | ||
| coupon = COUPONS_CONTROLLER.createCoupon(productFamilyId, validCouponRequest()).getCoupon(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldCreateAndUpdateCouponCurrencyPrices() throws IOException, ApiException { | ||
| // when | ||
| List<CouponCurrency> currencyPrices = COUPONS_CONTROLLER | ||
| .createOrUpdateCouponCurrencyPrices(coupon.getId(), new CouponCurrencyRequest( | ||
| List.of( | ||
| new UpdateCouponCurrency("USD", 15), | ||
| new UpdateCouponCurrency("EUR", 333) | ||
| ) | ||
| ) | ||
| ).getCurrencyPrices(); | ||
|
|
||
| // then | ||
| assertThat(currencyPrices).hasSize(2); | ||
| assertThat(currencyPrices.get(0).getId()).isNotNull(); | ||
| assertThat(currencyPrices.get(0).getCurrency()).isEqualTo("USD"); | ||
| assertThat(currencyPrices.get(0).getPrice()).isEqualTo(15.0); | ||
| assertThat(currencyPrices.get(0).getCouponId()).isEqualTo(coupon.getId()); | ||
| assertThat(currencyPrices.get(1).getId()).isNotNull(); | ||
| assertThat(currencyPrices.get(1).getCurrency()).isEqualTo("EUR"); | ||
| assertThat(currencyPrices.get(1).getPrice()).isEqualTo(333.0); | ||
| assertThat(currencyPrices.get(1).getCouponId()).isEqualTo(coupon.getId()); | ||
|
|
||
| // then update | ||
| List<CouponCurrency> currencyPrices2 = COUPONS_CONTROLLER | ||
| .createOrUpdateCouponCurrencyPrices(coupon.getId(), new CouponCurrencyRequest( | ||
| List.of( | ||
| new UpdateCouponCurrency("USD", 1), | ||
| new UpdateCouponCurrency("EUR", 2) | ||
| ) | ||
| ) | ||
| ).getCurrencyPrices(); | ||
|
|
||
| // then | ||
| assertThat(currencyPrices2.get(0).getId()).isEqualTo(currencyPrices.get(0).getId()); | ||
| assertThat(currencyPrices2.get(0).getCurrency()).isEqualTo("USD"); | ||
| assertThat(currencyPrices2.get(0).getPrice()).isEqualTo(1.0); | ||
| assertThat(currencyPrices2.get(0).getCouponId()).isEqualTo(coupon.getId()); | ||
| assertThat(currencyPrices2.get(1).getId()).isEqualTo(currencyPrices.get(1).getId()); | ||
| assertThat(currencyPrices2.get(1).getCurrency()).isEqualTo("EUR"); | ||
| assertThat(currencyPrices2.get(1).getPrice()).isEqualTo(2.0); | ||
| assertThat(currencyPrices2.get(1).getCouponId()).isEqualTo(coupon.getId()); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotCreateCurrencyPricesWithInvalidData() throws IOException, ApiException { | ||
| Coupon coupon2 = TEST_SETUP.createPercentageCoupon(productFamily, "2"); | ||
| assertThatErrorStringMapResponse(() -> COUPONS_CONTROLLER.createOrUpdateCouponCurrencyPrices(coupon2.getId(), | ||
| new CouponCurrencyRequest(List.of(new UpdateCouponCurrency("PLN", -10))))) | ||
| .hasErrorMap( | ||
| Map.of( | ||
| "PLN.currency", "Currency must be defined on the site level.", | ||
| "PLN.price", "Amount: must be greater than or equal to 0,00 zł.", | ||
| "coupon", "Cannot create prices for a percentage-based coupon." | ||
| )) | ||
| .isUnprocessableEntity(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotCreateCurrencyPricesForNonExistentCoupon() { | ||
| assertNotFound(() -> COUPONS_CONTROLLER.createOrUpdateCouponCurrencyPrices(123, | ||
| new CouponCurrencyRequest())); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotCreateCurrencyPricesWhenProvidingInvalidCredentials() { | ||
| assertUnauthorized(() -> TestClientProvider.createInvalidCredentialsClient() | ||
| .getCouponsController().createOrUpdateCouponCurrencyPrices(coupon.getId(), new CouponCurrencyRequest()) | ||
| ); | ||
| } | ||
|
|
||
| } | ||
67 changes: 67 additions & 0 deletions
67
.../maxio/advancedbilling/controllers/coupons/CouponsControllerCreateCouponSubcodesTest.java
This file contains hidden or 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,67 @@ | ||
| package com.maxio.advancedbilling.controllers.coupons; | ||
|
|
||
| import com.maxio.advancedbilling.TestClientProvider; | ||
| import com.maxio.advancedbilling.exceptions.ApiException; | ||
| import com.maxio.advancedbilling.models.Coupon; | ||
| import com.maxio.advancedbilling.models.CouponSubcodes; | ||
| import com.maxio.advancedbilling.models.CouponSubcodesResponse; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| 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 CouponsControllerCreateCouponSubcodesTest extends CouponsControllerTestBase { | ||
|
|
||
| private Coupon coupon; | ||
|
|
||
| @BeforeAll | ||
| void setupResources() throws IOException, ApiException { | ||
| coupon = COUPONS_CONTROLLER.createCoupon(productFamilyId, validCouponRequest()).getCoupon(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldCreateCouponSubcodes() throws IOException, ApiException { | ||
| // when | ||
| CouponSubcodesResponse response = COUPONS_CONTROLLER | ||
| .createCouponSubcodes(coupon.getId(), new CouponSubcodes( | ||
| List.of("ABC", "CcC123", "pppppP", "DD", "25%OFF", "ALLOWED%@+-_.", | ||
| "abc", "DD", | ||
| "NOTALLOWED$#?!", " ", "abc c", "") | ||
| )); | ||
|
|
||
| // then | ||
| assertThat(response.getCreatedCodes()) | ||
| .containsExactlyInAnyOrder("ABC", "CCC123", "PPPPPP", "DD", "25%OFF", "ALLOWED%@+-_."); | ||
| assertThat(response.getDuplicateCodes()).isEmpty(); | ||
| assertThat(response.getInvalidCodes()) | ||
| .containsExactlyInAnyOrder("NOTALLOWED$#?!", "ABC C"); | ||
|
|
||
| // when saving some duplicates | ||
| response = COUPONS_CONTROLLER | ||
| .createCouponSubcodes(coupon.getId(), new CouponSubcodes( | ||
| List.of("NEWONE", "abc", "DD"))); | ||
|
|
||
| assertThat(response.getCreatedCodes()).containsExactlyInAnyOrder("NEWONE"); | ||
| assertThat(response.getDuplicateCodes()).containsExactlyInAnyOrder("ABC", "DD"); | ||
| assertThat(response.getInvalidCodes()).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotCreateSubcodesForNonExistentCoupon() { | ||
| assertNotFound(() -> COUPONS_CONTROLLER.createCouponSubcodes(123, | ||
| new CouponSubcodes(List.of("abc")))); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotCreateCouponSubcodesWhenProvidingInvalidCredentials() { | ||
| assertUnauthorized(() -> TestClientProvider.createInvalidCredentialsClient() | ||
| .getCouponsController().createCouponSubcodes(coupon.getId(), new CouponSubcodes(List.of("abc"))) | ||
| ); | ||
| } | ||
|
|
||
| } |
72 changes: 72 additions & 0 deletions
72
.../maxio/advancedbilling/controllers/coupons/CouponsControllerDeleteCouponSubcodesTest.java
This file contains hidden or 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,72 @@ | ||
| package com.maxio.advancedbilling.controllers.coupons; | ||
|
|
||
| import com.maxio.advancedbilling.TestClientProvider; | ||
| import com.maxio.advancedbilling.exceptions.ApiException; | ||
| import com.maxio.advancedbilling.models.Coupon; | ||
| import com.maxio.advancedbilling.models.CouponSubcodes; | ||
| import com.maxio.advancedbilling.models.CouponSubcodesResponse; | ||
| import com.maxio.advancedbilling.models.ListCouponSubcodesInput; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| 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 CouponsControllerDeleteCouponSubcodesTest extends CouponsControllerTestBase { | ||
|
|
||
| private Coupon coupon; | ||
|
|
||
| @BeforeAll | ||
| void setupResources() throws IOException, ApiException { | ||
| coupon = COUPONS_CONTROLLER.createCoupon(productFamilyId, validCouponRequest()).getCoupon(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldDeleteCouponSubcodes() throws IOException, ApiException { | ||
| // create subcodes then delete one | ||
| CouponSubcodesResponse response = COUPONS_CONTROLLER | ||
| .createCouponSubcodes(coupon.getId(), new CouponSubcodes( | ||
| // Unfortunately deleting coupon with . (dot) won't work with sdk | ||
| List.of("ABC", "ALLOWED%@+-_") | ||
| )); | ||
| COUPONS_CONTROLLER.deleteCouponSubcode(coupon.getId(), "abc"); | ||
| List<String> codes = COUPONS_CONTROLLER | ||
| .listCouponSubcodes(new ListCouponSubcodesInput.Builder() | ||
| .couponId(coupon.getId()) | ||
| .build() | ||
| ).getCodes(); | ||
| assertThat(codes).hasSize(1); | ||
| assertThat(codes.get(0)).isEqualTo("ALLOWED%@+-_"); | ||
|
|
||
| // delete second one | ||
| COUPONS_CONTROLLER.deleteCouponSubcode(coupon.getId(), "ALLOWED%@+-_"); | ||
| codes = COUPONS_CONTROLLER | ||
| .listCouponSubcodes(new ListCouponSubcodesInput.Builder() | ||
| .couponId(coupon.getId()) | ||
| .build() | ||
| ).getCodes(); | ||
| assertThat(codes).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotDeleteNonExistentSubcode() { | ||
| assertNotFound(() -> COUPONS_CONTROLLER.deleteCouponSubcode(coupon.getId(), "xxx")); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotDeleteSubcodesForNonExistentCoupon() { | ||
| assertNotFound(() -> COUPONS_CONTROLLER.deleteCouponSubcode(123, "abc")); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotDeleteSubcodeWhenProvidingInvalidCredentials() { | ||
| assertUnauthorized(() -> TestClientProvider.createInvalidCredentialsClient() | ||
| .getCouponsController().deleteCouponSubcode(coupon.getId(), "abc") | ||
| ); | ||
| } | ||
|
|
||
| } |
96 changes: 96 additions & 0 deletions
96
...om/maxio/advancedbilling/controllers/coupons/CouponsControllerListCouponSubcodesTest.java
This file contains hidden or 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,96 @@ | ||
| package com.maxio.advancedbilling.controllers.coupons; | ||
|
|
||
| import com.maxio.advancedbilling.TestClientProvider; | ||
| import com.maxio.advancedbilling.exceptions.ApiException; | ||
| import com.maxio.advancedbilling.models.Coupon; | ||
| import com.maxio.advancedbilling.models.CouponSubcodes; | ||
| import com.maxio.advancedbilling.models.ListCouponSubcodesInput; | ||
| import org.apache.commons.lang3.RandomStringUtils; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Stream; | ||
|
|
||
| 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 CouponsControllerListCouponSubcodesTest extends CouponsControllerTestBase { | ||
|
|
||
| private Coupon coupon; | ||
| private List<String> subcodes; | ||
|
|
||
| @BeforeAll | ||
| void setupResources() throws IOException, ApiException { | ||
| coupon = COUPONS_CONTROLLER.createCoupon(productFamilyId, validCouponRequest()).getCoupon(); | ||
|
|
||
| List<String> list = new ArrayList<>(); | ||
| for (int i = 0; i < 10; i++) { | ||
| list.add(RandomStringUtils.randomAlphanumeric(5) + i); | ||
| } | ||
|
|
||
| subcodes = COUPONS_CONTROLLER | ||
| .createCouponSubcodes(coupon.getId(), new CouponSubcodes(list)).getCreatedCodes(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldListCouponSubcodes() throws IOException, ApiException { | ||
| List<String> codes = COUPONS_CONTROLLER | ||
| .listCouponSubcodes(new ListCouponSubcodesInput.Builder() | ||
| .couponId(coupon.getId()) | ||
| .build() | ||
| ).getCodes(); | ||
| assertThat(codes).containsExactlyInAnyOrderElementsOf(subcodes); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldListCouponSubcodesWithPaging() throws IOException, ApiException { | ||
| // given | ||
| List<String> page1 = COUPONS_CONTROLLER | ||
| .listCouponSubcodes(new ListCouponSubcodesInput.Builder() | ||
| .couponId(coupon.getId()) | ||
| .page(1) | ||
| .perPage(4) | ||
| .build() | ||
| ).getCodes(); | ||
| List<String> page2 = COUPONS_CONTROLLER | ||
| .listCouponSubcodes(new ListCouponSubcodesInput.Builder() | ||
| .couponId(coupon.getId()) | ||
| .page(2) | ||
| .perPage(4) | ||
| .build() | ||
| ).getCodes(); | ||
| List<String> page3 = COUPONS_CONTROLLER | ||
| .listCouponSubcodes(new ListCouponSubcodesInput.Builder() | ||
| .couponId(coupon.getId()) | ||
| .page(3) | ||
| .perPage(4) | ||
| .build() | ||
| ).getCodes(); | ||
|
|
||
| // then | ||
| assertThat(page1).hasSize(4); | ||
| assertThat(page2).hasSize(4); | ||
| assertThat(page3).hasSize(2); | ||
|
|
||
| assertThat( | ||
| Stream.concat(Stream.concat(page1.stream(), page2.stream()), page3.stream()).toList() | ||
| ).containsExactlyInAnyOrderElementsOf(subcodes); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotListSubcodesForNonExistentCoupon() { | ||
| assertNotFound(() -> COUPONS_CONTROLLER | ||
| .listCouponSubcodes(new ListCouponSubcodesInput(123, 1, 1))); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotListCouponSubcodesWhenProvidingInvalidCredentials() { | ||
| assertUnauthorized(() -> TestClientProvider.createInvalidCredentialsClient() | ||
| .getCouponsController().listCouponSubcodes(new ListCouponSubcodesInput(coupon.getId(), 1, 1))); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.