@@ -984,3 +984,112 @@ func Test_ParseISOTimestamp(t *testing.T) {
984984 })
985985 }
986986}
987+
988+ func Test_GetIssueComments (t * testing.T ) {
989+ // Verify tool definition once
990+ mockClient := github .NewClient (nil )
991+ tool , _ := getIssueComments (mockClient , translations .NullTranslationHelper )
992+
993+ assert .Equal (t , "get_issue_comments" , tool .Name )
994+ assert .NotEmpty (t , tool .Description )
995+ assert .Contains (t , tool .InputSchema .Properties , "owner" )
996+ assert .Contains (t , tool .InputSchema .Properties , "repo" )
997+ assert .Contains (t , tool .InputSchema .Properties , "issue_number" )
998+ assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" , "issue_number" })
999+
1000+ // Setup mock comments for success case
1001+ mockComments := []* github.IssueComment {
1002+ {
1003+ ID : github .Ptr (int64 (123 )),
1004+ Body : github .Ptr ("This is the first comment" ),
1005+ User : & github.User {
1006+ Login : github .Ptr ("user1" ),
1007+ },
1008+ CreatedAt : & github.Timestamp {Time : time .Now ().Add (- time .Hour * 24 )},
1009+ },
1010+ {
1011+ ID : github .Ptr (int64 (456 )),
1012+ Body : github .Ptr ("This is the second comment" ),
1013+ User : & github.User {
1014+ Login : github .Ptr ("user2" ),
1015+ },
1016+ CreatedAt : & github.Timestamp {Time : time .Now ().Add (- time .Hour )},
1017+ },
1018+ }
1019+
1020+ tests := []struct {
1021+ name string
1022+ mockedClient * http.Client
1023+ requestArgs map [string ]interface {}
1024+ expectError bool
1025+ expectedComments []* github.IssueComment
1026+ expectedErrMsg string
1027+ }{
1028+ {
1029+ name : "successful comments retrieval" ,
1030+ mockedClient : mock .NewMockedHTTPClient (
1031+ mock .WithRequestMatch (
1032+ mock .GetReposIssuesCommentsByOwnerByRepoByIssueNumber ,
1033+ mockComments ,
1034+ ),
1035+ ),
1036+ requestArgs : map [string ]interface {}{
1037+ "owner" : "owner" ,
1038+ "repo" : "repo" ,
1039+ "issue_number" : float64 (42 ),
1040+ },
1041+ expectError : false ,
1042+ expectedComments : mockComments ,
1043+ },
1044+ {
1045+ name : "issue not found" ,
1046+ mockedClient : mock .NewMockedHTTPClient (
1047+ mock .WithRequestMatchHandler (
1048+ mock .GetReposIssuesCommentsByOwnerByRepoByIssueNumber ,
1049+ mockResponse (t , http .StatusNotFound , `{"message": "Issue not found"}` ),
1050+ ),
1051+ ),
1052+ requestArgs : map [string ]interface {}{
1053+ "owner" : "owner" ,
1054+ "repo" : "repo" ,
1055+ "issue_number" : float64 (999 ),
1056+ },
1057+ expectError : true ,
1058+ expectedErrMsg : "failed to get issue comments" ,
1059+ },
1060+ }
1061+
1062+ for _ , tc := range tests {
1063+ t .Run (tc .name , func (t * testing.T ) {
1064+ // Setup client with mock
1065+ client := github .NewClient (tc .mockedClient )
1066+ _ , handler := getIssueComments (client , translations .NullTranslationHelper )
1067+
1068+ // Create call request
1069+ request := createMCPRequest (tc .requestArgs )
1070+
1071+ // Call handler
1072+ result , err := handler (context .Background (), request )
1073+
1074+ // Verify results
1075+ if tc .expectError {
1076+ require .Error (t , err )
1077+ assert .Contains (t , err .Error (), tc .expectedErrMsg )
1078+ return
1079+ }
1080+
1081+ require .NoError (t , err )
1082+ textContent := getTextResult (t , result )
1083+
1084+ // Unmarshal and verify the result
1085+ var returnedComments []* github.IssueComment
1086+ err = json .Unmarshal ([]byte (textContent .Text ), & returnedComments )
1087+ require .NoError (t , err )
1088+ assert .Equal (t , len (tc .expectedComments ), len (returnedComments ))
1089+ if len (returnedComments ) > 0 {
1090+ assert .Equal (t , * tc .expectedComments [0 ].Body , * returnedComments [0 ].Body )
1091+ assert .Equal (t , * tc .expectedComments [0 ].User .Login , * returnedComments [0 ].User .Login )
1092+ }
1093+ })
1094+ }
1095+ }
0 commit comments