diff --git a/extensions/msteams/src/graph-messages.search.test.ts b/extensions/msteams/src/graph-messages.search.test.ts index 2b4dc7bcbb85..832f5eb7b6b1 100644 --- a/extensions/msteams/src/graph-messages.search.test.ts +++ b/extensions/msteams/src/graph-messages.search.test.ts @@ -17,6 +17,18 @@ beforeAll(async () => { ({ searchMessagesMSTeams } = await loadGraphMessagesTestModule()); }); +function readFirstGraphPath(): string { + const [call] = mockState.fetchGraphJson.mock.calls; + if (!call) { + throw new Error("Expected Graph fetch call"); + } + const [request] = call; + if (!request || typeof request !== "object" || typeof request.path !== "string") { + throw new Error("Expected Graph fetch request path"); + } + return request.path; +} + describe("searchMessagesMSTeams", () => { it("searches chat messages with query string", async () => { mockState.fetchGraphJson.mockResolvedValue({ @@ -44,7 +56,7 @@ describe("searchMessagesMSTeams", () => { createdAt: "2026-03-25T10:00:00Z", }, ]); - const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string; + const calledPath = readFirstGraphPath(); expect(calledPath).toContain(`/chats/${encodeURIComponent(CHAT_ID)}/messages?`); expect(calledPath).toContain("$search="); expect(calledPath).toContain("$top=25"); @@ -71,7 +83,7 @@ describe("searchMessagesMSTeams", () => { }); expect(result.messages).toHaveLength(1); - const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string; + const calledPath = readFirstGraphPath(); expect(calledPath).toContain("/teams/team-id-1/channels/channel-id-1/messages?"); }); @@ -85,7 +97,7 @@ describe("searchMessagesMSTeams", () => { limit: 10, }); - const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string; + const calledPath = readFirstGraphPath(); expect(calledPath).toContain("$top=10"); }); @@ -99,7 +111,7 @@ describe("searchMessagesMSTeams", () => { limit: 100, }); - const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string; + const calledPath = readFirstGraphPath(); expect(calledPath).toContain("$top=50"); }); @@ -113,7 +125,7 @@ describe("searchMessagesMSTeams", () => { limit: 0, }); - const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string; + const calledPath = readFirstGraphPath(); expect(calledPath).toContain("$top=1"); }); @@ -127,7 +139,7 @@ describe("searchMessagesMSTeams", () => { from: "Alice", }); - const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string; + const calledPath = readFirstGraphPath(); expect(calledPath).toContain("$filter="); const decoded = decodeURIComponent(calledPath); expect(decoded).toContain("from/user/displayName eq 'Alice'"); @@ -143,7 +155,7 @@ describe("searchMessagesMSTeams", () => { from: "O'Brien", }); - const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string; + const calledPath = readFirstGraphPath(); const decoded = decodeURIComponent(calledPath); expect(decoded).toContain("O''Brien"); }); @@ -157,7 +169,7 @@ describe("searchMessagesMSTeams", () => { query: 'say "hello" world', }); - const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string; + const calledPath = readFirstGraphPath(); const decoded = decodeURIComponent(calledPath); expect(decoded).toContain('$search="say hello world"'); expect(decoded).not.toContain('""'); @@ -207,7 +219,7 @@ describe("searchMessagesMSTeams", () => { }); expect(mockState.findPreferredDmByUserId).toHaveBeenCalledWith("aad-user-1"); - const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string; + const calledPath = readFirstGraphPath(); expect(calledPath).toContain( `/chats/${encodeURIComponent("19:dm-chat@thread.tacv2")}/messages?`, );