forked from intercom/intercom-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegrationTest.java
More file actions
161 lines (145 loc) · 5.94 KB
/
Copy pathIntegrationTest.java
File metadata and controls
161 lines (145 loc) · 5.94 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.intercom.api.integration;
import com.intercom.api.Intercom;
import com.intercom.api.resources.companies.requests.AttachContactToCompanyRequest;
import com.intercom.api.resources.companies.requests.CreateOrUpdateCompanyRequest;
import com.intercom.api.resources.companies.requests.DeleteCompanyRequest;
import com.intercom.api.resources.companies.types.Company;
import com.intercom.api.resources.contacts.requests.DeleteContactRequest;
import com.intercom.api.resources.contacts.types.Contact;
import com.intercom.api.resources.conversations.requests.CreateConversationRequest;
import com.intercom.api.resources.messages.types.Message;
import com.intercom.api.resources.tags.requests.DeleteTagRequest;
import com.intercom.api.resources.tags.requests.TagConversationRequest;
import com.intercom.api.resources.tags.types.Tag;
import com.intercom.api.resources.tags.types.TagsCreateRequestBody;
import com.intercom.api.types.CreateContactRequest;
import com.intercom.api.types.CreateOrUpdateTagRequest;
import com.intercom.api.utils.TestClientFactory;
import com.intercom.api.utils.Utils;
import java.util.Date;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class IntegrationTest {
private Intercom client;
private String adminId;
private Company company;
private Contact user;
private Contact lead;
private Tag tag;
@BeforeEach
public void before() {
// arrange
client = TestClientFactory.create();
adminId = client.admins().list().getAdmins().get(0).getId();
company = client.companies()
.createOrUpdate(CreateOrUpdateCompanyRequest.builder()
.name(Utils.randomString())
.companyId(Utils.randomString())
.plan("1. Get pizzaid")
.size(62049)
.website("http://the-best.one")
.industry("The Best One")
.remoteCreatedAt((int) (new Date().toInstant().toEpochMilli() / 1000L))
.monthlySpend(9001)
.build());
user = client.contacts()
.create(CreateContactRequest.of(CreateContactRequest.WithExternalId.builder()
.externalId(Utils.randomString())
.build()));
lead = client.contacts()
.create(CreateContactRequest.of(CreateContactRequest.WithRole.builder()
.role("lead")
.name("Marek Barek")
.build()));
tag = client.tags()
.create(TagsCreateRequestBody.of(CreateOrUpdateTagRequest.builder()
.name(Utils.randomString())
.build()));
}
@AfterEach
public void after() {
// cleanup
tryDeleteContacts();
tryDeleteCompany();
tryDeleteTag();
}
@Test
public void testAddContactToCompany() {
// act
Company response = client.companies()
.attachContact(AttachContactToCompanyRequest.builder()
.contactId(user.getId())
.companyId(company.getId())
.build());
// assert
Assertions.assertNotNull(response);
}
@Test
public void testCreateConversationWithContact() {
// act
Message response = client.conversations()
.create(CreateConversationRequest.builder()
.from(CreateConversationRequest.From.builder()
.type(CreateConversationRequest.From.Type.USER)
.id(user.getId())
.build())
.body("Welcome to the club, buddy!")
.build());
// assert
Assertions.assertNotNull(response);
}
@Test
public void testTagConversation() {
// arrange
Message message = client.conversations()
.create(CreateConversationRequest.builder()
.from(CreateConversationRequest.From.builder()
.type(CreateConversationRequest.From.Type.USER)
.id(user.getId())
.build())
.body("Welcome to the club, buddy!")
.build());
// act
Tag response = client.tags()
.tagConversation(TagConversationRequest.builder()
.conversationId(message.getConversationId())
.tagId(tag.getId())
.adminId(adminId)
.build());
// assert
Assertions.assertNotNull(response);
}
private void tryDeleteContacts() {
try {
client.contacts()
.delete(DeleteContactRequest.builder()
.contactId(user.getId())
.build());
client.contacts()
.delete(DeleteContactRequest.builder()
.contactId(lead.getId())
.build());
} catch (Exception e) {
throw new RuntimeException("Failed to delete contacts.", e);
}
}
private void tryDeleteCompany() {
try {
client.companies()
.delete(DeleteCompanyRequest.builder()
.companyId(company.getId())
.build());
} catch (Exception e) {
throw new RuntimeException("Failed to delete company.", e);
}
}
private void tryDeleteTag() {
try {
client.tags().delete(DeleteTagRequest.builder().tagId(tag.getId()).build());
} catch (Exception e) {
throw new RuntimeException("Failed to delete tag.", e);
}
}
}