Unverified Commit a4e9e6c4 authored by Sander van Harmelen's avatar Sander van Harmelen Committed by GitHub

Merge pull request #651 from ZJvandeWeg/zj-todos-list-opts

ListTodo allows for ListOptions
parents 6af500e1 8ac669f5
[
{
"id": 1,
"state": "pending",
"target": {
"id": 1,
"approvals_before_merge": 2
}
},
{
"id": 2,
"state": "pending",
"target": {
"id": 2,
"approvals_before_merge": null
}
}
]
......@@ -121,6 +121,7 @@ func (t Todo) String() string {
//
// GitLab API docs: https://docs.gitlab.com/ce/api/todos.html#get-a-list-of-todos
type ListTodosOptions struct {
ListOptions
Action *TodoAction `url:"action,omitempty" json:"action,omitempty"`
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
ProjectID *int `url:"project_id,omitempty" json:"project_id,omitempty"`
......
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
"github.com/stretchr/testify/require"
)
func TestListTodos(t *testing.T) {
......@@ -13,21 +13,16 @@ func TestListTodos(t *testing.T) {
mux.HandleFunc("/api/v4/todos", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1,"state": "pending","target":{"id":1,"approvals_before_merge":2}},{"id":2,"state":"pending","target":{"id":2,"approvals_before_merge":null}}]`)
mustWriteHTTPResponse(t, w, "testdata/list_todos.json")
})
opts := &ListTodosOptions{}
opts := &ListTodosOptions{ListOptions: ListOptions{PerPage: 2}}
todos, _, err := client.Todos.ListTodos(opts)
if err != nil {
t.Errorf("Todos.ListTodos returned error: %v", err)
}
require.NoError(t, err)
want := []*Todo{{ID: 1, State: "pending", Target: TodoTarget{ID: 1, ApprovalsBeforeMerge: 2}}, {ID: 2, State: "pending", Target: TodoTarget{ID: 2}}}
if !reflect.DeepEqual(want, todos) {
t.Errorf("Todos.ListTodos returned %+v, want %+v", todos, want)
}
require.Equal(t, want, todos)
}
func TestMarkAllTodosAsDone(t *testing.T) {
......@@ -40,10 +35,7 @@ func TestMarkAllTodosAsDone(t *testing.T) {
})
_, err := client.Todos.MarkAllTodosAsDone()
if err != nil {
t.Fatalf("Todos.MarkTodosRead returns an error: %v", err)
}
require.NoError(t, err)
}
func TestMarkTodoAsDone(t *testing.T) {
......@@ -55,8 +47,5 @@ func TestMarkTodoAsDone(t *testing.T) {
})
_, err := client.Todos.MarkTodoAsDone(1)
if err != nil {
t.Fatalf("Todos.MarkTodoRead returns an error: %v", err)
}
require.NoError(t, err)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment