MCPcopy
hub / github.com/cli/cli / TestUpdateComment

Function TestUpdateComment

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

Source from the content-addressed store, hash-verified

3545}
3546
3547func TestUpdateComment(t *testing.T) {
3548 tests := []struct {
3549 name string
3550 commentID string
3551 body string
3552 httpStubs func(*testing.T, *httpmock.Registry)
3553 wantErr string
3554 wantComment *DiscussionComment
3555 }{
3556 {
3557 name: "updates comment body",
3558 commentID: "DC_1",
3559 body: "Updated body",
3560 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
3561 reg.Register(
3562 httpmock.GraphQLMutationMatcher(`mutation UpdateDiscussionComment\b`, func(input map[string]interface{}) bool {
3563 assert.Equal(t, "DC_1", input["commentId"])
3564 assert.Equal(t, "Updated body", input["body"])
3565 return true
3566 }),
3567 httpmock.StringResponse(`{
3568 "data": {
3569 "updateDiscussionComment": {
3570 "comment": {
3571 "id": "DC_1",
3572 "url": "https://github.com/OWNER/REPO/discussions/1#discussioncomment-1",
3573 "author": {"__typename": "User", "login": "monalisa", "id": "U1", "name": "Mona"},
3574 "body": "Updated body",
3575 "createdAt": "2025-06-01T00:00:00Z",
3576 "isAnswer": true,
3577 "upvoteCount": 5,
3578 "reactionGroups": [{"content": "HEART", "users": {"totalCount": 3}}]
3579 }
3580 }
3581 }
3582 }`),
3583 )
3584 },
3585 wantComment: &DiscussionComment{
3586 ID: "DC_1",
3587 URL: "https://github.com/OWNER/REPO/discussions/1#discussioncomment-1",
3588 Author: DiscussionActor{ID: "U1", Login: "monalisa", Name: "Mona"},
3589 Body: "Updated body",
3590 CreatedAt: time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC),
3591 IsAnswer: true,
3592 UpvoteCount: 5,
3593 ReactionGroups: []ReactionGroup{{Content: "HEART", TotalCount: 3}},
3594 },
3595 },
3596 {
3597 name: "mutation error",
3598 commentID: "DC_bad",
3599 body: "text",
3600 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
3601 reg.Register(
3602 httpmock.GraphQL(`mutation UpdateDiscussionComment\b`),
3603 httpmock.StringResponse(`{"data":null,"errors":[{"message":"not found"}]}`),
3604 )

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
UpdateCommentMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected