Skip to content

Commit fea92e0

Browse files
authored
Merge pull request #159 from ryannguyen16/update_referall_test
Update Partner Referral Retrieve All Function
2 parents 44b5e15 + 347cdeb commit fea92e0

File tree

4 files changed

+97
-52
lines changed

4 files changed

+97
-52
lines changed

src/main/java/com/easypost/model/beta/Referral.java renamed to src/main/java/com/easypost/model/beta/ReferralCustomer.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
import java.net.HttpURLConnection;
1616
import java.net.URL;
1717
import java.nio.charset.StandardCharsets;
18-
import java.util.Arrays;
1918
import java.util.HashMap;
2019
import java.util.List;
2120
import java.util.Map;
2221

23-
public class Referral extends BaseUser {
22+
public class ReferralCustomer extends BaseUser {
2423
private List<ApiKey> apiKeys;
2524

2625
/**
@@ -48,7 +47,7 @@ public void setApiKeys(List<ApiKey> apiKeys) {
4847
* @return Referral object.
4948
* @throws EasyPostException when the request fails.
5049
*/
51-
public static Referral create(Map<String, Object> params) throws EasyPostException {
50+
public static ReferralCustomer create(Map<String, Object> params) throws EasyPostException {
5251
return create(params, null);
5352
}
5453

@@ -60,12 +59,12 @@ public static Referral create(Map<String, Object> params) throws EasyPostExcepti
6059
* @return Referral object.
6160
* @throws EasyPostException when the request fails.
6261
*/
63-
public static Referral create(Map<String, Object> params, String apiKey) throws EasyPostException {
62+
public static ReferralCustomer create(Map<String, Object> params, String apiKey) throws EasyPostException {
6463
Map<String, Object> wrappedParams = new HashMap<>();
6564
wrappedParams.put("user", params);
6665

6766
return request(RequestMethod.POST, String.format("%s/%s", EasyPost.BETA_API_BASE, "referral_customers"),
68-
wrappedParams, Referral.class, apiKey);
67+
wrappedParams, ReferralCustomer.class, apiKey);
6968
}
7069

7170
/**
@@ -96,7 +95,7 @@ public static boolean updateEmail(String email, String userId, String apiKey) th
9695
wrappedParams.put("user", params);
9796

9897
request(RequestMethod.PUT, String.format("%s/%s/%s", EasyPost.BETA_API_BASE, "referral_customers", userId),
99-
wrappedParams, Referral.class, apiKey);
98+
wrappedParams, ReferralCustomer.class, apiKey);
10099

101100
return true;
102101
}
@@ -108,7 +107,7 @@ public static boolean updateEmail(String email, String userId, String apiKey) th
108107
* @return List<Referral> object.
109108
* @throws EasyPostException when the request fails.
110109
*/
111-
public static List<Referral> all(final Map<String, Object> params) throws EasyPostException {
110+
public static ReferralCustomerCollection all(final Map<String, Object> params) throws EasyPostException {
112111
return all(params, null);
113112
}
114113

@@ -117,15 +116,13 @@ public static List<Referral> all(final Map<String, Object> params) throws EasyPo
117116
*
118117
* @param params Map of parameters.
119118
* @param apiKey API key to use in request (overrides default API key).
120-
* @return List<Referral> object.
119+
* @return ReferralCustomerCollection object.
121120
* @throws EasyPostException when the request fails.
122121
*/
123-
public static List<Referral> all(final Map<String, Object> params, String apiKey) throws EasyPostException {
124-
Referral[] response =
125-
request(RequestMethod.GET, String.format("%s/%s", EasyPost.BETA_API_BASE, "referral_customers"), params,
126-
Referral[].class, apiKey);
127-
128-
return Arrays.asList(response);
122+
public static ReferralCustomerCollection all(final Map<String, Object> params, String apiKey)
123+
throws EasyPostException {
124+
return request(RequestMethod.GET, String.format("%s/%s", EasyPost.BETA_API_BASE, "referral_customers"),
125+
params, ReferralCustomerCollection.class, apiKey);
129126
}
130127

131128
/**
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.easypost.model.beta;
2+
3+
import com.easypost.net.EasyPostResource;
4+
5+
import java.util.List;
6+
7+
public final class ReferralCustomerCollection extends EasyPostResource {
8+
private List<ReferralCustomer> referralCustomers;
9+
private boolean hasMore;
10+
11+
/**
12+
* Get a list of ReferralCustomers.
13+
*
14+
* @return List of ReferralCustomers objects
15+
*/
16+
public List<ReferralCustomer> getReferralCustomers() {
17+
return referralCustomers;
18+
}
19+
20+
/**
21+
* Set a list of ReferralCustomers.
22+
*
23+
* @param referralCustomers List of ReferralCustomers objects
24+
*/
25+
public void setReferralCustomers(final List<ReferralCustomer> referralCustomers) {
26+
this.referralCustomers = referralCustomers;
27+
}
28+
29+
/**
30+
* Get whether there are more ReferralCustomers to retrieve.
31+
*
32+
* @return whether there are more ReferralCustomers to retrieve
33+
*/
34+
public boolean getHasMore() {
35+
return hasMore;
36+
}
37+
38+
/**
39+
* Set whether there are more ReferralCustomers to retrieve.
40+
*
41+
* @param hasMore Boolean whether there are more ReferralCustomers to retrieve
42+
*/
43+
public void setHasMore(final boolean hasMore) {
44+
this.hasMore = hasMore;
45+
}
46+
}

src/test/cassettes/referral/all.json

Lines changed: 22 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/java/com/easypost/beta/ReferralTest.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import com.easypost.exception.EasyPostException;
66
import com.easypost.model.PaymentMethod;
77
import com.easypost.model.PaymentMethodObject;
8-
import com.easypost.model.beta.Referral;
8+
import com.easypost.model.beta.ReferralCustomer;
9+
import com.easypost.model.beta.ReferralCustomerCollection;
10+
911
import org.junit.jupiter.api.BeforeAll;
1012
import org.junit.jupiter.api.Disabled;
1113
import org.junit.jupiter.api.Test;
@@ -16,6 +18,7 @@
1618

1719
import static org.junit.jupiter.api.Assertions.assertEquals;
1820
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1922
import static org.junit.jupiter.api.Assertions.assertTrue;
2023

2124
public final class ReferralTest {
@@ -42,9 +45,9 @@ public static void setup() throws EasyPostException {
4245
public void testCreate() throws EasyPostException {
4346
vcr.setUpTest("create");
4447

45-
Referral referralUser = createReferral();
48+
ReferralCustomer referralUser = createReferral();
4649

47-
assertInstanceOf(Referral.class, referralUser);
50+
assertInstanceOf(ReferralCustomer.class, referralUser);
4851
assertTrue(referralUser.getId().startsWith("user_"));
4952
assertEquals(Fixture.referralUser().get("name"), referralUser.getName());
5053
}
@@ -54,8 +57,8 @@ public void testCreate() throws EasyPostException {
5457
*
5558
* @return Referral object
5659
*/
57-
private static Referral createReferral() throws EasyPostException {
58-
return Referral.create(Fixture.referralUser());
60+
private static ReferralCustomer createReferral() throws EasyPostException {
61+
return ReferralCustomer.create(Fixture.referralUser());
5962
}
6063

6164
/**
@@ -67,8 +70,8 @@ private static Referral createReferral() throws EasyPostException {
6770
public void testUpdate() throws EasyPostException {
6871
vcr.setUpTest("update");
6972

70-
Referral referralUser = createReferral();
71-
boolean response = Referral.updateEmail("[email protected]", referralUser.getId());
73+
ReferralCustomer referralUser = createReferral();
74+
boolean response = ReferralCustomer.updateEmail("[email protected]", referralUser.getId());
7275

7376
assertTrue(response);
7477
}
@@ -82,13 +85,16 @@ public void testUpdate() throws EasyPostException {
8285
public void testAll() throws EasyPostException {
8386
vcr.setUpTest("all");
8487

85-
Map<String, Object> params = new HashMap<>();
88+
Map<String, Object> params = new HashMap<String, Object>();
8689
params.put("page_size", Fixture.pageSize());
8790

88-
List<Referral> referralUsers = Referral.all(params);
91+
ReferralCustomerCollection referallCustomorCollection = ReferralCustomer.all(params);
92+
93+
List<ReferralCustomer> referallUsers = referallCustomorCollection.getReferralCustomers();
8994

90-
assertTrue(referralUsers.size() <= Fixture.pageSize());
91-
assertTrue(referralUsers.stream().allMatch(referral -> referral instanceof Referral));
95+
assertTrue(referallUsers.size() <= Fixture.pageSize());
96+
assertNotNull(referallCustomorCollection.getHasMore());
97+
assertTrue(referallUsers.stream().allMatch(referral -> referral instanceof ReferralCustomer));
9298
}
9399

94100
/**
@@ -103,7 +109,7 @@ public void testReferralAddCreditCard() throws Exception {
103109

104110
Map<String, String> creditCardDetails = Fixture.creditCardDetails();
105111
PaymentMethodObject creditCard =
106-
Referral.addCreditCardToUser(REFERRAL_USER_PROD_API_KEY, creditCardDetails.get("number"),
112+
ReferralCustomer.addCreditCardToUser(REFERRAL_USER_PROD_API_KEY, creditCardDetails.get("number"),
107113
Integer.parseInt(creditCardDetails.get("expiration_month")),
108114
Integer.parseInt(creditCardDetails.get("expiration_year")), creditCardDetails.get("cvc"),
109115
PaymentMethod.Priority.PRIMARY);

0 commit comments

Comments
 (0)