feat(backend): book list/detail/delete with embedded progress + cache cleanup
This commit is contained in:
@@ -9,14 +9,11 @@ import (
|
||||
|
||||
func adminToken(t *testing.T, h http.Handler) string {
|
||||
t.Helper()
|
||||
w := do(h, "POST", "/api/auth/login", "", map[string]string{"username": "alice", "password": "pw12345"})
|
||||
var v struct{ Token string }
|
||||
json.Unmarshal(w.Body.Bytes(), &v)
|
||||
return v.Token
|
||||
return loginAs(t, h, "alice", testPW)
|
||||
}
|
||||
|
||||
func TestUserCRUD(t *testing.T) {
|
||||
_, h := setupAPI(t)
|
||||
_, _, h, _ := setupAPI(t)
|
||||
tok := adminToken(t, h)
|
||||
w := do(h, "POST", "/api/users", tok, map[string]string{"username": "carol", "password": "pw123456", "role": "member"})
|
||||
if w.Code != 201 {
|
||||
@@ -59,7 +56,7 @@ func TestUserCRUD(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBadRoleRejected(t *testing.T) {
|
||||
_, h := setupAPI(t)
|
||||
_, _, h, _ := setupAPI(t)
|
||||
tok := adminToken(t, h)
|
||||
w := do(h, "POST", "/api/users", tok, map[string]string{"username": "e", "password": "pw123456", "role": "god"})
|
||||
if w.Code != 400 {
|
||||
@@ -76,4 +73,9 @@ func findID(rows []map[string]any, name string) float64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func itoa(v any) string { return strconv.FormatFloat(v.(float64), 'f', 0, 64) }
|
||||
func itoa(v any) string {
|
||||
if i, ok := v.(int64); ok {
|
||||
return strconv.FormatInt(i, 10) // DB 行里的 id (如 store.Library.ID)
|
||||
}
|
||||
return strconv.FormatFloat(v.(float64), 'f', 0, 64) // json.Unmarshal 出来的数字
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user