Skip to content

Commit 3a96591

Browse files
authored
add wikis tests to improve code coverage (#244)
Improve Wikis code coverage from; ```sh ----------------|---------|----------|---------|---------|------------------------------------------------------ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ----------------|---------|----------|---------|---------|------------------------------------------------------ wikis.ts | 100 | 70.58 | 100 | 100 | 39,69-89,110,145 ----------------|---------|----------|---------|---------|------------------------------------------------------ ``` to ```sh ----------------|---------|----------|---------|---------|------------------------------------------------------ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ----------------|---------|----------|---------|---------|------------------------------------------------------ wikis.ts | 100 | 100 | 100 | 100 | ----------------|---------|----------|---------|---------|------------------------------------------------------ ``` ## GitHub issue number #57 (Don't close the issue, there are other tools to improve test coverages) ## **Associated Risks** None ## ✅ **PR Checklist** - [x] **I have read the [contribution guidelines](https://github.com/microsoft/azure-devops-mcp/blob/main/CONTRIBUTING.md)** - [x] **I have read the [code of conduct guidelines](https://github.com/microsoft/azure-devops-mcp/blob/main/CODE_OF_CONDUCT.md)** - [x] Title of the pull request is clear and informative. - [x] 👌 Code hygiene - [x] 🔭 Telemetry added, updated, or N/A - [x] 📄 Documentation added, updated, or N/A - [x] 🛡️ Automated tests added, or N/A ## 🧪 **How did you test it?** Run `npm run test` in the project root
1 parent 109f596 commit 3a96591

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

test/src/tools/wiki.test.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ describe("configureWikiTools", () => {
104104
expect(result.isError).toBe(true);
105105
expect(result.content[0].text).toBe("No wiki found");
106106
});
107+
108+
it("should handle unknown error type correctly", async () => {
109+
configureWikiTools(server, tokenProvider, connectionProvider);
110+
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wiki_get_wiki");
111+
if (!call) throw new Error("wiki_get_wiki tool not registered");
112+
const [, , , handler] = call;
113+
114+
mockWikiApi.getWiki.mockRejectedValue("string error");
115+
116+
const params = {
117+
wikiIdentifier: "wiki1",
118+
project: "proj1",
119+
};
120+
121+
const result = await handler(params);
122+
123+
expect(mockWikiApi.getWiki).toHaveBeenCalled();
124+
expect(result.isError).toBe(true);
125+
expect(result.content[0].text).toContain("Error fetching wiki: Unknown error occurred");
126+
});
107127
});
108128

109129
describe("list_wikis tool", () => {
@@ -168,6 +188,25 @@ describe("configureWikiTools", () => {
168188
expect(result.isError).toBe(true);
169189
expect(result.content[0].text).toBe("No wikis found");
170190
});
191+
192+
it("should handle unknown error type correctly", async () => {
193+
configureWikiTools(server, tokenProvider, connectionProvider);
194+
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wiki_list_wikis");
195+
if (!call) throw new Error("wiki_list_wikis tool not registered");
196+
const [, , , handler] = call;
197+
198+
mockWikiApi.getAllWikis.mockRejectedValue("string error");
199+
200+
const params = {
201+
project: "proj1",
202+
};
203+
204+
const result = await handler(params);
205+
206+
expect(mockWikiApi.getAllWikis).toHaveBeenCalled();
207+
expect(result.isError).toBe(true);
208+
expect(result.content[0].text).toContain("Error fetching wikis: Unknown error occurred");
209+
});
171210
});
172211

173212
describe("list_wiki_pages tool", () => {
@@ -201,6 +240,31 @@ describe("configureWikiTools", () => {
201240
expect(result.isError).toBeUndefined();
202241
});
203242

243+
it("should use default top parameter when not provided", async () => {
244+
configureWikiTools(server, tokenProvider, connectionProvider);
245+
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wiki_list_pages");
246+
if (!call) throw new Error("wiki_list_pages tool not registered");
247+
const [, , , handler] = call;
248+
mockWikiApi.getPagesBatch.mockResolvedValue({ value: ["page1", "page2"] });
249+
250+
const params = {
251+
wikiIdentifier: "wiki1",
252+
project: "proj1",
253+
};
254+
const result = await handler(params);
255+
256+
expect(mockWikiApi.getPagesBatch).toHaveBeenCalledWith(
257+
{
258+
top: 20,
259+
continuationToken: undefined,
260+
pageViewsForDays: undefined,
261+
},
262+
"proj1",
263+
"wiki1"
264+
);
265+
expect(result.isError).toBeUndefined();
266+
});
267+
204268
it("should handle API errors correctly", async () => {
205269
configureWikiTools(server, tokenProvider, connectionProvider);
206270
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wiki_list_pages");
@@ -243,6 +307,27 @@ describe("configureWikiTools", () => {
243307
expect(result.isError).toBe(true);
244308
expect(result.content[0].text).toBe("No wiki pages found");
245309
});
310+
311+
it("should handle unknown error type correctly", async () => {
312+
configureWikiTools(server, tokenProvider, connectionProvider);
313+
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wiki_list_pages");
314+
if (!call) throw new Error("wiki_list_pages tool not registered");
315+
const [, , , handler] = call;
316+
317+
mockWikiApi.getPagesBatch.mockRejectedValue("string error");
318+
319+
const params = {
320+
wikiIdentifier: "wiki1",
321+
project: "proj1",
322+
top: 10,
323+
};
324+
325+
const result = await handler(params);
326+
327+
expect(mockWikiApi.getPagesBatch).toHaveBeenCalled();
328+
expect(result.isError).toBe(true);
329+
expect(result.content[0].text).toContain("Error fetching wiki pages: Unknown error occurred");
330+
});
246331
});
247332

248333
describe("get_page_content tool", () => {
@@ -353,5 +438,26 @@ describe("configureWikiTools", () => {
353438
expect(result.isError).toBe(true);
354439
expect(result.content[0].text).toContain("Error fetching wiki page content: Stream read error");
355440
});
441+
442+
it("should handle unknown error type correctly", async () => {
443+
configureWikiTools(server, tokenProvider, connectionProvider);
444+
const call = (server.tool as jest.Mock).mock.calls.find(([toolName]) => toolName === "wiki_get_page_content");
445+
if (!call) throw new Error("wiki_get_page_content tool not registered");
446+
const [, , , handler] = call;
447+
448+
mockWikiApi.getPageText.mockRejectedValue("string error");
449+
450+
const params = {
451+
wikiIdentifier: "wiki1",
452+
project: "proj1",
453+
path: "/page1",
454+
};
455+
456+
const result = await handler(params);
457+
458+
expect(mockWikiApi.getPageText).toHaveBeenCalled();
459+
expect(result.isError).toBe(true);
460+
expect(result.content[0].text).toContain("Error fetching wiki page content: Unknown error occurred");
461+
});
356462
});
357463
});

0 commit comments

Comments
 (0)