(t *testing.T)
| 2854 | } |
| 2855 | |
| 2856 | func TestEditDiscussionLabels(t *testing.T) { |
| 2857 | repo := ghrepo.New("OWNER", "REPO") |
| 2858 | |
| 2859 | baseNode := func() discussionListNode { |
| 2860 | return discussionListNode{ |
| 2861 | ID: "D_1", |
| 2862 | Number: 5, |
| 2863 | Title: "T", |
| 2864 | Body: "B", |
| 2865 | URL: "https://github.com/OWNER/REPO/discussions/5", |
| 2866 | Author: actorNode{ |
| 2867 | TypeName: "User", |
| 2868 | Login: "alice", |
| 2869 | User: struct{ ID, Name string }{ID: "U1", Name: "Alice"}, |
| 2870 | Bot: struct{ ID string }{ID: "U1"}, |
| 2871 | }, |
| 2872 | Category: struct { |
| 2873 | ID string |
| 2874 | Name string |
| 2875 | Slug string |
| 2876 | Emoji string |
| 2877 | IsAnswerable bool |
| 2878 | }{ID: "CAT_1", Name: "General", Slug: "general"}, |
| 2879 | ReactionGroups: []struct { |
| 2880 | Content string |
| 2881 | Users struct{ TotalCount int } |
| 2882 | }{}, |
| 2883 | CreatedAt: time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC), |
| 2884 | UpdatedAt: time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC), |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | tests := []struct { |
| 2889 | name string |
| 2890 | addIDs []string |
| 2891 | removeIDs []string |
| 2892 | setupMock func(reg *httpmock.Registry) |
| 2893 | wantErr string |
| 2894 | wantNode func() discussionListNode |
| 2895 | }{ |
| 2896 | { |
| 2897 | name: "adds and removes labels", |
| 2898 | addIDs: []string{"L_bug", "L_enh"}, |
| 2899 | removeIDs: []string{"L_old"}, |
| 2900 | setupMock: func(reg *httpmock.Registry) { |
| 2901 | reg.Register( |
| 2902 | httpmock.GraphQLMutationMatcher(`mutation RemoveLabelsFromDiscussion\b`, func(input map[string]interface{}) bool { |
| 2903 | assert.Equal(t, "D_1", input["labelableId"]) |
| 2904 | assert.Equal(t, []interface{}{"L_old"}, input["labelIds"]) |
| 2905 | return true |
| 2906 | }), |
| 2907 | // This response is superseded by the subsequent add mutation so we don't need all fields. |
| 2908 | httpmock.StringResponse(`{"data":{"removeLabelsFromLabelable":{"labelable":{"id": "D_1"}}}}`), |
| 2909 | ) |
| 2910 | reg.Register( |
| 2911 | httpmock.GraphQLMutationMatcher(`mutation AddLabelsToDiscussion\b`, func(input map[string]interface{}) bool { |
| 2912 | assert.Equal(t, "D_1", input["labelableId"]) |
| 2913 | assert.Equal(t, []interface{}{"L_bug", "L_enh"}, input["labelIds"]) |
nothing calls this directly
no test coverage detected