(t *testing.T)
| 940 | } |
| 941 | |
| 942 | func 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) |
nothing calls this directly
no test coverage detected