


























@@ -17,6 +17,18 @@ beforeAll(async () => {
1717({ searchMessagesMSTeams } = await loadGraphMessagesTestModule());
1818});
191920+function readFirstGraphPath(): string {
21+const [call] = mockState.fetchGraphJson.mock.calls;
22+if (!call) {
23+throw new Error("Expected Graph fetch call");
24+}
25+const [request] = call;
26+if (!request || typeof request !== "object" || typeof request.path !== "string") {
27+throw new Error("Expected Graph fetch request path");
28+}
29+return request.path;
30+}
31+2032describe("searchMessagesMSTeams", () => {
2133it("searches chat messages with query string", async () => {
2234mockState.fetchGraphJson.mockResolvedValue({
@@ -44,7 +56,7 @@ describe("searchMessagesMSTeams", () => {
4456createdAt: "2026-03-25T10:00:00Z",
4557},
4658]);
47-const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string;
59+const calledPath = readFirstGraphPath();
4860expect(calledPath).toContain(`/chats/${encodeURIComponent(CHAT_ID)}/messages?`);
4961expect(calledPath).toContain("$search=");
5062expect(calledPath).toContain("$top=25");
@@ -71,7 +83,7 @@ describe("searchMessagesMSTeams", () => {
7183});
72847385expect(result.messages).toHaveLength(1);
74-const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string;
86+const calledPath = readFirstGraphPath();
7587expect(calledPath).toContain("/teams/team-id-1/channels/channel-id-1/messages?");
7688});
7789@@ -85,7 +97,7 @@ describe("searchMessagesMSTeams", () => {
8597limit: 10,
8698});
879988-const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string;
100+const calledPath = readFirstGraphPath();
89101expect(calledPath).toContain("$top=10");
90102});
91103@@ -99,7 +111,7 @@ describe("searchMessagesMSTeams", () => {
99111limit: 100,
100112});
101113102-const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string;
114+const calledPath = readFirstGraphPath();
103115expect(calledPath).toContain("$top=50");
104116});
105117@@ -113,7 +125,7 @@ describe("searchMessagesMSTeams", () => {
113125limit: 0,
114126});
115127116-const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string;
128+const calledPath = readFirstGraphPath();
117129expect(calledPath).toContain("$top=1");
118130});
119131@@ -127,7 +139,7 @@ describe("searchMessagesMSTeams", () => {
127139from: "Alice",
128140});
129141130-const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string;
142+const calledPath = readFirstGraphPath();
131143expect(calledPath).toContain("$filter=");
132144const decoded = decodeURIComponent(calledPath);
133145expect(decoded).toContain("from/user/displayName eq 'Alice'");
@@ -143,7 +155,7 @@ describe("searchMessagesMSTeams", () => {
143155from: "O'Brien",
144156});
145157146-const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string;
158+const calledPath = readFirstGraphPath();
147159const decoded = decodeURIComponent(calledPath);
148160expect(decoded).toContain("O''Brien");
149161});
@@ -157,7 +169,7 @@ describe("searchMessagesMSTeams", () => {
157169query: 'say "hello" world',
158170});
159171160-const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string;
172+const calledPath = readFirstGraphPath();
161173const decoded = decodeURIComponent(calledPath);
162174expect(decoded).toContain('$search="say hello world"');
163175expect(decoded).not.toContain('""');
@@ -207,7 +219,7 @@ describe("searchMessagesMSTeams", () => {
207219});
208220209221expect(mockState.findPreferredDmByUserId).toHaveBeenCalledWith("aad-user-1");
210-const calledPath = mockState.fetchGraphJson.mock.calls[0][0].path as string;
222+const calledPath = readFirstGraphPath();
211223expect(calledPath).toContain(
212224`/chats/${encodeURIComponent("19:dm-chat@thread.tacv2")}/messages?`,
213225);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。