chore(repo): reinitialize repository
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"inbox/internal/base/timeutil"
|
||||
sqlitestore "inbox/internal/store/sqlite"
|
||||
)
|
||||
|
||||
func TestDashboardWorkflowBoardMissingWorkspace(t *testing.T) {
|
||||
clock := timeutil.FixedClock{Time: time.Date(2026, 3, 13, 18, 30, 0, 0, time.UTC)}
|
||||
store, err := sqlitestore.OpenInMemory(clock)
|
||||
if err != nil {
|
||||
t.Fatalf("OpenInMemory() error = %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
handler := NewHandler(store, clock)
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/v2/dashboard/workflow/board?workspace=blog", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
handler.ServeHTTP(rec, req)
|
||||
|
||||
if rec.Code != http.StatusNotFound {
|
||||
t.Fatalf("GET workflow board status = %d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
|
||||
var payload struct {
|
||||
Error string `json:"error"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatalf("decode response: %v", err)
|
||||
}
|
||||
if !strings.Contains(payload.Error, "workspace not found: blog") {
|
||||
t.Fatalf("unexpected error payload: %#v", payload)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDashboardRolesWithoutWorkspaceReturnsGlobalRoster(t *testing.T) {
|
||||
clock := timeutil.FixedClock{Time: time.Date(2026, 3, 13, 18, 30, 0, 0, time.UTC)}
|
||||
store, err := sqlitestore.OpenInMemory(clock)
|
||||
if err != nil {
|
||||
t.Fatalf("OpenInMemory() error = %v", err)
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
handler := NewHandler(store, clock)
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/v2/dashboard/roles", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
handler.ServeHTTP(rec, req)
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("GET dashboard roles status = %d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
|
||||
var payload struct {
|
||||
Roles []struct {
|
||||
Name string `json:"name"`
|
||||
Pending int `json:"pending"`
|
||||
Session any `json:"session"`
|
||||
} `json:"roles"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatalf("decode response: %v", err)
|
||||
}
|
||||
if len(payload.Roles) != 2 {
|
||||
t.Fatalf("expected 2 enabled builtin roles, got %d", len(payload.Roles))
|
||||
}
|
||||
for _, item := range payload.Roles {
|
||||
if item.Pending != 0 {
|
||||
t.Fatalf("expected %s pending=0 in global mode, got %d", item.Name, item.Pending)
|
||||
}
|
||||
if item.Session != nil {
|
||||
t.Fatalf("expected %s session=nil in global mode, got %#v", item.Name, item.Session)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user