Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: integration tests #51

Merged
merged 5 commits into from
Feb 3, 2022
Merged
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
33 changes: 33 additions & 0 deletions test/freshteam/business-units.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Freshteam } from "../../src";
import nock from "nock";
import getBusinessUnits200 from "./responses/business-units/get-business-units-200";

const FT_DOMAIN = "example.freshteam.com";
const FT_API_KEY = "f_xkcd_222";

const mock = nock(`https://${FT_DOMAIN}`);

describe("Business Units API", function () {
const ft = new Freshteam(FT_DOMAIN, FT_API_KEY);

describe("get business-unit by id: /api/business_units/:id", function () {
it("should get business-unit's information successfully", async function () {
const id = 6000001054;
mock.get(`/api/business_units/${id}`).reply(200, getBusinessUnits200[0]);
const bussUnitDetail = await ft.businessUnits.get(id);
expect(bussUnitDetail).toBeInstanceOf(Freshteam.models.BusinessUnit);
expect(bussUnitDetail.id).toEqual(id);
});
});

describe("get business-units: /api/business_units", function () {
it("should list all business-units information successfully without queries", async function () {
mock.get(`/api/business_units`).reply(200, getBusinessUnits200);
const bussUnitsList = await ft.businessUnits.list();
expect(bussUnitsList).toBeInstanceOf(Array);
for (const e of bussUnitsList) {
expect(e).toBeInstanceOf(Freshteam.models.BusinessUnit);
}
});
});
});
33 changes: 33 additions & 0 deletions test/freshteam/departments.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Freshteam } from "../../src";
import nock from "nock";
import getDepartments200 from "./responses/departments/get-departments-200";

const FT_DOMAIN = "example.freshteam.com";
const FT_API_KEY = "f_xkcd_222";

const mock = nock(`https://${FT_DOMAIN}`);

describe("Departments API", function () {
const ft = new Freshteam(FT_DOMAIN, FT_API_KEY);

describe("get department by id: /api/department/:id", function () {
it("should get department information successfully", async function () {
const id = 6000060442;
mock.get(`/api/departments/${id}`).reply(200, getDepartments200[0]);
const deptDetail = await ft.departments.get(id);
expect(deptDetail).toBeInstanceOf(Freshteam.models.Department);
expect(deptDetail.id).toEqual(id);
});
});

describe("get departments: /api/departments", function () {
it("should list all departments information successfully without queries", async function () {
mock.get(`/api/departments`).reply(200, getDepartments200);
const deptList = await ft.departments.list();
expect(deptList).toBeInstanceOf(Array);
for (const e of deptList) {
expect(e).toBeInstanceOf(Freshteam.models.Department);
}
});
});
});
33 changes: 33 additions & 0 deletions test/freshteam/levels.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Freshteam } from "../../src";
import nock from "nock";
import getLevels200 from "./responses/levels/get-levels-200";

const FT_DOMAIN = "example.freshteam.com";
const FT_API_KEY = "f_xkcd_222";

const mock = nock(`https://${FT_DOMAIN}`);

describe("Levels API", function () {
const ft = new Freshteam(FT_DOMAIN, FT_API_KEY);

describe("get level by id: /api/levels/:id", function () {
it("should get level's information successfully", async function () {
const id = 6000116873;
mock.get(`/api/levels/${id}`).reply(200, getLevels200[0]);
const levelDetail = await ft.levels.get(id);
expect(levelDetail).toBeInstanceOf(Freshteam.models.Level);
expect(levelDetail.id).toEqual(id);
});
});

describe("get levels: /api/levels", function () {
it("should list all levels information successfully without queries", async function () {
mock.get(`/api/levels`).reply(200, getLevels200);
const levelsList = await ft.levels.list();
expect(levelsList).toBeInstanceOf(Array);
for (const e of levelsList) {
expect(e).toBeInstanceOf(Freshteam.models.Level);
}
});
});
});
26 changes: 26 additions & 0 deletions test/freshteam/responses/business-units/get-business-units-200.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default [
{
id: 6000001054,
created_at: "2021-12-21T13:03:35.000Z",
updated_at: "2021-12-21T13:03:35.000Z",
deleted: false,
name: "Division",
description: null
},
{
id: 6000001053,
created_at: "2021-12-21T13:03:30.000Z",
updated_at: "2021-12-21T13:03:30.000Z",
deleted: false,
name: "Functional",
description: null
},
{
id: 6000001055,
created_at: "2021-12-21T13:03:43.000Z",
updated_at: "2021-12-21T13:03:43.000Z",
deleted: false,
name: "Matrix",
description: null
}
];
37 changes: 37 additions & 0 deletions test/freshteam/responses/departments/get-departments-200.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export default [
{
id: 6000060442,
created_at: "2021-07-16T17:43:48.000Z",
updated_at: "2021-07-16T17:43:48.000Z",
deleted: false,
name: "Administration"
},
{
id: 6000060441,
created_at: "2021-07-16T17:43:48.000Z",
updated_at: "2021-07-16T17:43:48.000Z",
deleted: false,
name: "Finance"
},
{
id: 6000060444,
created_at: "2021-07-16T17:43:48.000Z",
updated_at: "2021-07-16T17:43:48.000Z",
deleted: false,
name: "Human Resources"
},
{
id: 6000060440,
created_at: "2021-07-16T17:43:48.000Z",
updated_at: "2021-07-16T17:43:48.000Z",
deleted: false,
name: "Marketing"
},
{
id: 6000060443,
created_at: "2021-07-16T17:43:48.000Z",
updated_at: "2021-07-16T17:43:48.000Z",
deleted: false,
name: "Sales"
}
];
23 changes: 23 additions & 0 deletions test/freshteam/responses/levels/get-levels-200.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default [
{
id: 6000116873,
created_at: "2021-07-16T17:43:51.000Z",
updated_at: "2021-07-16T17:43:51.000Z",
deleted: false,
name: "IC1"
},
{
id: 6000116874,
created_at: "2021-07-16T17:43:51.000Z",
updated_at: "2021-07-16T17:43:51.000Z",
deleted: false,
name: "IC2"
},
{
id: 6000116875,
created_at: "2021-07-16T17:43:51.000Z",
updated_at: "2021-07-16T17:43:51.000Z",
deleted: false,
name: "IC3"
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default [
{
id: 6000001846,
created_at: "2021-12-21T12:53:37.000Z",
updated_at: "2021-12-21T12:53:37.000Z",
deleted: null,
name: "Developer Marketing",
description: null
},
{
id: 6000001845,
created_at: "2021-12-21T12:53:24.000Z",
updated_at: "2021-12-21T12:53:24.000Z",
deleted: null,
name: "Developer Relations",
description: null
}
];
51 changes: 51 additions & 0 deletions test/freshteam/responses/teams/get-teams-200.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export default [
{
id: 6000117751,
created_at: "2021-07-16T17:43:47.000Z",
updated_at: "2021-07-16T17:43:47.000Z",
deleted: false,
name: "Business"
},
{
id: 6000117758,
created_at: "2021-07-16T17:43:51.000Z",
updated_at: "2021-07-16T17:43:51.000Z",
deleted: false,
name: "Corporate Marketing"
},
{
id: 6000117753,
created_at: "2021-07-16T17:43:51.000Z",
updated_at: "2021-07-16T17:43:51.000Z",
deleted: false,
name: "Customer Success"
},
{
id: 6000117757,
created_at: "2021-07-16T17:43:51.000Z",
updated_at: "2021-07-16T17:43:51.000Z",
deleted: false,
name: "Digital Marketing"
},
{
id: 6000117756,
created_at: "2021-07-16T17:43:51.000Z",
updated_at: "2021-07-16T17:43:51.000Z",
deleted: false,
name: "Field Sales"
},
{
id: 6000117760,
created_at: "2021-07-16T17:43:51.000Z",
updated_at: "2021-07-16T17:43:51.000Z",
deleted: false,
name: "HR Operations"
},
{
id: 6000117755,
created_at: "2021-07-16T17:43:51.000Z",
updated_at: "2021-07-16T17:43:51.000Z",
deleted: false,
name: "Inbound Sales"
}
];
33 changes: 33 additions & 0 deletions test/freshteam/sub-departments.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Freshteam } from "../../src";
import nock from "nock";
import getSubDepartments200 from "./responses/sub-departments/get-sub-departments-200";

const FT_DOMAIN = "example.freshteam.com";
const FT_API_KEY = "f_xkcd_222";

const mock = nock(`https://${FT_DOMAIN}`);

describe("Sub Departments API", function () {
const ft = new Freshteam(FT_DOMAIN, FT_API_KEY);

describe("get sub-department by id: /api/sub_departments/:id", function () {
it("should get sub-departments information successfully", async function () {
const id = 6000001846;
mock.get(`/api/sub_departments/${id}`).reply(200, getSubDepartments200[0]);
const subDeptDetail = await ft.subDepartments.get(id);
expect(subDeptDetail).toBeInstanceOf(Freshteam.models.SubDepartment);
expect(subDeptDetail.id).toEqual(id);
});
});

describe("get sub-departments: /api/sub_departments", function () {
it("should list all sub-departments information successfully without queries", async function () {
mock.get(`/api/sub_departments`).reply(200, getSubDepartments200);
const subDeptList = await ft.subDepartments.list();
expect(subDeptList).toBeInstanceOf(Array);
for (const e of subDeptList) {
expect(e).toBeInstanceOf(Freshteam.models.SubDepartment);
}
});
});
});
33 changes: 33 additions & 0 deletions test/freshteam/teams.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Freshteam } from "../../src";
import nock from "nock";
import getTeams200 from "./responses/teams/get-teams-200";

const FT_DOMAIN = "example.freshteam.com";
const FT_API_KEY = "f_xkcd_222";

const mock = nock(`https://${FT_DOMAIN}`);

describe("Teams API", function () {
const ft = new Freshteam(FT_DOMAIN, FT_API_KEY);

describe("get team by id: /api/teams/:id", function () {
it("should get team's information successfully", async function () {
const id = 6000117751;
mock.get(`/api/teams/${id}`).reply(200, getTeams200[0]);
const teamDetail = await ft.teams.get(id);
expect(teamDetail).toBeInstanceOf(Freshteam.models.Team);
expect(teamDetail.id).toEqual(id);
});
});

describe("get teams: /api/teams", function () {
it("should list all teams information successfully without queries", async function () {
mock.get(`/api/teams`).reply(200, getTeams200);
const teamList = await ft.teams.list();
expect(teamList).toBeInstanceOf(Array);
for (const e of teamList) {
expect(e).toBeInstanceOf(Freshteam.models.Team);
}
});
});
});