mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Boost unit test coverage across three core packages: - internal/sync: 11.6% → 54.6% (discovery, status, checksum, manifest, pull, merge/prune) - internal/install: 40.7% → 60.0% (meta, ignore, copy, updatable, local install, options, gitignore, source) - internal/server: 15.1% → 40.0% (health, overview, skills, targets, config, log, trash, sync, collect, check, backup, diff, audit, hub)
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestHandleOverview_Empty(t *testing.T) {
|
|
s, _ := newTestServer(t)
|
|
req := httptest.NewRequest(http.MethodGet, "/api/overview", nil)
|
|
rr := httptest.NewRecorder()
|
|
s.handler.ServeHTTP(rr, req)
|
|
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String())
|
|
}
|
|
|
|
var resp map[string]any
|
|
json.Unmarshal(rr.Body.Bytes(), &resp)
|
|
if resp["skillCount"].(float64) != 0 {
|
|
t.Errorf("expected 0 skills, got %v", resp["skillCount"])
|
|
}
|
|
if resp["targetCount"].(float64) != 0 {
|
|
t.Errorf("expected 0 targets, got %v", resp["targetCount"])
|
|
}
|
|
if resp["isProjectMode"].(bool) {
|
|
t.Error("expected isProjectMode false")
|
|
}
|
|
}
|
|
|
|
func TestHandleOverview_WithSkills(t *testing.T) {
|
|
s, src := newTestServer(t)
|
|
addSkill(t, src, "alpha")
|
|
addSkill(t, src, "beta")
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/api/overview", nil)
|
|
rr := httptest.NewRecorder()
|
|
s.handler.ServeHTTP(rr, req)
|
|
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String())
|
|
}
|
|
|
|
var resp map[string]any
|
|
json.Unmarshal(rr.Body.Bytes(), &resp)
|
|
if resp["skillCount"].(float64) != 2 {
|
|
t.Errorf("expected 2 skills, got %v", resp["skillCount"])
|
|
}
|
|
}
|
|
|
|
func TestHandleOverview_ProjectMode(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
s, _ := newTestServer(t)
|
|
s.projectRoot = tmp // simulate project mode
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/api/overview", nil)
|
|
rr := httptest.NewRecorder()
|
|
// Use mux directly to bypass config auto-reload middleware
|
|
// (project config file doesn't exist in test)
|
|
s.mux.ServeHTTP(rr, req)
|
|
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String())
|
|
}
|
|
|
|
var resp map[string]any
|
|
json.Unmarshal(rr.Body.Bytes(), &resp)
|
|
if !resp["isProjectMode"].(bool) {
|
|
t.Error("expected isProjectMode true")
|
|
}
|
|
if resp["projectRoot"] != tmp {
|
|
t.Errorf("expected projectRoot %q, got %v", tmp, resp["projectRoot"])
|
|
}
|
|
}
|