Parse optional account_ids in run handler
This commit is contained in:
@@ -26,3 +26,25 @@ func TestImportCSVFailsOnBadEncKey(t *testing.T) {
|
||||
t.Fatalf("import must fail on bad EncKey, got %d", rw.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRunAccountIDs(t *testing.T) {
|
||||
// empty body => nil (run all)
|
||||
req := httptest.NewRequest("POST", "/api/tasks/1/run", strings.NewReader(""))
|
||||
ids, err := parseRunAccountIDs(req)
|
||||
if err != nil || ids != nil {
|
||||
t.Fatalf("empty body must yield nil ids, got %v err=%v", ids, err)
|
||||
}
|
||||
|
||||
// explicit selection
|
||||
req = httptest.NewRequest("POST", "/api/tasks/1/run", strings.NewReader(`{"account_ids":[3,7]}`))
|
||||
ids, err = parseRunAccountIDs(req)
|
||||
if err != nil || len(ids) != 2 || ids[0] != 3 || ids[1] != 7 {
|
||||
t.Fatalf("must parse account_ids, got %v err=%v", ids, err)
|
||||
}
|
||||
|
||||
// malformed JSON => error
|
||||
req = httptest.NewRequest("POST", "/api/tasks/1/run", strings.NewReader(`{bad`))
|
||||
if _, err := parseRunAccountIDs(req); err == nil {
|
||||
t.Fatal("malformed body must error")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user