Skip to content

Commit 02aef00

Browse files
committed
Add specs for new item service methods
1 parent a0ab033 commit 02aef00

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

test/items/services/ItemService.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ jest.mock("@infrastructure/github", () => ({
1111
createIssue: jest.fn(),
1212
addIssueToProject: jest.fn(),
1313
updateProjectItemDueDate: jest.fn(),
14+
updateProjectItemAssignee: jest.fn(),
1415
},
1516
}));
1617

17-
const mockIssue = { id: "issue-123" };
18+
const mockIssue = {
19+
id: "issue-123",
20+
title: "Mock Issue Title",
21+
url: "https://github.com/mock/issue",
22+
createdAt: "2025-05-01T00:00:00Z",
23+
updatedAt: "2025-05-02T00:00:00Z",
24+
};
1825
const mockItem = { id: "item-456" };
1926
const mockSuccessResult = Ok({ success: true });
2027

@@ -93,3 +100,36 @@ describe("create", () => {
93100
expect(result.val).toEqual(error);
94101
});
95102
});
103+
104+
describe("updateAssignee", () => {
105+
const assigneeId = "MDQ6VXNlcjQzMjIzNjgy";
106+
const itemId = "issue-123";
107+
108+
beforeEach(() => {
109+
jest.clearAllMocks();
110+
});
111+
112+
it("will return success if GitHubAPI.updateProjectItemAssignee succeeds", async () => {
113+
const mockResult = Ok({ status: "success" });
114+
(GithubAPI.updateProjectItemAssignee as jest.Mock).mockResolvedValue(mockResult);
115+
116+
const result = await ItemService.updateAssignee({ assigneeId, itemId });
117+
118+
expect(GithubAPI.updateProjectItemAssignee).toHaveBeenCalledWith({
119+
issueId: itemId,
120+
assigneeId,
121+
});
122+
expect(result.ok).toBe(true);
123+
expect(result.val).toEqual({ status: "success" });
124+
});
125+
126+
it("will return error if GitHubAPI.updateProjectItemAssignee fails", async () => {
127+
const error = new Error("updateProjectItemAssignee failed");
128+
(GithubAPI.updateProjectItemAssignee as jest.Mock).mockResolvedValue(Err(error));
129+
130+
const result = await ItemService.updateAssignee({ assigneeId, itemId });
131+
132+
expect(result.err).toBe(true);
133+
expect(result.val).toEqual(error);
134+
});
135+
});

0 commit comments

Comments
 (0)