MCPcopy
hub / github.com/cli/cli / TestAddComment

Function TestAddComment

pkg/cmd/discussion/client/client_test.go:3416–3545  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3414}
3415
3416func TestAddComment(t *testing.T) {
3417 tests := []struct {
3418 name string
3419 discussionID string
3420 body string
3421 replyToID string
3422 httpStubs func(*testing.T, *httpmock.Registry)
3423 wantErr string
3424 wantComment *DiscussionComment
3425 }{
3426 {
3427 name: "adds top-level comment",
3428 discussionID: "D_123",
3429 body: "Hello world",
3430 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
3431 reg.Register(
3432 httpmock.GraphQLMutationMatcher(`mutation AddDiscussionComment\b`, func(input map[string]interface{}) bool {
3433 assert.Equal(t, "D_123", input["discussionId"])
3434 assert.Equal(t, "Hello world", input["body"])
3435 assert.Nil(t, input["replyToId"])
3436 return true
3437 }),
3438 httpmock.StringResponse(`{
3439 "data": {
3440 "addDiscussionComment": {
3441 "comment": {
3442 "id": "DC_1",
3443 "url": "https://github.com/OWNER/REPO/discussions/1#discussioncomment-1",
3444 "author": {"__typename": "User", "login": "monalisa", "id": "U1", "name": "Mona"},
3445 "body": "Hello world",
3446 "createdAt": "2025-06-01T00:00:00Z",
3447 "isAnswer": false,
3448 "upvoteCount": 1,
3449 "reactionGroups": [{"content": "THUMBS_UP", "users": {"totalCount": 0}}]
3450 }
3451 }
3452 }
3453 }`),
3454 )
3455 },
3456 wantComment: &DiscussionComment{
3457 ID: "DC_1",
3458 URL: "https://github.com/OWNER/REPO/discussions/1#discussioncomment-1",
3459 Author: DiscussionActor{ID: "U1", Login: "monalisa", Name: "Mona"},
3460 Body: "Hello world",
3461 CreatedAt: time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC),
3462 UpvoteCount: 1,
3463 ReactionGroups: []ReactionGroup{{Content: "THUMBS_UP", TotalCount: 0}},
3464 },
3465 },
3466 {
3467 name: "adds reply to comment",
3468 discussionID: "D_123",
3469 body: "Reply text",
3470 replyToID: "DC_parent",
3471 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
3472 reg.Register(
3473 httpmock.GraphQLMutationMatcher(`mutation AddDiscussionComment\b`, func(input map[string]interface{}) bool {

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
VerifyMethod · 0.95
GraphQLMutationMatcherFunction · 0.92
StringResponseFunction · 0.92
GraphQLFunction · 0.92
NewFunction · 0.92
newTestDiscussionClientFunction · 0.85
EqualMethod · 0.80
ContainsMethod · 0.80
RunMethod · 0.65
AddCommentMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected