Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/test/java/com/intercom/api/integration/AdminsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ public class AdminsTest {

private Intercom client;
private String adminId;
private int adminIdInt;

@BeforeEach
public void before() {
// arrange
client = TestClientFactory.create();
adminId = client.admins().list().getAdmins().get(0).getId();
adminId = client.admins().list().getAdmins()
.orElseThrow(() -> new RuntimeException("Admins list is required"))
.get(0)
.orElseThrow(() -> new RuntimeException("Admin is required"))
.getId();
adminIdInt = Integer.parseInt(adminId);
}

@Test
Expand All @@ -38,8 +44,9 @@ public void testList() {
@Test
public void testFind() {
// act
Admin response =
client.admins().find(FindAdminRequest.builder().adminId(adminId).build());
Admin response = client.admins()
.find(FindAdminRequest.builder().adminId(adminIdInt).build())
.orElseThrow(() -> new RuntimeException("Admin not found"));

// assert
Assertions.assertNotNull(response);
Expand Down Expand Up @@ -69,10 +76,11 @@ public void testAwayOn() {
// act
Admin response = client.admins()
.away(ConfigureAwayAdminRequest.builder()
.adminId(adminId)
.adminId(adminIdInt)
.awayModeEnabled(true)
.awayModeReassign(true)
.build());
.build())
.orElseThrow(() -> new RuntimeException("Admin not found"));

// assert
Assertions.assertNotNull(response);
Expand All @@ -83,10 +91,11 @@ public void testAwayOff() {
// act
Admin response = client.admins()
.away(ConfigureAwayAdminRequest.builder()
.adminId(adminId)
.adminId(adminIdInt)
.awayModeEnabled(false)
.awayModeReassign(false)
.build());
.build())
.orElseThrow(() -> new RuntimeException("Admin not found"));

// assert
Assertions.assertNotNull(response);
Expand Down
18 changes: 11 additions & 7 deletions src/test/java/com/intercom/api/integration/ArticlesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.intercom.api.Intercom;
import com.intercom.api.core.pagination.SyncPagingIterable;
import com.intercom.api.resources.articles.requests.CreateArticleRequest;
import com.intercom.api.types.CreateArticleRequest;
import com.intercom.api.resources.articles.requests.DeleteArticleRequest;
import com.intercom.api.resources.articles.requests.FindArticleRequest;
import com.intercom.api.resources.articles.requests.ListArticlesRequest;
Expand All @@ -26,7 +26,7 @@ public class ArticlesTest {

private Intercom client;
private Article article;
private String articleId;
private int articleId;
private boolean deleteAfter;

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

Integer parentId = Integer.parseInt(randomCollections.getItems().get(0).getId());
int adminId = Integer.parseInt(randomAdmins.getAdmins().get(0).getId());
int adminId = Integer.parseInt(randomAdmins.getAdmins()
.orElseThrow(() -> new RuntimeException("Admins list is required"))
.get(0)
.orElseThrow(() -> new RuntimeException("Admin is required"))
.getId());

// act
article = createArticle(parentId, adminId);
articleId = article.getId();
articleId = Integer.parseInt(article.getId());

deleteAfter = true;
}
Expand Down Expand Up @@ -108,7 +112,7 @@ public void testDelete() {

private Article createArticle(Integer parentId, int adminId) {
return client.articles()
.create(CreateArticleRequest.builder()
.create(java.util.Optional.of(CreateArticleRequest.builder()
.title(Utils.randomString())
.authorId(adminId)
.description(Utils.randomString())
Expand All @@ -125,10 +129,10 @@ private Article createArticle(Integer parentId, int adminId) {
.state(ArticleContent.State.DRAFT)
.build())
.build())
.build());
.build()));
}

private void tryDeleteArticle(String articleId) {
private void tryDeleteArticle(int articleId) {
try {
client.articles()
.delete(DeleteArticleRequest.builder().articleId(articleId).build());
Expand Down
14 changes: 6 additions & 8 deletions src/test/java/com/intercom/api/integration/CompaniesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.intercom.api.core.pagination.SyncPage;
import com.intercom.api.core.pagination.SyncPagingIterable;
import com.intercom.api.resources.companies.requests.AttachContactToCompanyRequest;
import com.intercom.api.resources.companies.requests.CreateOrUpdateCompanyRequest;
import com.intercom.api.types.CreateOrUpdateCompanyRequest;
import com.intercom.api.resources.companies.requests.DeleteCompanyRequest;
import com.intercom.api.resources.companies.requests.DetachContactFromCompanyRequest;
import com.intercom.api.resources.companies.requests.FindCompanyRequest;
Expand Down Expand Up @@ -42,9 +42,9 @@ public void before() {
client.contacts().list(ListContactsRequest.builder().perPage(1).build());

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

deleteAfter = true;
Expand All @@ -77,7 +77,7 @@ public void testCreate() {
public void testUpdate() {
// act
Company response = client.companies()
.createOrUpdate(CreateOrUpdateCompanyRequest.builder()
.createOrUpdate(java.util.Optional.of(CreateOrUpdateCompanyRequest.builder()
.name(Utils.randomString())
.companyId(Utils.randomString())
.plan("1. Get pizzaid")
Expand All @@ -86,7 +86,7 @@ public void testUpdate() {
.industry("The Best One")
.remoteCreatedAt((int) (new Date().toInstant().toEpochMilli() / 1000L))
.monthlySpend(9001)
.build());
.build()));

// assert
Assertions.assertNotNull(response);
Expand Down Expand Up @@ -164,8 +164,6 @@ public void testListAttachedContacts() {
CompanyAttachedContacts response = client.companies()
.listAttachedContacts(ListAttachedContactsRequest.builder()
.companyId(companyId)
.page(1)
.perPage(25)
.build());

// assert
Expand Down
Loading