@@ -367,3 +367,61 @@ func TestSendMessageContextRedactsTokenInDebugLog(t *testing.T) {
367367 })
368368 }
369369}
370+
371+ func TestUpdateMessage (t * testing.T ) {
372+ type messageTest struct {
373+ endpoint string
374+ opt []MsgOption
375+ expected url.Values
376+ }
377+ tests := map [string ]messageTest {
378+ "empty file_ids" : {
379+ endpoint : "/chat.update" ,
380+ opt : []MsgOption {},
381+ expected : url.Values {
382+ "channel" : []string {"CXXX" },
383+ "token" : []string {"testing-token" },
384+ "ts" : []string {"1234567890.123456" },
385+ },
386+ },
387+ "with file_ids" : {
388+ endpoint : "/chat.update" ,
389+ opt : []MsgOption {
390+ MsgOptionFileIDs ([]string {"F123" , "F456" }),
391+ },
392+ expected : url.Values {
393+ "channel" : []string {"CXXX" },
394+ "token" : []string {"testing-token" },
395+ "ts" : []string {"1234567890.123456" },
396+ "file_ids" : []string {`["F123","F456"]` },
397+ },
398+ },
399+ }
400+
401+ once .Do (startServer )
402+ api := New (validToken , OptionAPIURL ("http://" + serverAddr + "/" ))
403+
404+ for name , test := range tests {
405+ t .Run (name , func (t * testing.T ) {
406+ http .DefaultServeMux = new (http.ServeMux )
407+ http .HandleFunc (test .endpoint , func (rw http.ResponseWriter , r * http.Request ) {
408+ body , err := io .ReadAll (r .Body )
409+ if err != nil {
410+ t .Errorf ("unexpected error: %v" , err )
411+ return
412+ }
413+ actual , err := url .ParseQuery (string (body ))
414+ if err != nil {
415+ t .Errorf ("unexpected error: %v" , err )
416+ return
417+ }
418+ if ! reflect .DeepEqual (actual , test .expected ) {
419+ t .Errorf ("\n expected: %s\n actual: %s" , test .expected , actual )
420+ return
421+ }
422+ })
423+
424+ _ , _ , _ , _ = api .UpdateMessage ("CXXX" , "1234567890.123456" , test .opt ... )
425+ })
426+ }
427+ }
0 commit comments