Every template and handler message in internal/web goes through a JSON
catalogue under internal/web/locales/<code>/, with English as the fallback.
The language is the person's choice (a cookie set by /_lang/{code}), else
Accept-Language, else landing.language. Tests refuse a key some language
lacks, a translation with other arguments than English, and template text
left in English.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
|
)
|
|
|
|
func TestEachStaffRoleMayDoWhatItSays(t *testing.T) {
|
|
cases := []struct {
|
|
role, method, path string
|
|
may bool
|
|
}{
|
|
{store.RoleViewer, "GET", "/admin/users", true},
|
|
{store.RoleViewer, "POST", "/admin/users/u1/suspend", false},
|
|
{store.RoleViewer, "POST", "/admin/mirror/fetch", false},
|
|
{store.RoleOperator, "GET", "/admin", true},
|
|
{store.RoleOperator, "POST", "/admin/mirror/fetch", true},
|
|
{store.RoleOperator, "POST", "/admin/nodes/n1/engines", true},
|
|
{store.RoleOperator, "POST", "/admin/quotas", false},
|
|
{store.RoleOperator, "POST", "/admin/tenancy/org", false},
|
|
{store.RoleBilling, "GET", "/admin/usage", true},
|
|
{store.RoleBilling, "GET", "/admin/quotas", true},
|
|
{store.RoleBilling, "GET", "/admin/users", false},
|
|
{store.RoleBilling, "POST", "/admin/quotas", false},
|
|
{"", "GET", "/admin", false},
|
|
}
|
|
for _, c := range cases {
|
|
u := store.User{Role: c.role}
|
|
if got := staffMay(u, httptest.NewRequest(c.method, c.path, nil)); got != c.may {
|
|
t.Errorf("%s %s %s: %v", c.role, c.method, c.path, got)
|
|
}
|
|
}
|
|
if !staffMay(store.User{IsAdmin: true}, httptest.NewRequest("POST", "/admin/users/u1/delete", nil)) {
|
|
t.Error("an administrator may do anything")
|
|
}
|
|
}
|
|
|
|
func TestABillingRoleIsShownUsageAndQuotasOnly(t *testing.T) {
|
|
rec := httptest.NewRecorder()
|
|
render(rec, nil, "admin_guard", guardPageData{Nav: Nav{Admin: true, Role: store.RoleBilling}})
|
|
body := rec.Body.String()
|
|
if !strings.Contains(body, `href="/admin/usage"`) || strings.Contains(body, `href="/admin/users"`) {
|
|
t.Errorf("menu: %s", body)
|
|
}
|
|
}
|