(t *testing.T)
| 3414 | } |
| 3415 | |
| 3416 | func 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 { |
nothing calls this directly
no test coverage detected