Skip to content

Commit 2ec3c00

Browse files
chore: add e2e test file and registry in node step action (#14)
* chore: add project e2e tests * add registry url in node setup step
1 parent 2d03c00 commit 2ec3c00

File tree

2 files changed

+182
-0
lines changed

2 files changed

+182
-0
lines changed

.github/workflows/publish-node-sdk.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ jobs:
1313

1414
- name: Set up Node.js
1515
uses: actions/setup-node@v4
16+
with:
17+
registry-url: 'https://registry.npmjs.org'
18+
node-version: '20'
1619

1720
- name: Enable corepack
1821
run: corepack enable pnpm

tests/e2e/project.test.ts

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
import { createTestClient, randomizeName, wait } from "../helpers/test-utils";
2+
import { e2eConfig } from "./config";
3+
import { Project, Cycle, Module, WorkItem } from "../../src/models";
4+
5+
describe("End to End Project Test", () => {
6+
// Shared state across tests
7+
let client: ReturnType<typeof createTestClient>;
8+
let userId: string;
9+
let project: Project;
10+
let cycle: Cycle;
11+
let module: Module;
12+
let workItem1: WorkItem;
13+
let workItem2: WorkItem;
14+
let workItem3: WorkItem;
15+
16+
beforeAll(async () => {
17+
// Initialize client and create prerequisites for all tests
18+
client = createTestClient();
19+
20+
// Get current user - needed for assignees and cycle owners
21+
const me = await client.users.me();
22+
userId = me.id!;
23+
24+
// Create project - all tests depend on this
25+
const projectName = randomizeName();
26+
project = await client.projects.create(e2eConfig.workspaceSlug, {
27+
name: projectName,
28+
id: projectName.slice(0, 5).toUpperCase(),
29+
});
30+
});
31+
32+
it("should create and list cycles", async () => {
33+
const cycleName = randomizeName("Test Cycle");
34+
cycle = await client.cycles.create(e2eConfig.workspaceSlug, project.id, {
35+
name: cycleName,
36+
description: "Test Cycle Description",
37+
// YYYY-MM-DD format
38+
start_date: new Date().toISOString().split("T")[0],
39+
// YYYY-MM-DD format
40+
end_date: new Date(new Date().setDate(new Date().getDate() + 14)).toISOString().split("T")[0],
41+
owned_by: userId,
42+
project_id: project.id,
43+
});
44+
45+
expect(cycle).toBeDefined();
46+
expect(cycle.id).toBeDefined();
47+
expect(cycle.name).toBe(cycleName);
48+
49+
const cycles = await client.cycles.list(e2eConfig.workspaceSlug, project.id);
50+
expect(cycles.results.length).toBeGreaterThan(0);
51+
expect(cycles.results.find((c) => c.name === cycle.name)).toBeDefined();
52+
});
53+
54+
it("should create and list modules", async () => {
55+
const moduleName = randomizeName("Test Module");
56+
module = await client.modules.create(e2eConfig.workspaceSlug, project.id, {
57+
name: moduleName,
58+
description: "Test Module Description",
59+
});
60+
61+
expect(module).toBeDefined();
62+
expect(module.id).toBeDefined();
63+
expect(module.name).toBe(moduleName);
64+
65+
const modules = await client.modules.list(e2eConfig.workspaceSlug, project.id);
66+
expect(modules.results.length).toBeGreaterThan(0);
67+
expect(modules.results.find((m) => m.name === module.name)).toBeDefined();
68+
});
69+
70+
it("should create work items with assignees", async () => {
71+
workItem1 = await client.workItems.create(e2eConfig.workspaceSlug, project.id, {
72+
name: randomizeName("Test Work Item 1"),
73+
description_html: "<p>Test Work Item 1 Description</p>",
74+
assignees: [userId],
75+
});
76+
77+
expect(workItem1).toBeDefined();
78+
expect(workItem1.id).toBeDefined();
79+
expect(workItem1.assignees).toBeDefined();
80+
81+
workItem2 = await client.workItems.create(e2eConfig.workspaceSlug, project.id, {
82+
name: randomizeName("Test Work Item 2"),
83+
description_html: "<p>Test Work Item 2 Description</p>",
84+
assignees: [userId],
85+
});
86+
87+
expect(workItem2).toBeDefined();
88+
expect(workItem2.id).toBeDefined();
89+
expect(workItem2.assignees).toHaveLength(1);
90+
91+
const workItems = await client.workItems.list(e2eConfig.workspaceSlug, project.id);
92+
expect(workItems.results.length).toBeGreaterThan(0);
93+
});
94+
95+
it("should create work item relations", async () => {
96+
await client.workItems.relations.create(e2eConfig.workspaceSlug, project.id, workItem1.id, {
97+
relation_type: "relates_to",
98+
issues: [workItem2.id],
99+
});
100+
101+
const relations = await client.workItems.relations.list(e2eConfig.workspaceSlug, project.id, workItem1.id);
102+
expect(relations.relates_to).toBeDefined();
103+
expect(relations.relates_to[0]).toBe(workItem2.id);
104+
});
105+
106+
it("should create work item with parent relationship", async () => {
107+
workItem3 = await client.workItems.create(e2eConfig.workspaceSlug, project.id, {
108+
name: randomizeName("Test Work Item 3"),
109+
description_html: "<p>Test Work Item 3 Description</p>",
110+
assignees: [userId],
111+
parent: workItem1.id,
112+
});
113+
114+
expect(workItem3).toBeDefined();
115+
expect(workItem3.id).toBeDefined();
116+
117+
const workItem3Details = await client.workItems.retrieve(e2eConfig.workspaceSlug, project.id, workItem3.id);
118+
expect(workItem3Details.parent).toBe(workItem1.id);
119+
});
120+
121+
it("should add work items to cycle", async () => {
122+
await client.cycles.addWorkItemsToCycle(e2eConfig.workspaceSlug, project.id, cycle.id, [
123+
workItem1.id,
124+
workItem2.id,
125+
]);
126+
127+
const workItemsInCycle = await client.cycles.listWorkItemsInCycle(e2eConfig.workspaceSlug, project.id, cycle.id);
128+
expect(workItemsInCycle.results.length).toBeGreaterThan(0);
129+
expect(workItemsInCycle.results.find((w) => w.id === workItem1.id)).toBeDefined();
130+
expect(workItemsInCycle.results.find((w) => w.id === workItem2.id)).toBeDefined();
131+
});
132+
133+
it("should add work items to module", async () => {
134+
await client.modules.addWorkItemsToModule(e2eConfig.workspaceSlug, project.id, module.id, [
135+
workItem1.id,
136+
workItem2.id,
137+
]);
138+
139+
const workItemsInModule = await client.modules.listWorkItemsInModule(
140+
e2eConfig.workspaceSlug,
141+
project.id,
142+
module.id
143+
);
144+
expect(workItemsInModule.results.length).toBeGreaterThan(0);
145+
expect(workItemsInModule.results.find((w) => w.id === workItem1.id)).toBeDefined();
146+
expect(workItemsInModule.results.find((w) => w.id === workItem2.id)).toBeDefined();
147+
});
148+
149+
it("should remove work item from module", async () => {
150+
await client.modules.removeWorkItemFromModule(e2eConfig.workspaceSlug, project.id, module.id, workItem1.id);
151+
152+
const workItemsInModuleAfterRemoval = await client.modules.listWorkItemsInModule(
153+
e2eConfig.workspaceSlug,
154+
project.id,
155+
module.id
156+
);
157+
expect(workItemsInModuleAfterRemoval.results.length).toBe(1);
158+
expect(workItemsInModuleAfterRemoval.results.find((w) => w.id === workItem2.id)).toBeDefined();
159+
expect(workItemsInModuleAfterRemoval.results.find((w) => w.id === workItem1.id)).toBeUndefined();
160+
});
161+
162+
it("should remove work item from cycle", async () => {
163+
await client.cycles.removeWorkItemFromCycle(e2eConfig.workspaceSlug, project.id, cycle.id, workItem1.id);
164+
165+
const workItemsInCycleAfterRemoval = await client.cycles.listWorkItemsInCycle(
166+
e2eConfig.workspaceSlug,
167+
project.id,
168+
cycle.id
169+
);
170+
expect(workItemsInCycleAfterRemoval.results.length).toBe(1);
171+
expect(workItemsInCycleAfterRemoval.results.find((w) => w.id === workItem2.id)).toBeDefined();
172+
expect(workItemsInCycleAfterRemoval.results.find((w) => w.id === workItem1.id)).toBeUndefined();
173+
});
174+
175+
afterAll(async () => {
176+
console.log("Deleting project: ", project.name);
177+
await client.projects.delete(e2eConfig.workspaceSlug, project.id);
178+
});
179+
});

0 commit comments

Comments
 (0)