Files
platforms/backend/api/internal/logic/gas/menu_test.go

52 lines
1.5 KiB
Go

package gas
import "testing"
func TestMenusOnlyAllowGasAdmin(t *testing.T) {
if got := MenusForRole("admin"); len(got) == 0 {
t.Fatal("admin must receive gas menus")
}
for _, role := range []string{"root", "delivery", "installer", "operations", ""} {
if got := MenusForRole(role); len(got) != 0 {
t.Fatalf("role %q must not receive gas admin menus", role)
}
}
}
func TestMenuContainsContractAndDeliveryManagement(t *testing.T) {
found := map[string]bool{}
for _, menu := range MenusForRole("admin") {
found[menu.Identity] = true
}
for _, identity := range []string{"delivery_basic", "gasorder_contract", "invitation_qrcode"} {
if !found[identity] {
t.Fatalf("missing confirmed menu %q", identity)
}
}
}
func TestMenuContainsDashboardRoutes(t *testing.T) {
want := map[string]string{
"dashboard_overview": "/dashboard/overview",
}
for _, menu := range MenusForRole("admin") {
if path, ok := want[menu.Identity]; ok {
if menu.Path != path {
t.Fatalf("menu %q path = %q, want %q", menu.Identity, menu.Path, path)
}
delete(want, menu.Identity)
}
}
if len(want) != 0 {
t.Fatalf("missing dashboard menus: %#v", want)
}
for _, menu := range MenusForRole("admin") {
if menu.Identity == "dashboard_overview" && (menu.ParentIdentity != "" || menu.Icon != "icon-dashboard") {
t.Fatalf("dashboard overview must be a first-level icon menu: %#v", menu)
}
if menu.Identity == "dashboard" || menu.Identity == "dashboard_reports" {
t.Fatalf("legacy dashboard menu must not be returned: %#v", menu)
}
}
}