(t *testing.T)
| 3634 | } |
| 3635 | |
| 3636 | func TestDeleteComment(t *testing.T) { |
| 3637 | tests := []struct { |
| 3638 | name string |
| 3639 | commentID string |
| 3640 | httpStubs func(*httpmock.Registry) |
| 3641 | wantErr string |
| 3642 | }{ |
| 3643 | { |
| 3644 | name: "deletes comment", |
| 3645 | commentID: "DC_1", |
| 3646 | httpStubs: func(reg *httpmock.Registry) { |
| 3647 | reg.Register( |
| 3648 | httpmock.GraphQL(`mutation DeleteDiscussionComment\b`), |
| 3649 | httpmock.StringResponse(`{"data":{"deleteDiscussionComment":{"comment":{"id":"DC_1"}}}}`), |
| 3650 | ) |
| 3651 | }, |
| 3652 | }, |
| 3653 | { |
| 3654 | name: "mutation error", |
| 3655 | commentID: "DC_bad", |
| 3656 | httpStubs: func(reg *httpmock.Registry) { |
| 3657 | reg.Register( |
| 3658 | httpmock.GraphQL(`mutation DeleteDiscussionComment\b`), |
| 3659 | httpmock.StringResponse(`{"data":null,"errors":[{"message":"not found"}]}`), |
| 3660 | ) |
| 3661 | }, |
| 3662 | wantErr: "not found", |
| 3663 | }, |
| 3664 | } |
| 3665 | |
| 3666 | for _, tt := range tests { |
| 3667 | t.Run(tt.name, func(t *testing.T) { |
| 3668 | reg := &httpmock.Registry{} |
| 3669 | defer reg.Verify(t) |
| 3670 | |
| 3671 | if tt.httpStubs != nil { |
| 3672 | tt.httpStubs(reg) |
| 3673 | } |
| 3674 | |
| 3675 | repo := ghrepo.New("OWNER", "REPO") |
| 3676 | c := newTestDiscussionClient(reg) |
| 3677 | err := c.DeleteComment(repo, tt.commentID) |
| 3678 | |
| 3679 | if tt.wantErr != "" { |
| 3680 | require.Error(t, err) |
| 3681 | assert.Contains(t, err.Error(), tt.wantErr) |
| 3682 | return |
| 3683 | } |
| 3684 | |
| 3685 | require.NoError(t, err) |
| 3686 | }) |
| 3687 | } |
| 3688 | } |
| 3689 | |
| 3690 | func TestGetComment(t *testing.T) { |
| 3691 | tests := []struct { |
nothing calls this directly
no test coverage detected