Skip to content

Commit 9983109

Browse files
committed
Add integration tests
1 parent 4a42ac8 commit 9983109

25 files changed

+1999
-1
lines changed

.fernignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
.github/PULL_REQUEST_TEMPLATE.md
44
.gitattributes
55
LICENSE
6-
REPO_OWNER
6+
REPO_OWNER
7+
tests/integration

tests/integration/admins.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { createClient } from "./utils/createClient";
2+
3+
describe("Admins", () => {
4+
let adminId: string;
5+
const client = createClient();
6+
7+
beforeAll(async () => {
8+
// arrange
9+
const adminList = await client.admins.list();
10+
adminId = adminList.admins[0].id;
11+
});
12+
13+
it("list", async () => {
14+
// act
15+
const response = await client.admins.list();
16+
17+
// assert
18+
expect(response).toBeDefined();
19+
});
20+
it("find", async () => {
21+
// act
22+
const response = await client.admins.find({ admin_id: adminId });
23+
24+
// assert
25+
expect(response).toBeDefined();
26+
});
27+
28+
it("listAllActivityLogs", async () => {
29+
// act
30+
const response = await client.admins.listAllActivityLogs({
31+
created_at_after: new Date("2021-12-12").toISOString(),
32+
created_at_before: new Date("2022-01-01").toISOString(),
33+
});
34+
35+
// assert
36+
expect(response).toBeDefined();
37+
});
38+
39+
it("away - ON", async () => {
40+
// act
41+
const response = await client.admins.away({
42+
admin_id: adminId,
43+
away_mode_enabled: true,
44+
away_mode_reassign: true,
45+
});
46+
47+
// assert
48+
expect(response).toBeDefined();
49+
});
50+
it("away - OFF", async () => {
51+
// act
52+
const response = await client.admins.away({
53+
admin_id: adminId,
54+
away_mode_enabled: false,
55+
away_mode_reassign: false,
56+
});
57+
58+
// assert
59+
expect(response).toBeDefined();
60+
});
61+
});

tests/integration/articles.test.ts

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { IntercomClient as Client } from "../../src";
2+
import { randomString } from "./utils/random";
3+
import { createClient } from "./utils/createClient";
4+
5+
async function createArticle(client: Client, parentId: number, adminId: number) {
6+
return await client.articles.create({
7+
title: randomString(),
8+
description: randomString(),
9+
body: "<b>Eins Zwei</b>",
10+
author_id: adminId,
11+
state: "draft",
12+
parent_id: parentId,
13+
parent_type: "collection",
14+
translated_content: {
15+
fr: {
16+
type: "article_content",
17+
title: "Allez les verts",
18+
description: "French description",
19+
body: "<p>French body in html</p>",
20+
author_id: adminId,
21+
state: "draft",
22+
},
23+
},
24+
});
25+
}
26+
27+
async function tryDeleteArticle(client: Client, articleId: string) {
28+
try {
29+
await client.articles.delete({ article_id: articleId });
30+
} catch (error) {
31+
console.error("Failed to delete article:", error);
32+
}
33+
}
34+
35+
describe("Articles", () => {
36+
let articleId: string;
37+
let parentId: number;
38+
let adminId: number;
39+
const client = createClient();
40+
41+
beforeAll(async () => {
42+
// arrange
43+
const randomCollections = await client.helpCenters.collections.list({
44+
per_page: 1,
45+
});
46+
const randomAdmins = await client.admins.list();
47+
48+
parentId = parseInt(randomCollections.data[0].id, 10);
49+
adminId = parseInt(randomAdmins.admins[0].id, 10);
50+
51+
const article = await createArticle(client, parentId, adminId);
52+
articleId = article.id;
53+
});
54+
55+
afterAll(async () => {
56+
// cleanup
57+
await tryDeleteArticle(client, articleId);
58+
});
59+
60+
it("create", async () => {
61+
// act
62+
const article = await createArticle(client, parentId, adminId);
63+
64+
// assert
65+
expect(article).toBeDefined();
66+
67+
// cleanup
68+
await tryDeleteArticle(client, article.id);
69+
});
70+
71+
it("find", async () => {
72+
// act
73+
const response = await client.articles.find({ article_id: articleId });
74+
75+
// assert
76+
expect(response).toBeDefined();
77+
});
78+
79+
it("update", async () => {
80+
// arrange
81+
const article = await createArticle(client, parentId, adminId);
82+
83+
// act
84+
const response = await client.articles.update({
85+
article_id: article.id,
86+
body: {
87+
title: "Biba & Boba",
88+
},
89+
});
90+
91+
// assert
92+
expect(response).toBeDefined();
93+
94+
// cleanup
95+
await tryDeleteArticle(client, article.id);
96+
});
97+
98+
it("list", async () => {
99+
// act
100+
const response = await client.articles.list({ page: 1, per_page: 12 });
101+
102+
// assert
103+
expect(response).toBeDefined();
104+
});
105+
106+
it("delete", async () => {
107+
// arrange
108+
const article = await createArticle(client, parentId, adminId);
109+
110+
// act
111+
const response = await client.articles.delete({ article_id: article.id });
112+
113+
// assert
114+
expect(response).toBeDefined();
115+
});
116+
});
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import { Intercom } from "../../src";
2+
import { dateToUnixTimestamp } from "./utils/date";
3+
import { createCompany, tryDeleteCompany } from "./helpers";
4+
import { createClient } from "./utils/createClient";
5+
6+
describe("Companies", () => {
7+
let contactId: string;
8+
let company: Intercom.Company;
9+
10+
const client = createClient();
11+
12+
beforeAll(async () => {
13+
// arrange
14+
const randomContacts = await client.contacts.list({
15+
per_page: 1,
16+
});
17+
18+
contactId = randomContacts.data[0].id;
19+
company = await createCompany(client);
20+
});
21+
22+
afterAll(async () => {
23+
// cleanup
24+
await tryDeleteCompany(client, company.id);
25+
});
26+
27+
it("create", async () => {
28+
// act
29+
const company = await createCompany(client);
30+
31+
// assert
32+
expect(company).toBeDefined();
33+
34+
// cleanup
35+
await tryDeleteCompany(client, company.id);
36+
});
37+
38+
it("update", async () => {
39+
// arrange
40+
const company = await createCompany(client);
41+
42+
// act
43+
const response = await client.companies.createOrUpdate({
44+
company_id: company.company_id,
45+
remote_created_at: dateToUnixTimestamp(new Date()),
46+
name: "BestCompanyInc",
47+
monthly_spend: 9001,
48+
plan: "1. Get pizzaid",
49+
size: 62049,
50+
website: "http://the-best.one",
51+
industry: "The Best One",
52+
custom_attributes: {},
53+
});
54+
55+
// assert
56+
expect(response).toBeDefined();
57+
58+
// cleanup
59+
await tryDeleteCompany(client, company.id);
60+
});
61+
62+
it("find - by id", async () => {
63+
// act
64+
const response = await client.companies.find({
65+
company_id: company.id,
66+
});
67+
68+
// assert
69+
expect(response).toBeDefined();
70+
});
71+
72+
it("list", async () => {
73+
// act
74+
const response = await client.companies.list({
75+
page: 1,
76+
per_page: 35,
77+
order: "desc",
78+
});
79+
80+
// assert
81+
expect(response).toBeDefined();
82+
});
83+
84+
it("delete", async () => {
85+
// arrange
86+
const company = await createCompany(client);
87+
88+
// act
89+
const response = await client.companies.delete({
90+
company_id: company.id,
91+
});
92+
93+
// assert
94+
expect(response).toBeDefined();
95+
});
96+
97+
it.skip("scroll - infinite one", async () => {
98+
// act
99+
const response = await client.companies.scroll();
100+
101+
// assert
102+
expect(response.data).toBeDefined();
103+
});
104+
105+
it("attachContact", async () => {
106+
// act
107+
const response = await client.companies.attachContact({
108+
contact_id: contactId,
109+
id: company.id,
110+
});
111+
112+
// assert
113+
expect(response).toBeDefined();
114+
});
115+
116+
it("detachContact", async () => {
117+
// act
118+
const response = await client.companies.detachContact({
119+
contact_id: contactId,
120+
company_id: company.id,
121+
});
122+
123+
// assert
124+
expect(response).toBeDefined();
125+
});
126+
127+
it("listAttachedContacts", async () => {
128+
// act
129+
const response = await client.companies.listAttachedContacts({
130+
company_id: company.id,
131+
page: 1,
132+
per_page: 25,
133+
});
134+
135+
// assert
136+
expect(response).toBeDefined();
137+
});
138+
139+
it("listAttachedSegments", async () => {
140+
// act
141+
const response = await client.companies.listAttachedSegments({
142+
company_id: company.id,
143+
});
144+
145+
// assert
146+
expect(response).toBeDefined();
147+
});
148+
});

0 commit comments

Comments
 (0)