-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCouponsControllerDeleteCouponSubcodesTest.java
More file actions
72 lines (60 loc) · 2.79 KB
/
CouponsControllerDeleteCouponSubcodesTest.java
File metadata and controls
72 lines (60 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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")
);
}
}