cmsctl and docs
This commit is contained in:
1 parent
fea6eb51b1
commit
93cfa123e4
5 files changed
+316
No files matched your search
@@ -293,3 +293,97 @@ func TestFinderAdminAlwaysUsesBackofficeBaseURL(t *testing.T) {
|
||||
t.Fatalf("requests = %v %v", methods, paths)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTodosListFiltersAndDoneCommands(t *testing.T) {
|
||||
var requests []struct {
|
||||
Method string
|
||||
Path string
|
||||
Query string
|
||||
Body string
|
||||
}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
requests = append(requests, struct {
|
||||
Method string
|
||||
Path string
|
||||
Query string
|
||||
Body string
|
||||
}{
|
||||
Method: r.Method,
|
||||
Path: r.URL.Path,
|
||||
Query: r.URL.RawQuery,
|
||||
Body: string(body),
|
||||
})
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if r.Method == http.MethodPatch {
|
||||
_, _ = io.WriteString(w, `{"id":"todo-1","dataType":"todo","data":{"done":true}}`)
|
||||
return
|
||||
}
|
||||
if r.Method == http.MethodPost {
|
||||
_, _ = io.WriteString(w, `{"id":"todo-created","dataType":"todo"}`)
|
||||
return
|
||||
}
|
||||
_, _ = io.WriteString(w, `{"items":[],"total":0}`)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := newClient(Config{BaseURL: server.URL}, "token", "", time.Second)
|
||||
var output bytes.Buffer
|
||||
|
||||
// 1. List with --open
|
||||
if err := runTodos(context.Background(), client, []string{"list", "--open", "--prio", "high", "--q", "cart"}, strings.NewReader(""), &output); err != nil {
|
||||
t.Fatalf("todos list --open: %v", err)
|
||||
}
|
||||
if len(requests) != 1 || requests[0].Path != "/api/todos" {
|
||||
t.Fatalf("unexpected request: %+v", requests)
|
||||
}
|
||||
if !strings.Contains(requests[0].Query, "done=false") || !strings.Contains(requests[0].Query, "prio=high") || !strings.Contains(requests[0].Query, "q=cart") {
|
||||
t.Fatalf("unexpected query string: %q", requests[0].Query)
|
||||
}
|
||||
|
||||
// 2. List with --done=true
|
||||
requests = nil
|
||||
if err := runTodos(context.Background(), client, []string{"list", "--done=true"}, strings.NewReader(""), &output); err != nil {
|
||||
t.Fatalf("todos list --done=true: %v", err)
|
||||
}
|
||||
if len(requests) != 1 || !strings.Contains(requests[0].Query, "done=true") {
|
||||
t.Fatalf("expected done=true in query: %q", requests[0].Query)
|
||||
}
|
||||
|
||||
// 3. Mark done
|
||||
requests = nil
|
||||
if err := runTodos(context.Background(), client, []string{"done", "todo-123"}, strings.NewReader(""), &output); err != nil {
|
||||
t.Fatalf("todos done: %v", err)
|
||||
}
|
||||
if len(requests) != 1 || requests[0].Method != http.MethodPatch || requests[0].Path != "/api/nodes/todo-123" {
|
||||
t.Fatalf("unexpected mark done request: %+v", requests)
|
||||
}
|
||||
if !strings.Contains(requests[0].Body, `"done":true`) {
|
||||
t.Fatalf("expected done:true in patch body: %q", requests[0].Body)
|
||||
}
|
||||
|
||||
// 4. Reopen
|
||||
requests = nil
|
||||
if err := runTodos(context.Background(), client, []string{"reopen", "todo-123"}, strings.NewReader(""), &output); err != nil {
|
||||
t.Fatalf("todos reopen: %v", err)
|
||||
}
|
||||
if len(requests) != 1 || requests[0].Method != http.MethodPatch || requests[0].Path != "/api/nodes/todo-123" {
|
||||
t.Fatalf("unexpected reopen request: %+v", requests)
|
||||
}
|
||||
if !strings.Contains(requests[0].Body, `"done":false`) {
|
||||
t.Fatalf("expected done:false in reopen body: %q", requests[0].Body)
|
||||
}
|
||||
|
||||
// 5. Create
|
||||
requests = nil
|
||||
if err := runTodos(context.Background(), client, []string{"create", "--note", "Fix button", "--prio", "high", "--location", "Admin"}, strings.NewReader(""), &output); err != nil {
|
||||
t.Fatalf("todos create: %v", err)
|
||||
}
|
||||
if len(requests) != 1 || requests[0].Method != http.MethodPost || requests[0].Path != "/api/nodes" {
|
||||
t.Fatalf("unexpected create request: %+v", requests)
|
||||
}
|
||||
if !strings.Contains(requests[0].Body, `"dataType":"todo"`) || !strings.Contains(requests[0].Body, `"note":"Fix button"`) {
|
||||
t.Fatalf("unexpected create body: %q", requests[0].Body)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user