MCPcopy
hub / github.com/cli/cli / TestListCategories

Function TestListCategories

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

Source from the content-addressed store, hash-verified

940}
941
942func TestListCategories(t *testing.T) {
943 repo := ghrepo.New("OWNER", "REPO")
944
945 tests := []struct {
946 name string
947 httpStubs func(*testing.T, *httpmock.Registry)
948 wantErr string
949 wantCats []DiscussionCategory
950 }{
951 {
952 name: "maps all fields",
953 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
954 reg.Register(
955 httpmock.GraphQL(`query DiscussionCategoryList\b`),
956 httpmock.StringResponse(`{"data":{"repository":{
957 "hasDiscussionsEnabled":true,
958 "discussionCategories":{"nodes":[
959 {"id":"C1","name":"General","slug":"general","emoji":":speech_balloon:","isAnswerable":false},
960 {"id":"C2","name":"Q&A","slug":"q-a","emoji":":question:","isAnswerable":true}
961 ]}
962 }}}`),
963 )
964 },
965 wantCats: []DiscussionCategory{
966 {ID: "C1", Name: "General", Slug: "general", Emoji: ":speech_balloon:", IsAnswerable: false},
967 {ID: "C2", Name: "Q&A", Slug: "q-a", Emoji: ":question:", IsAnswerable: true},
968 },
969 },
970 {
971 name: "discussions disabled",
972 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
973 reg.Register(
974 httpmock.GraphQL(`query DiscussionCategoryList\b`),
975 httpmock.StringResponse(`{"data":{"repository":{
976 "hasDiscussionsEnabled":false,
977 "discussionCategories":{"nodes":[]}
978 }}}`),
979 )
980 },
981 wantErr: "discussions disabled",
982 },
983 }
984
985 for _, tt := range tests {
986 t.Run(tt.name, func(t *testing.T) {
987 reg := &httpmock.Registry{}
988 defer reg.Verify(t)
989
990 if tt.httpStubs != nil {
991 tt.httpStubs(t, reg)
992 }
993
994 c := newTestDiscussionClient(reg)
995 categories, err := c.ListCategories(repo)
996
997 if tt.wantErr != "" {
998 require.Error(t, err)
999 assert.Contains(t, err.Error(), tt.wantErr)

Callers

nothing calls this directly

Calls 12

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
ListCategoriesMethod · 0.65
LenMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected