Skip to content

Commit 6b40e5e

Browse files
authored
Update integration tests (#350)
1 parent 04723f7 commit 6b40e5e

17 files changed

+303
-192
lines changed

src/test/java/com/intercom/api/integration/AdminsTest.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ public class AdminsTest {
1818

1919
private Intercom client;
2020
private String adminId;
21+
private int adminIdInt;
2122

2223
@BeforeEach
2324
public void before() {
2425
// arrange
2526
client = TestClientFactory.create();
26-
adminId = client.admins().list().getAdmins().get(0).getId();
27+
adminId = client.admins().list().getAdmins()
28+
.orElseThrow(() -> new RuntimeException("Admins list is required"))
29+
.get(0)
30+
.orElseThrow(() -> new RuntimeException("Admin is required"))
31+
.getId();
32+
adminIdInt = Integer.parseInt(adminId);
2733
}
2834

2935
@Test
@@ -38,8 +44,9 @@ public void testList() {
3844
@Test
3945
public void testFind() {
4046
// act
41-
Admin response =
42-
client.admins().find(FindAdminRequest.builder().adminId(adminId).build());
47+
Admin response = client.admins()
48+
.find(FindAdminRequest.builder().adminId(adminIdInt).build())
49+
.orElseThrow(() -> new RuntimeException("Admin not found"));
4350

4451
// assert
4552
Assertions.assertNotNull(response);
@@ -69,10 +76,11 @@ public void testAwayOn() {
6976
// act
7077
Admin response = client.admins()
7178
.away(ConfigureAwayAdminRequest.builder()
72-
.adminId(adminId)
79+
.adminId(adminIdInt)
7380
.awayModeEnabled(true)
7481
.awayModeReassign(true)
75-
.build());
82+
.build())
83+
.orElseThrow(() -> new RuntimeException("Admin not found"));
7684

7785
// assert
7886
Assertions.assertNotNull(response);
@@ -83,10 +91,11 @@ public void testAwayOff() {
8391
// act
8492
Admin response = client.admins()
8593
.away(ConfigureAwayAdminRequest.builder()
86-
.adminId(adminId)
94+
.adminId(adminIdInt)
8795
.awayModeEnabled(false)
8896
.awayModeReassign(false)
89-
.build());
97+
.build())
98+
.orElseThrow(() -> new RuntimeException("Admin not found"));
9099

91100
// assert
92101
Assertions.assertNotNull(response);

src/test/java/com/intercom/api/integration/ArticlesTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.intercom.api.Intercom;
44
import com.intercom.api.core.pagination.SyncPagingIterable;
5-
import com.intercom.api.resources.articles.requests.CreateArticleRequest;
5+
import com.intercom.api.types.CreateArticleRequest;
66
import com.intercom.api.resources.articles.requests.DeleteArticleRequest;
77
import com.intercom.api.resources.articles.requests.FindArticleRequest;
88
import com.intercom.api.resources.articles.requests.ListArticlesRequest;
@@ -26,7 +26,7 @@ public class ArticlesTest {
2626

2727
private Intercom client;
2828
private Article article;
29-
private String articleId;
29+
private int articleId;
3030
private boolean deleteAfter;
3131

3232
@BeforeEach
@@ -39,11 +39,15 @@ public void before() {
3939
AdminList randomAdmins = client.admins().list();
4040

4141
Integer parentId = Integer.parseInt(randomCollections.getItems().get(0).getId());
42-
int adminId = Integer.parseInt(randomAdmins.getAdmins().get(0).getId());
42+
int adminId = Integer.parseInt(randomAdmins.getAdmins()
43+
.orElseThrow(() -> new RuntimeException("Admins list is required"))
44+
.get(0)
45+
.orElseThrow(() -> new RuntimeException("Admin is required"))
46+
.getId());
4347

4448
// act
4549
article = createArticle(parentId, adminId);
46-
articleId = article.getId();
50+
articleId = Integer.parseInt(article.getId());
4751

4852
deleteAfter = true;
4953
}
@@ -108,7 +112,7 @@ public void testDelete() {
108112

109113
private Article createArticle(Integer parentId, int adminId) {
110114
return client.articles()
111-
.create(CreateArticleRequest.builder()
115+
.create(java.util.Optional.of(CreateArticleRequest.builder()
112116
.title(Utils.randomString())
113117
.authorId(adminId)
114118
.description(Utils.randomString())
@@ -125,10 +129,10 @@ private Article createArticle(Integer parentId, int adminId) {
125129
.state(ArticleContent.State.DRAFT)
126130
.build())
127131
.build())
128-
.build());
132+
.build()));
129133
}
130134

131-
private void tryDeleteArticle(String articleId) {
135+
private void tryDeleteArticle(int articleId) {
132136
try {
133137
client.articles()
134138
.delete(DeleteArticleRequest.builder().articleId(articleId).build());

src/test/java/com/intercom/api/integration/CompaniesTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.intercom.api.core.pagination.SyncPage;
55
import com.intercom.api.core.pagination.SyncPagingIterable;
66
import com.intercom.api.resources.companies.requests.AttachContactToCompanyRequest;
7-
import com.intercom.api.resources.companies.requests.CreateOrUpdateCompanyRequest;
7+
import com.intercom.api.types.CreateOrUpdateCompanyRequest;
88
import com.intercom.api.resources.companies.requests.DeleteCompanyRequest;
99
import com.intercom.api.resources.companies.requests.DetachContactFromCompanyRequest;
1010
import com.intercom.api.resources.companies.requests.FindCompanyRequest;
@@ -42,9 +42,9 @@ public void before() {
4242
client.contacts().list(ListContactsRequest.builder().perPage(1).build());
4343

4444
// act
45-
contactId = randomContacts.getItems().get(0).getId();
45+
contactId = randomContacts.getItems().get(0).getId().orElseThrow(() -> new RuntimeException("Contact ID is required"));
4646
company = client.companies()
47-
.createOrUpdate(CreateOrUpdateCompanyRequest.builder()
47+
.createOrUpdate(java.util.Optional.of(CreateOrUpdateCompanyRequest.builder()
4848
.name(Utils.randomString())
4949
.companyId(Utils.randomString())
5050
.plan("1. Get pizzaid")
@@ -53,7 +53,7 @@ public void before() {
5353
.industry("The Best One")
5454
.remoteCreatedAt((int) (new Date().toInstant().toEpochMilli() / 1000L))
5555
.monthlySpend(9001)
56-
.build());
56+
.build()));
5757
companyId = company.getId();
5858

5959
deleteAfter = true;
@@ -77,7 +77,7 @@ public void testCreate() {
7777
public void testUpdate() {
7878
// act
7979
Company response = client.companies()
80-
.createOrUpdate(CreateOrUpdateCompanyRequest.builder()
80+
.createOrUpdate(java.util.Optional.of(CreateOrUpdateCompanyRequest.builder()
8181
.name(Utils.randomString())
8282
.companyId(Utils.randomString())
8383
.plan("1. Get pizzaid")
@@ -86,7 +86,7 @@ public void testUpdate() {
8686
.industry("The Best One")
8787
.remoteCreatedAt((int) (new Date().toInstant().toEpochMilli() / 1000L))
8888
.monthlySpend(9001)
89-
.build());
89+
.build()));
9090

9191
// assert
9292
Assertions.assertNotNull(response);
@@ -164,8 +164,6 @@ public void testListAttachedContacts() {
164164
CompanyAttachedContacts response = client.companies()
165165
.listAttachedContacts(ListAttachedContactsRequest.builder()
166166
.companyId(companyId)
167-
.page(1)
168-
.perPage(25)
169167
.build());
170168

171169
// assert

0 commit comments

Comments
 (0)