-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwork-items.test.ts
More file actions
168 lines (143 loc) · 5.63 KB
/
work-items.test.ts
File metadata and controls
168 lines (143 loc) · 5.63 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
162
163
164
165
166
167
168
import { PlaneClient } from "../../../src/client/plane-client";
import { WorkItem } from "../../../src/models/WorkItem";
import { config } from "../constants";
import { createTestClient, randomizeName } from "../../helpers/test-utils";
import { describeIf as describe } from "../../helpers/conditional-tests";
describe(!!(config.workspaceSlug && config.projectId && config.userId), "Work Items API Tests", () => {
let client: PlaneClient;
let workspaceSlug: string;
let projectId: string;
let userId: string;
let workItem: WorkItem;
beforeAll(async () => {
client = createTestClient();
workspaceSlug = config.workspaceSlug;
projectId = config.projectId;
userId = config.userId;
});
afterAll(async () => {
// Clean up created work item
if (workItem?.id) {
try {
await client.workItems.delete(workspaceSlug, projectId, workItem.id);
} catch (error) {
console.warn("Failed to delete work item:", error);
}
}
});
it("should create a work item", async () => {
const name = randomizeName();
workItem = await client.workItems.create(workspaceSlug, projectId, {
name,
description_html: "<p>A work item created via the Plane SDK</p>",
});
expect(workItem).toBeDefined();
expect(workItem.id).toBeDefined();
expect(workItem.name).toContain(name);
expect(workItem.description_html).toBe("<p>A work item created via the Plane SDK</p>");
});
it("should retrieve a work item", async () => {
const retrievedWorkItem = await client.workItems.retrieve(workspaceSlug, projectId, workItem.id!);
expect(retrievedWorkItem).toBeDefined();
expect(retrievedWorkItem.id).toBe(workItem.id);
expect(retrievedWorkItem.name).toBe(workItem.name);
});
it("should update a work item", async () => {
const states = await client.states.list(workspaceSlug, projectId);
const labels = await client.labels.list(workspaceSlug, projectId);
const label = labels.results[0];
const state = states.results[0];
const updatedWorkItem = await client.workItems.update(workspaceSlug, projectId, workItem.id!, {
name: `${workItem.name} - Updated`,
description_html: "<p>Updated Test Work Item Description</p>",
state: state ? state.id : undefined,
assignees: [userId],
labels: label ? [label.id] : undefined,
});
expect(updatedWorkItem).toBeDefined();
expect(updatedWorkItem.id).toBe(workItem.id);
expect(updatedWorkItem.name).toBe(`${workItem.name} - Updated`);
expect(updatedWorkItem.description_html).toBe("<p>Updated Test Work Item Description</p>");
});
it("should list work items", async () => {
const workItems = await client.workItems.list(workspaceSlug, projectId);
expect(workItems).toBeDefined();
expect(Array.isArray(workItems.results)).toBe(true);
expect(workItems.results.length).toBeGreaterThan(0);
const foundWorkItem = workItems.results.find((wi) => wi.id === workItem.id);
expect(foundWorkItem).toBeDefined();
});
it("should retrieve work item by identifier", async () => {
const project = await client.projects.retrieve(workspaceSlug, projectId);
const workItemByIdentifier = await client.workItems.retrieveByIdentifier(
workspaceSlug,
`${project.identifier}-${workItem.sequence_id}`,
["project"]
);
expect(workItemByIdentifier).toBeDefined();
expect(workItemByIdentifier.id).toBe(workItem.id);
});
it("should search work items", async () => {
const searchedWorkItemsResponse = await client.workItems.search(workspaceSlug, workItem.name);
expect(searchedWorkItemsResponse.issues).toBeDefined();
expect(Array.isArray(searchedWorkItemsResponse.issues)).toBe(true);
expect(searchedWorkItemsResponse.issues.length).toBeGreaterThan(0);
const foundWorkItem = searchedWorkItemsResponse.issues.find((wi) => wi.id === workItem.id);
expect(foundWorkItem).toBeDefined();
});
it("should advanced search work items with query only", async () => {
const results = await client.workItems.advancedSearch(workspaceSlug, {
query: workItem.name,
limit: 10,
});
expect(Array.isArray(results)).toBe(true);
for (const item of results) {
expect(item.id).toBeDefined();
expect(item.name).toBeDefined();
expect(item.sequence_id).toBeDefined();
expect(item.project_id).toBeDefined();
expect(item.workspace_id).toBeDefined();
}
});
it("should advanced search work items with filters", async () => {
const results = await client.workItems.advancedSearch(workspaceSlug, {
filters: {
and: [
{ priority: workItem.priority },
],
},
limit: 10,
});
expect(Array.isArray(results)).toBe(true);
for (const item of results) {
expect(item.id).toBeDefined();
expect(item.name).toBeDefined();
}
});
it("should advanced search work items with nested AND/OR filters", async () => {
const states = await client.states.list(workspaceSlug, projectId);
const stateId = states.results[0]?.id;
const results = await client.workItems.advancedSearch(workspaceSlug, {
filters: {
and: [
...(stateId ? [{ state_id: stateId }] : []),
{
or: [
{ priority: "high" },
{ priority: "urgent" },
],
},
],
},
limit: 10,
});
expect(Array.isArray(results)).toBe(true);
for (const item of results) {
expect(item.id).toBeDefined();
expect(item.name).toBeDefined();
expect(item.sequence_id).toBeDefined();
expect(item.project_id).toBeDefined();
expect(item.workspace_id).toBeDefined();
}
});
});