@@ -61,28 +61,31 @@ func Test_ListDiscussions(t *testing.T) {
6161 assert .ElementsMatch (t , toolDef .InputSchema .Required , []string {"owner" , "repo" })
6262
6363 // Use exact string queries that match implementation output (from error messages)
64- qDiscussions := "query($first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first){nodes{number,title,createdAt,category{name},url},pageInfo{hasNextPage,endCursor}}}}"
64+ qDiscussions := "query($after:String$ first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after ){nodes{number,title,createdAt,category{name},url},pageInfo{hasNextPage,endCursor}}}}"
6565
66- qDiscussionsFiltered := "query($categoryId:ID!$first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, categoryId: $categoryId){nodes{number,title,createdAt,category{name},url},pageInfo{hasNextPage,endCursor}}}}"
66+ qDiscussionsFiltered := "query($after:String$ categoryId:ID!$first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after , categoryId: $categoryId){nodes{number,title,createdAt,category{name},url},pageInfo{hasNextPage,endCursor}}}}"
6767
6868 // Variables matching what GraphQL receives after JSON marshaling/unmarshaling
6969 varsListAll := map [string ]interface {}{
7070 "owner" : "owner" ,
7171 "repo" : "repo" ,
7272 "first" : float64 (30 ),
73+ "after" : (* string )(nil ),
7374 }
7475
7576 varsRepoNotFound := map [string ]interface {}{
7677 "owner" : "owner" ,
7778 "repo" : "nonexistent-repo" ,
7879 "first" : float64 (30 ),
80+ "after" : (* string )(nil ),
7981 }
8082
8183 varsDiscussionsFiltered := map [string ]interface {}{
8284 "owner" : "owner" ,
8385 "repo" : "repo" ,
8486 "categoryId" : "DIC_kwDOABC123" ,
8587 "first" : float64 (30 ),
88+ "after" : (* string )(nil ),
8689 }
8790
8891 tests := []struct {
@@ -155,15 +158,21 @@ func Test_ListDiscussions(t *testing.T) {
155158 require .NoError (t , err )
156159
157160 // Parse the structured response with pagination info
158- var returnedDiscussions []* github.Discussion
159- err = json .Unmarshal ([]byte (text ), & returnedDiscussions )
161+ var response struct {
162+ Discussions []* github.Discussion `json:"discussions"`
163+ PageInfo struct {
164+ HasNextPage bool `json:"hasNextPage"`
165+ EndCursor string `json:"endCursor"`
166+ } `json:"pageInfo"`
167+ }
168+ err = json .Unmarshal ([]byte (text ), & response )
160169 require .NoError (t , err )
161170
162- assert .Len (t , returnedDiscussions , tc .expectedCount , "Expected %d discussions, got %d" , tc .expectedCount , len (returnedDiscussions ))
171+ assert .Len (t , response . Discussions , tc .expectedCount , "Expected %d discussions, got %d" , tc .expectedCount , len (response . Discussions ))
163172
164173 // Verify that all returned discussions have a category if filtered
165174 if _ , hasCategory := tc .reqParams ["category" ]; hasCategory {
166- for _ , discussion := range returnedDiscussions {
175+ for _ , discussion := range response . Discussions {
167176 require .NotNil (t , discussion .DiscussionCategory , "Discussion should have category" )
168177 assert .NotEmpty (t , * discussion .DiscussionCategory .Name , "Discussion should have category name" )
169178 }
@@ -266,14 +275,15 @@ func Test_GetDiscussionComments(t *testing.T) {
266275 assert .ElementsMatch (t , toolDef .InputSchema .Required , []string {"owner" , "repo" , "discussionNumber" })
267276
268277 // Use exact string query that matches implementation output
269- qGetComments := "query($discussionNumber:Int!$first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussion(number: $discussionNumber){comments(first: $first){nodes{body},pageInfo{hasNextPage,endCursor}}}}}"
278+ qGetComments := "query($after:String$ discussionNumber:Int!$first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussion(number: $discussionNumber){comments(first: $first, after: $after ){nodes{body},pageInfo{hasNextPage,endCursor}}}}}"
270279
271280 // Variables matching what GraphQL receives after JSON marshaling/unmarshaling
272281 vars := map [string ]interface {}{
273282 "owner" : "owner" ,
274283 "repo" : "repo" ,
275284 "discussionNumber" : float64 (1 ),
276285 "first" : float64 (100 ),
286+ "after" : (* string )(nil ),
277287 }
278288
279289 mockResponse := githubv4mock .DataResponse (map [string ]any {
@@ -311,25 +321,32 @@ func Test_GetDiscussionComments(t *testing.T) {
311321 // Debug: print the actual JSON response
312322 t .Logf ("JSON response: %s" , textContent .Text )
313323
314- var comments []* github.IssueComment
315- err = json .Unmarshal ([]byte (textContent .Text ), & comments )
324+ var response struct {
325+ Comments []* github.IssueComment `json:"comments"`
326+ PageInfo struct {
327+ HasNextPage bool `json:"hasNextPage"`
328+ EndCursor string `json:"endCursor"`
329+ } `json:"pageInfo"`
330+ }
331+ err = json .Unmarshal ([]byte (textContent .Text ), & response )
316332 require .NoError (t , err )
317- assert .Len (t , comments , 2 )
333+ assert .Len (t , response . Comments , 2 )
318334 expectedBodies := []string {"This is the first comment" , "This is the second comment" }
319- for i , comment := range comments {
335+ for i , comment := range response . Comments {
320336 assert .Equal (t , expectedBodies [i ], * comment .Body )
321337 }
322338}
323339
324340func Test_ListDiscussionCategories (t * testing.T ) {
325341 // Use exact string query that matches implementation output
326- qListCategories := "query($first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussionCategories(first: $first){nodes{id,name},pageInfo{hasNextPage,endCursor}}}}"
342+ qListCategories := "query($after:String$ first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussionCategories(first: $first, after: $after ){nodes{id,name},pageInfo{hasNextPage,endCursor}}}}"
327343
328344 // Variables matching what GraphQL receives after JSON marshaling/unmarshaling
329345 vars := map [string ]interface {}{
330346 "owner" : "owner" ,
331347 "repo" : "repo" ,
332348 "first" : float64 (100 ),
349+ "after" : (* string )(nil ),
333350 }
334351
335352 mockResp := githubv4mock .DataResponse (map [string ]any {
@@ -366,11 +383,17 @@ func Test_ListDiscussionCategories(t *testing.T) {
366383 // Debug: print the actual JSON response
367384 t .Logf ("JSON response: %s" , text )
368385
369- var categories []map [string ]string
370- require .NoError (t , json .Unmarshal ([]byte (text ), & categories ))
371- assert .Len (t , categories , 2 )
372- assert .Equal (t , "123" , categories [0 ]["id" ])
373- assert .Equal (t , "CategoryOne" , categories [0 ]["name" ])
374- assert .Equal (t , "456" , categories [1 ]["id" ])
375- assert .Equal (t , "CategoryTwo" , categories [1 ]["name" ])
386+ var response struct {
387+ Categories []map [string ]string `json:"categories"`
388+ PageInfo struct {
389+ HasNextPage bool `json:"hasNextPage"`
390+ EndCursor string `json:"endCursor"`
391+ } `json:"pageInfo"`
392+ }
393+ require .NoError (t , json .Unmarshal ([]byte (text ), & response ))
394+ assert .Len (t , response .Categories , 2 )
395+ assert .Equal (t , "123" , response .Categories [0 ]["id" ])
396+ assert .Equal (t , "CategoryOne" , response .Categories [0 ]["name" ])
397+ assert .Equal (t , "456" , response .Categories [1 ]["id" ])
398+ assert .Equal (t , "CategoryTwo" , response .Categories [1 ]["name" ])
376399}
0 commit comments