MCPcopy
hub / github.com/cli/cli / TestResolveCommentNodeID

Function TestResolveCommentNodeID

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

Source from the content-addressed store, hash-verified

3785}
3786
3787func TestResolveCommentNodeID(t *testing.T) {
3788 tests := []struct {
3789 name string
3790 commentDatabaseID int64
3791 httpStubs func(*httpmock.Registry)
3792 wantNodeID string
3793 wantErr string
3794 }{
3795 {
3796 name: "encodes node ID correctly",
3797 commentDatabaseID: 17196842,
3798 httpStubs: func(reg *httpmock.Registry) {
3799 reg.Register(
3800 httpmock.GraphQL(`query RepositoryMetaForDiscussions\b`),
3801 httpmock.StringResponse(repoMetaResp("R_1", true)),
3802 )
3803 },
3804 wantNodeID: "DC_kwDOOokwWs4BBmcq",
3805 },
3806 {
3807 name: "repo not found",
3808 commentDatabaseID: 123,
3809 httpStubs: func(reg *httpmock.Registry) {
3810 reg.Register(
3811 httpmock.GraphQL(`query RepositoryMetaForDiscussions\b`),
3812 httpmock.StringResponse(`{"data":null,"errors":[{"message":"repo not found"}]}`),
3813 )
3814 },
3815 wantErr: "repo not found",
3816 },
3817 }
3818
3819 for _, tt := range tests {
3820 t.Run(tt.name, func(t *testing.T) {
3821 repo := ghrepo.New("OWNER", "REPO")
3822 reg := &httpmock.Registry{}
3823 defer reg.Verify(t)
3824
3825 if tt.httpStubs != nil {
3826 tt.httpStubs(reg)
3827 }
3828
3829 c := newTestDiscussionClient(reg)
3830 nodeID, err := c.ResolveCommentNodeID(repo, tt.commentDatabaseID)
3831
3832 if tt.wantErr != "" {
3833 require.Error(t, err)
3834 assert.Contains(t, err.Error(), tt.wantErr)
3835 return
3836 }
3837
3838 require.NoError(t, err)
3839 assert.Equal(t, tt.wantNodeID, nodeID)
3840 })
3841 }
3842}

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected