@@ -61,28 +61,31 @@ func Test_ListDiscussions(t *testing.T) {
61
61
assert .ElementsMatch (t , toolDef .InputSchema .Required , []string {"owner" , "repo" })
62
62
63
63
// 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}}}}"
65
65
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}}}}"
67
67
68
68
// Variables matching what GraphQL receives after JSON marshaling/unmarshaling
69
69
varsListAll := map [string ]interface {}{
70
70
"owner" : "owner" ,
71
71
"repo" : "repo" ,
72
72
"first" : float64 (30 ),
73
+ "after" : (* string )(nil ),
73
74
}
74
75
75
76
varsRepoNotFound := map [string ]interface {}{
76
77
"owner" : "owner" ,
77
78
"repo" : "nonexistent-repo" ,
78
79
"first" : float64 (30 ),
80
+ "after" : (* string )(nil ),
79
81
}
80
82
81
83
varsDiscussionsFiltered := map [string ]interface {}{
82
84
"owner" : "owner" ,
83
85
"repo" : "repo" ,
84
86
"categoryId" : "DIC_kwDOABC123" ,
85
87
"first" : float64 (30 ),
88
+ "after" : (* string )(nil ),
86
89
}
87
90
88
91
tests := []struct {
@@ -155,15 +158,21 @@ func Test_ListDiscussions(t *testing.T) {
155
158
require .NoError (t , err )
156
159
157
160
// 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 )
160
169
require .NoError (t , err )
161
170
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 ))
163
172
164
173
// Verify that all returned discussions have a category if filtered
165
174
if _ , hasCategory := tc .reqParams ["category" ]; hasCategory {
166
- for _ , discussion := range returnedDiscussions {
175
+ for _ , discussion := range response . Discussions {
167
176
require .NotNil (t , discussion .DiscussionCategory , "Discussion should have category" )
168
177
assert .NotEmpty (t , * discussion .DiscussionCategory .Name , "Discussion should have category name" )
169
178
}
@@ -266,14 +275,15 @@ func Test_GetDiscussionComments(t *testing.T) {
266
275
assert .ElementsMatch (t , toolDef .InputSchema .Required , []string {"owner" , "repo" , "discussionNumber" })
267
276
268
277
// 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}}}}}"
270
279
271
280
// Variables matching what GraphQL receives after JSON marshaling/unmarshaling
272
281
vars := map [string ]interface {}{
273
282
"owner" : "owner" ,
274
283
"repo" : "repo" ,
275
284
"discussionNumber" : float64 (1 ),
276
285
"first" : float64 (100 ),
286
+ "after" : (* string )(nil ),
277
287
}
278
288
279
289
mockResponse := githubv4mock .DataResponse (map [string ]any {
@@ -311,25 +321,32 @@ func Test_GetDiscussionComments(t *testing.T) {
311
321
// Debug: print the actual JSON response
312
322
t .Logf ("JSON response: %s" , textContent .Text )
313
323
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 )
316
332
require .NoError (t , err )
317
- assert .Len (t , comments , 2 )
333
+ assert .Len (t , response . Comments , 2 )
318
334
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 {
320
336
assert .Equal (t , expectedBodies [i ], * comment .Body )
321
337
}
322
338
}
323
339
324
340
func Test_ListDiscussionCategories (t * testing.T ) {
325
341
// 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}}}}"
327
343
328
344
// Variables matching what GraphQL receives after JSON marshaling/unmarshaling
329
345
vars := map [string ]interface {}{
330
346
"owner" : "owner" ,
331
347
"repo" : "repo" ,
332
348
"first" : float64 (100 ),
349
+ "after" : (* string )(nil ),
333
350
}
334
351
335
352
mockResp := githubv4mock .DataResponse (map [string ]any {
@@ -366,11 +383,17 @@ func Test_ListDiscussionCategories(t *testing.T) {
366
383
// Debug: print the actual JSON response
367
384
t .Logf ("JSON response: %s" , text )
368
385
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" ])
376
399
}
0 commit comments