Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Swimburger committed Dec 20, 2024
1 parent 4a42ac8 commit 9983109
Show file tree
Hide file tree
Showing 25 changed files with 1,999 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.github/PULL_REQUEST_TEMPLATE.md
.gitattributes
LICENSE
REPO_OWNER
REPO_OWNER
tests/integration
61 changes: 61 additions & 0 deletions tests/integration/admins.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { createClient } from "./utils/createClient";

describe("Admins", () => {
let adminId: string;
const client = createClient();

beforeAll(async () => {
// arrange
const adminList = await client.admins.list();
adminId = adminList.admins[0].id;
});

it("list", async () => {
// act
const response = await client.admins.list();

// assert
expect(response).toBeDefined();
});
it("find", async () => {
// act
const response = await client.admins.find({ admin_id: adminId });

// assert
expect(response).toBeDefined();
});

it("listAllActivityLogs", async () => {
// act
const response = await client.admins.listAllActivityLogs({
created_at_after: new Date("2021-12-12").toISOString(),
created_at_before: new Date("2022-01-01").toISOString(),
});

// assert
expect(response).toBeDefined();
});

it("away - ON", async () => {
// act
const response = await client.admins.away({
admin_id: adminId,
away_mode_enabled: true,
away_mode_reassign: true,
});

// assert
expect(response).toBeDefined();
});
it("away - OFF", async () => {
// act
const response = await client.admins.away({
admin_id: adminId,
away_mode_enabled: false,
away_mode_reassign: false,
});

// assert
expect(response).toBeDefined();
});
});
116 changes: 116 additions & 0 deletions tests/integration/articles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { IntercomClient as Client } from "../../src";
import { randomString } from "./utils/random";
import { createClient } from "./utils/createClient";

async function createArticle(client: Client, parentId: number, adminId: number) {
return await client.articles.create({
title: randomString(),
description: randomString(),
body: "<b>Eins Zwei</b>",
author_id: adminId,
state: "draft",
parent_id: parentId,
parent_type: "collection",
translated_content: {
fr: {
type: "article_content",
title: "Allez les verts",
description: "French description",
body: "<p>French body in html</p>",
author_id: adminId,
state: "draft",
},
},
});
}

async function tryDeleteArticle(client: Client, articleId: string) {
try {
await client.articles.delete({ article_id: articleId });
} catch (error) {
console.error("Failed to delete article:", error);
}
}

describe("Articles", () => {
let articleId: string;
let parentId: number;
let adminId: number;
const client = createClient();

beforeAll(async () => {
// arrange
const randomCollections = await client.helpCenters.collections.list({
per_page: 1,
});
const randomAdmins = await client.admins.list();

parentId = parseInt(randomCollections.data[0].id, 10);
adminId = parseInt(randomAdmins.admins[0].id, 10);

const article = await createArticle(client, parentId, adminId);
articleId = article.id;
});

afterAll(async () => {
// cleanup
await tryDeleteArticle(client, articleId);
});

it("create", async () => {
// act
const article = await createArticle(client, parentId, adminId);

// assert
expect(article).toBeDefined();

// cleanup
await tryDeleteArticle(client, article.id);
});

it("find", async () => {
// act
const response = await client.articles.find({ article_id: articleId });

// assert
expect(response).toBeDefined();
});

it("update", async () => {
// arrange
const article = await createArticle(client, parentId, adminId);

// act
const response = await client.articles.update({
article_id: article.id,
body: {
title: "Biba & Boba",
},
});

// assert
expect(response).toBeDefined();

// cleanup
await tryDeleteArticle(client, article.id);
});

it("list", async () => {
// act
const response = await client.articles.list({ page: 1, per_page: 12 });

// assert
expect(response).toBeDefined();
});

it("delete", async () => {
// arrange
const article = await createArticle(client, parentId, adminId);

// act
const response = await client.articles.delete({ article_id: article.id });

// assert
expect(response).toBeDefined();
});
});
148 changes: 148 additions & 0 deletions tests/integration/companies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { Intercom } from "../../src";
import { dateToUnixTimestamp } from "./utils/date";
import { createCompany, tryDeleteCompany } from "./helpers";
import { createClient } from "./utils/createClient";

describe("Companies", () => {
let contactId: string;
let company: Intercom.Company;

const client = createClient();

beforeAll(async () => {
// arrange
const randomContacts = await client.contacts.list({
per_page: 1,
});

contactId = randomContacts.data[0].id;
company = await createCompany(client);
});

afterAll(async () => {
// cleanup
await tryDeleteCompany(client, company.id);
});

it("create", async () => {
// act
const company = await createCompany(client);

// assert
expect(company).toBeDefined();

// cleanup
await tryDeleteCompany(client, company.id);
});

it("update", async () => {
// arrange
const company = await createCompany(client);

// act
const response = await client.companies.createOrUpdate({
company_id: company.company_id,
remote_created_at: dateToUnixTimestamp(new Date()),
name: "BestCompanyInc",
monthly_spend: 9001,
plan: "1. Get pizzaid",
size: 62049,
website: "http://the-best.one",
industry: "The Best One",
custom_attributes: {},
});

// assert
expect(response).toBeDefined();

// cleanup
await tryDeleteCompany(client, company.id);
});

it("find - by id", async () => {
// act
const response = await client.companies.find({
company_id: company.id,
});

// assert
expect(response).toBeDefined();
});

it("list", async () => {
// act
const response = await client.companies.list({
page: 1,
per_page: 35,
order: "desc",
});

// assert
expect(response).toBeDefined();
});

it("delete", async () => {
// arrange
const company = await createCompany(client);

// act
const response = await client.companies.delete({
company_id: company.id,
});

// assert
expect(response).toBeDefined();
});

it.skip("scroll - infinite one", async () => {
// act
const response = await client.companies.scroll();

// assert
expect(response.data).toBeDefined();
});

it("attachContact", async () => {
// act
const response = await client.companies.attachContact({
contact_id: contactId,
id: company.id,
});

// assert
expect(response).toBeDefined();
});

it("detachContact", async () => {
// act
const response = await client.companies.detachContact({
contact_id: contactId,
company_id: company.id,
});

// assert
expect(response).toBeDefined();
});

it("listAttachedContacts", async () => {
// act
const response = await client.companies.listAttachedContacts({
company_id: company.id,
page: 1,
per_page: 25,
});

// assert
expect(response).toBeDefined();
});

it("listAttachedSegments", async () => {
// act
const response = await client.companies.listAttachedSegments({
company_id: company.id,
});

// assert
expect(response).toBeDefined();
});
});
Loading

0 comments on commit 9983109

Please sign in to comment.