Implement change order endpoint

This commit is contained in:
bel
2019-12-01 17:31:30 -07:00
parent 48e8b91039
commit c756c005ac
8 changed files with 96 additions and 5 deletions

View File

@@ -177,3 +177,33 @@ func TestAjaxMoveTask(t *testing.T) {
t.Error(err, task)
}
}
func TestAjaxChangeOrder(t *testing.T) {
ajax := mockAjax()
ajax.storageSetTask("list", &task.Task{UUID: "b", Title: "c", Index: 5})
ajax.storageSetTask("list", &task.Task{UUID: "d", Title: "e", Index: 6})
ajax.storageSetTask("list", &task.Task{UUID: "f", Title: "g", Index: 7})
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/", strings.NewReader(`order=b%3d0%26d%3d-1%26f%3d-1%26`))
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
ajax.changeOrder(w, r)
if v := w.Code; v != http.StatusOK {
t.Error(v)
}
tasks, err := ajax.storageListTasks("list")
if err != nil {
t.Fatal(err)
}
if len(tasks) != 3 {
t.Fatal(err)
}
if tasks[0].UUID != "d" {
t.Error(tasks[0])
}
if tasks[1].UUID != "f" {
t.Error(tasks[1])
}
if tasks[2].UUID != "b" {
t.Error(tasks[2])
}
}