Verified Commit 7c051f03 authored by Zubeen's avatar Zubeen 🤖 Committed by GitLab
Browse files

feat(topics): add without_projects option to ListTopics

Changelog: Improvements
parent 000e81ea
Loading
Loading
Loading
Loading
+1 −0
Changes for topics.go: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ func (t Topic) String() string {
type ListTopicsOptions struct {
	ListOptions
	Search          *string `url:"search,omitempty" json:"search,omitempty"`
	WithoutProjects *bool   `url:"without_projects,omitempty" json:"without_projects,omitempty"`
}

func (s *TopicsService) ListTopics(opt *ListTopicsOptions, options ...RequestOptionFunc) ([]*Topic, *Response, error) {
+20 −0
Changes for topics_test.go: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -91,6 +91,26 @@ func TestTopicsService_ListTopics(t *testing.T) {
	assert.Equal(t, want, topics)
}

func TestTopicsService_ListTopics_WithoutProjects(t *testing.T) {
	t.Parallel()

	// GIVEN a server that returns a topic without projects
	mux, client := setup(t)
	mux.HandleFunc("/api/v4/topics", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodGet)
		testParam(t, r, "without_projects", "true")
		fmt.Fprint(w, `[{"id": 4, "name": "unused", "total_projects_count": 0}]`)
	})

	// WHEN listing topics without projects
	opt := &ListTopicsOptions{WithoutProjects: new(true)}
	topics, _, err := client.Topics.ListTopics(opt)

	// THEN the filter is sent and the topic is returned
	assert.NoError(t, err)
	assert.Equal(t, []*Topic{{ID: 4, Name: "unused"}}, topics)
}

func TestTopicsService_GetTopic(t *testing.T) {
	t.Parallel()
	mux, client := setup(t)