MCPcopy
hub / github.com/cli/cli / TestCreate

Function TestCreate

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

Source from the content-addressed store, hash-verified

2353}
2354
2355func TestCreate(t *testing.T) {
2356 repo := ghrepo.New("OWNER", "REPO")
2357
2358 tests := []struct {
2359 name string
2360 input CreateDiscussionInput
2361 httpStubs func(*testing.T, *httpmock.Registry)
2362 wantErr string
2363 assertDisc *Discussion
2364 }{
2365 {
2366 name: "maps all fields",
2367 input: CreateDiscussionInput{
2368 CategoryID: "CAT_1",
2369 Title: "New Discussion",
2370 Body: "Discussion body",
2371 },
2372 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
2373 reg.Register(
2374 httpmock.GraphQL(`query RepositoryMetaForDiscussions\b`),
2375 httpmock.StringResponse(repoMetaResp("R_1", true)),
2376 )
2377 reg.Register(
2378 httpmock.GraphQLMutationMatcher(`mutation CreateDiscussion\b`, func(input map[string]interface{}) bool {
2379 assert.Equal(t, "R_1", input["repositoryId"])
2380 assert.Equal(t, "CAT_1", input["categoryId"])
2381 assert.Equal(t, "New Discussion", input["title"])
2382 assert.Equal(t, "Discussion body", input["body"])
2383 return true
2384 }),
2385 httpmock.StringResponse(heredoc.Doc(`
2386 {
2387 "data": {
2388 "createDiscussion": {
2389 "discussion": {
2390 "id": "D_new",
2391 "number": 99,
2392 "title": "New Discussion",
2393 "body": "Discussion body",
2394 "url": "https://github.com/OWNER/REPO/discussions/99",
2395 "closed": false,
2396 "stateReason": "",
2397 "isAnswered": false,
2398 "answerChosenAt": "0001-01-01T00:00:00Z",
2399 "author": {"__typename": "User", "login": "alice", "id": "U1", "name": "Alice"},
2400 "category": {"id": "CAT_1", "name": "General", "slug": "general", "emoji": ":speech_balloon:", "isAnswerable": false},
2401 "answerChosenBy": null,
2402 "labels": {"nodes": []},
2403 "reactionGroups": [{"content": "THUMBS_UP", "users": {"totalCount": 0}}],
2404 "createdAt": "2025-06-01T00:00:00Z",
2405 "updatedAt": "2025-06-01T00:00:00Z",
2406 "closedAt": "0001-01-01T00:00:00Z",
2407 "locked": false
2408 }
2409 }
2410 }
2411 }
2412 `)),

Callers

nothing calls this directly

Calls 13

RegisterMethod · 0.95
VerifyMethod · 0.95
NewFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
GraphQLMutationMatcherFunction · 0.92
repoMetaRespFunction · 0.85
newTestDiscussionClientFunction · 0.85
EqualMethod · 0.80
ContainsMethod · 0.80
RunMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected