MCPcopy Index your code
hub / github.com/github/github-mcp-server / Test_GetDiscussionComments

Function Test_GetDiscussionComments

pkg/github/discussions_test.go:637–724  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

635}
636
637func Test_GetDiscussionComments(t *testing.T) {
638 // Verify tool definition and schema
639 toolDef := GetDiscussionComments(translations.NullTranslationHelper)
640 tool := toolDef.Tool
641 require.NoError(t, toolsnaps.Test(tool.Name, tool))
642
643 assert.Equal(t, "get_discussion_comments", tool.Name)
644 assert.NotEmpty(t, tool.Description)
645 schema, ok := tool.InputSchema.(*jsonschema.Schema)
646 require.True(t, ok, "InputSchema should be *jsonschema.Schema")
647 assert.Contains(t, schema.Properties, "owner")
648 assert.Contains(t, schema.Properties, "repo")
649 assert.Contains(t, schema.Properties, "discussionNumber")
650 assert.Contains(t, schema.Properties, "includeReplies")
651 assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "discussionNumber"})
652
653 // Use exact string query that matches implementation output
654 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{id,body,isAnswer},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}"
655
656 // Variables matching what GraphQL receives after JSON marshaling/unmarshaling
657 vars := map[string]any{
658 "owner": "owner",
659 "repo": "repo",
660 "discussionNumber": float64(1),
661 "first": float64(30),
662 "after": (*string)(nil),
663 }
664
665 mockResponse := githubv4mock.DataResponse(map[string]any{
666 "repository": map[string]any{
667 "discussion": map[string]any{
668 "comments": map[string]any{
669 "nodes": []map[string]any{
670 {"id": "DC_id1", "body": "This is the first comment"},
671 {"id": "DC_id2", "body": "This is the second comment"},
672 },
673 "pageInfo": map[string]any{
674 "hasNextPage": false,
675 "hasPreviousPage": false,
676 "startCursor": "",
677 "endCursor": "",
678 },
679 "totalCount": 2,
680 },
681 },
682 },
683 })
684 matcher := githubv4mock.NewQueryMatcher(qGetComments, vars, mockResponse)
685 httpClient := githubv4mock.NewMockedHTTPClient(matcher)
686 gqlClient := githubv4.NewClient(httpClient)
687 deps := BaseDeps{GQLClient: gqlClient}
688 handler := toolDef.Handler(deps)
689
690 reqParams := map[string]any{
691 "owner": "owner",
692 "repo": "repo",
693 "discussionNumber": int32(1),
694 }

Callers

nothing calls this directly

Calls 9

TestFunction · 0.92
DataResponseFunction · 0.92
NewQueryMatcherFunction · 0.92
NewMockedHTTPClientFunction · 0.92
GetDiscussionCommentsFunction · 0.85
createMCPRequestFunction · 0.85
ContextWithDepsFunction · 0.85
getTextResultFunction · 0.85
HandlerMethod · 0.45

Tested by

no test coverage detected