MCPcopy
hub / github.com/cli/cli / TestUpdate

Function TestUpdate

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

Source from the content-addressed store, hash-verified

3124}
3125
3126func TestUpdate(t *testing.T) {
3127 repo := ghrepo.New("OWNER", "REPO")
3128
3129 titleStr := "Updated title"
3130 bodyStr := "Updated body"
3131 catID := "CAT_2"
3132
3133 tests := []struct {
3134 name string
3135 input UpdateDiscussionInput
3136 httpStubs func(*testing.T, *httpmock.Registry)
3137 wantErr string
3138 assertDisc *Discussion
3139 }{
3140 {
3141 name: "nothing to update",
3142 input: UpdateDiscussionInput{
3143 DiscussionID: "D_1",
3144 },
3145 wantErr: "nothing to update",
3146 },
3147 {
3148 name: "maps all fields",
3149 input: UpdateDiscussionInput{
3150 DiscussionID: "D_1",
3151 Title: &titleStr,
3152 Body: &bodyStr,
3153 CategoryID: &catID,
3154 AddLabelIDs: []string{"L_bug", "L_enh"},
3155 RemoveLabelIDs: []string{"L_old", "L_stale"},
3156 },
3157 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
3158 reg.Register(
3159 httpmock.GraphQL(`mutation UpdateDiscussion\b`),
3160 httpmock.StringResponse(heredoc.Doc(`
3161 {
3162 "data": {
3163 "updateDiscussion": {
3164 "discussion": {
3165 "id": "D_1",
3166 "number": 5,
3167 "title": "Updated title",
3168 "body": "Updated body",
3169 "url": "https://github.com/OWNER/REPO/discussions/5",
3170 "closed": false,
3171 "stateReason": "",
3172 "isAnswered": false,
3173 "answerChosenAt": "0001-01-01T00:00:00Z",
3174 "author": {"__typename": "User", "login": "alice", "id": "U1", "name": "Alice"},
3175 "category": {"id": "CAT_2", "name": "Q&A", "slug": "q-a", "emoji": ":question:", "isAnswerable": true},
3176 "answerChosenBy": null,
3177 "labels": {"nodes": [{"id": "L_bug", "name": "bug", "color": "d73a4a"}, {"id": "L_enh", "name": "enhancement", "color": "a2eeef"}]},
3178 "reactionGroups": [{"content": "THUMBS_UP", "users": {"totalCount": 0}}],
3179 "createdAt": "2025-06-01T00:00:00Z",
3180 "updatedAt": "2025-06-02T00:00:00Z",
3181 "closedAt": "0001-01-01T00:00:00Z",
3182 "locked": false
3183 }

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected