@@ -10,9 +10,8 @@ import {
1010const mockState = vi . hoisted ( ( ) => ( {
1111 resolveGraphToken : vi . fn ( ) ,
1212 fetchGraphJson : vi . fn ( ) ,
13- postGraphJson : vi . fn ( ) ,
13+ mutateGraphJson : vi . fn ( ) ,
1414 deleteGraphRequest : vi . fn ( ) ,
15- patchGraphJson : vi . fn ( ) ,
1615 findPreferredDmByUserId : vi . fn ( ) ,
1716} ) ) ;
1817
@@ -22,9 +21,8 @@ vi.mock("./graph.js", async (importOriginal) => {
2221 ...actual ,
2322 resolveGraphToken : mockState . resolveGraphToken ,
2423 fetchGraphJson : mockState . fetchGraphJson ,
25- postGraphJson : mockState . postGraphJson ,
24+ mutateGraphJson : mockState . mutateGraphJson ,
2625 deleteGraphRequest : mockState . deleteGraphRequest ,
27- patchGraphJson : mockState . patchGraphJson ,
2826 } ;
2927} ) ;
3028
3937const CHANNEL_TO = "team-id-1/channel-id-1" ;
4038
4139function postGraphBodyAt ( index : number ) : Record < string , unknown > {
42- const call = mockState . postGraphJson . mock . calls [ index ] ;
40+ const call = mockState . mutateGraphJson . mock . calls [ index ] ;
4341 if ( ! call ) {
4442 throw new Error ( `expected Graph post call ${ index } ` ) ;
4543 }
@@ -57,7 +55,7 @@ describe("addParticipantMSTeams", () => {
5755 } ) ;
5856
5957 it ( "maps the default chat member role to Graph owner" , async ( ) => {
60- mockState . postGraphJson . mockResolvedValue ( { } ) ;
58+ mockState . mutateGraphJson . mockResolvedValue ( { } ) ;
6159
6260 const result = await addParticipantMSTeams ( {
6361 cfg : { } as OpenClawConfig ,
@@ -66,9 +64,10 @@ describe("addParticipantMSTeams", () => {
6664 } ) ;
6765
6866 expect ( result ) . toEqual ( { added : { userId : "user-aad-id-1" , chatId : CHAT_ID } } ) ;
69- expect ( mockState . postGraphJson ) . toHaveBeenCalledWith ( {
67+ expect ( mockState . mutateGraphJson ) . toHaveBeenCalledWith ( {
7068 token : TOKEN ,
7169 path : `/chats/${ encodeURIComponent ( CHAT_ID ) } /members` ,
70+ method : "POST" ,
7271 body : {
7372 "@odata.type" : "#microsoft.graph.aadUserConversationMember" ,
7473 roles : [ "owner" ] ,
@@ -78,7 +77,7 @@ describe("addParticipantMSTeams", () => {
7877 } ) ;
7978
8079 it ( "adds member to a chat with owner role" , async ( ) => {
81- mockState . postGraphJson . mockResolvedValue ( { } ) ;
80+ mockState . mutateGraphJson . mockResolvedValue ( { } ) ;
8281
8382 const result = await addParticipantMSTeams ( {
8483 cfg : { } as OpenClawConfig ,
@@ -88,9 +87,10 @@ describe("addParticipantMSTeams", () => {
8887 } ) ;
8988
9089 expect ( result ) . toEqual ( { added : { userId : "user-aad-id-2" , chatId : CHAT_ID } } ) ;
91- expect ( mockState . postGraphJson ) . toHaveBeenCalledWith ( {
90+ expect ( mockState . mutateGraphJson ) . toHaveBeenCalledWith ( {
9291 token : TOKEN ,
9392 path : `/chats/${ encodeURIComponent ( CHAT_ID ) } /members` ,
93+ method : "POST" ,
9494 body : {
9595 "@odata.type" : "#microsoft.graph.aadUserConversationMember" ,
9696 roles : [ "owner" ] ,
@@ -100,7 +100,7 @@ describe("addParticipantMSTeams", () => {
100100 } ) ;
101101
102102 it ( "normalizes role casing and whitespace" , async ( ) => {
103- mockState . postGraphJson . mockResolvedValue ( { } ) ;
103+ mockState . mutateGraphJson . mockResolvedValue ( { } ) ;
104104
105105 await addParticipantMSTeams ( {
106106 cfg : { } as OpenClawConfig ,
@@ -109,9 +109,10 @@ describe("addParticipantMSTeams", () => {
109109 role : " OWNER " ,
110110 } ) ;
111111
112- expect ( mockState . postGraphJson ) . toHaveBeenCalledWith ( {
112+ expect ( mockState . mutateGraphJson ) . toHaveBeenCalledWith ( {
113113 token : TOKEN ,
114114 path : `/chats/${ encodeURIComponent ( CHAT_ID ) } /members` ,
115+ method : "POST" ,
115116 body : {
116117 "@odata.type" : "#microsoft.graph.aadUserConversationMember" ,
117118 roles : [ "owner" ] ,
@@ -130,11 +131,11 @@ describe("addParticipantMSTeams", () => {
130131 } ) ,
131132 ) . rejects . toThrow ( 'role must be "member" or "owner"' ) ;
132133
133- expect ( mockState . postGraphJson ) . not . toHaveBeenCalled ( ) ;
134+ expect ( mockState . mutateGraphJson ) . not . toHaveBeenCalled ( ) ;
134135 } ) ;
135136
136137 it ( "constructs correct [email protected] URL" , async ( ) => { 137- mockState . postGraphJson . mockResolvedValue ( { } ) ;
138+ mockState . mutateGraphJson . mockResolvedValue ( { } ) ;
138139
139140 await addParticipantMSTeams ( {
140141 cfg : { } as OpenClawConfig ,
@@ -149,7 +150,7 @@ describe("addParticipantMSTeams", () => {
149150 } ) ;
150151
151152 it ( "escapes user ids before building the OData bind URL" , async ( ) => {
152- mockState . postGraphJson . mockResolvedValue ( { } ) ;
153+ mockState . mutateGraphJson . mockResolvedValue ( { } ) ;
153154
154155 await addParticipantMSTeams ( {
155156 cfg : { } as OpenClawConfig ,
@@ -164,7 +165,7 @@ describe("addParticipantMSTeams", () => {
164165 } ) ;
165166
166167 it ( "maps the default channel member role to an empty Graph role list" , async ( ) => {
167- mockState . postGraphJson . mockResolvedValue ( { } ) ;
168+ mockState . mutateGraphJson . mockResolvedValue ( { } ) ;
168169
169170 const result = await addParticipantMSTeams ( {
170171 cfg : { } as OpenClawConfig ,
@@ -173,9 +174,10 @@ describe("addParticipantMSTeams", () => {
173174 } ) ;
174175
175176 expect ( result ) . toEqual ( { added : { userId : "user-aad-id-3" , chatId : CHANNEL_TO } } ) ;
176- expect ( mockState . postGraphJson ) . toHaveBeenCalledWith ( {
177+ expect ( mockState . mutateGraphJson ) . toHaveBeenCalledWith ( {
177178 token : TOKEN ,
178179 path : "/teams/team-id-1/channels/channel-id-1/members" ,
180+ method : "POST" ,
179181 body : {
180182 "@odata.type" : "#microsoft.graph.aadUserConversationMember" ,
181183 roles : [ ] ,
@@ -185,7 +187,7 @@ describe("addParticipantMSTeams", () => {
185187 } ) ;
186188
187189 it ( "preserves the owner role for a channel" , async ( ) => {
188- mockState . postGraphJson . mockResolvedValue ( { } ) ;
190+ mockState . mutateGraphJson . mockResolvedValue ( { } ) ;
189191
190192 await addParticipantMSTeams ( {
191193 cfg : { } as OpenClawConfig ,
@@ -194,9 +196,10 @@ describe("addParticipantMSTeams", () => {
194196 role : "owner" ,
195197 } ) ;
196198
197- expect ( mockState . postGraphJson ) . toHaveBeenCalledWith ( {
199+ expect ( mockState . mutateGraphJson ) . toHaveBeenCalledWith ( {
198200 token : TOKEN ,
199201 path : "/teams/team-id-1/channels/channel-id-1/members" ,
202+ method : "POST" ,
200203 body : {
201204 "@odata.type" : "#microsoft.graph.aadUserConversationMember" ,
202205 roles : [ "owner" ] ,
@@ -319,7 +322,7 @@ describe("renameGroupMSTeams", () => {
319322 } ) ;
320323
321324 it ( "renames a chat with topic" , async ( ) => {
322- mockState . patchGraphJson . mockResolvedValue ( undefined ) ;
325+ mockState . mutateGraphJson . mockResolvedValue ( undefined ) ;
323326
324327 const result = await renameGroupMSTeams ( {
325328 cfg : { } as OpenClawConfig ,
@@ -328,15 +331,16 @@ describe("renameGroupMSTeams", () => {
328331 } ) ;
329332
330333 expect ( result ) . toEqual ( { renamed : { chatId : CHAT_ID , newName : "New Chat Name" } } ) ;
331- expect ( mockState . patchGraphJson ) . toHaveBeenCalledWith ( {
334+ expect ( mockState . mutateGraphJson ) . toHaveBeenCalledWith ( {
332335 token : TOKEN ,
333336 path : `/chats/${ encodeURIComponent ( CHAT_ID ) } ` ,
337+ method : "PATCH" ,
334338 body : { topic : "New Chat Name" } ,
335339 } ) ;
336340 } ) ;
337341
338342 it ( "renames a channel with displayName" , async ( ) => {
339- mockState . patchGraphJson . mockResolvedValue ( undefined ) ;
343+ mockState . mutateGraphJson . mockResolvedValue ( undefined ) ;
340344
341345 const result = await renameGroupMSTeams ( {
342346 cfg : { } as OpenClawConfig ,
@@ -345,9 +349,10 @@ describe("renameGroupMSTeams", () => {
345349 } ) ;
346350
347351 expect ( result ) . toEqual ( { renamed : { chatId : CHANNEL_TO , newName : "New Channel Name" } } ) ;
348- expect ( mockState . patchGraphJson ) . toHaveBeenCalledWith ( {
352+ expect ( mockState . mutateGraphJson ) . toHaveBeenCalledWith ( {
349353 token : TOKEN ,
350354 path : "/teams/team-id-1/channels/channel-id-1" ,
355+ method : "PATCH" ,
351356 body : { displayName : "New Channel Name" } ,
352357 } ) ;
353358 } ) ;
0 commit comments