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

49 lines
1.4 KiB
Go
Raw Normal View History

package delivery
import "testing"
func TestMenusOnlyAllowAdmin(t *testing.T) {
if len(MenusForRole("admin")) == 0 {
t.Fatal("admin must receive delivery menus")
}
for _, role := range []string{"root", "dispatcher", "warehouse", "quality", "delivery", ""} {
if len(MenusForRole(role)) != 0 {
t.Fatalf("role %q must not receive delivery admin menus", role)
}
}
}
func TestMenusExcludeInventoryAndEcommerce(t *testing.T) {
for _, menu := range MenusForRole("admin") {
switch menu.GroupCode {
case "inventory", "warehouse", "ec":
t.Fatalf("forbidden menu group %q", menu.GroupCode)
}
}
}
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)
}
}
}