71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
package access
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestGoAutoModulesOwnEveryAdminAPIExactlyOnce(t *testing.T) {
|
|
modules := GoAutoModules()
|
|
if len(modules) != 11 {
|
|
t.Fatalf("got %d modules, want 11", len(modules))
|
|
}
|
|
|
|
owners := make(map[string]int)
|
|
for _, module := range modules {
|
|
if module.Key == "" || module.Path == "" || module.RouteName == "" || module.Component == "" {
|
|
t.Fatalf("module metadata is incomplete: %#v", module)
|
|
}
|
|
for _, permission := range module.APIs {
|
|
owners[permission.Method+" "+permission.Path]++
|
|
}
|
|
}
|
|
for _, permission := range AdminAPIs {
|
|
key := permission.Method + " " + permission.Path
|
|
if owners[key] != 1 {
|
|
t.Fatalf("%s belongs to %d modules, want exactly one", key, owners[key])
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAIMatchingIsHardHiddenFromPurchaser(t *testing.T) {
|
|
module, ok := ModuleByRouteName("GoAutoAiMatchingSettings")
|
|
if !ok {
|
|
t.Fatal("AI matching module not found")
|
|
}
|
|
if module.PurchaserDefault || !module.PurchaserHardHidden {
|
|
t.Fatalf("unexpected AI purchaser flags: %#v", module)
|
|
}
|
|
if len(module.APIs) == 0 {
|
|
t.Fatal("AI matching module must own its APIs")
|
|
}
|
|
}
|
|
|
|
func TestGoAutoModuleRoutesMatchCurrentWebRouter(t *testing.T) {
|
|
_, fileName, _, ok := runtime.Caller(0)
|
|
if !ok {
|
|
t.Fatal("cannot locate test source")
|
|
}
|
|
routerPath := filepath.Join(filepath.Dir(fileName), "..", "..", "..", "..", "web", "src", "router", "index.js")
|
|
content, err := os.ReadFile(routerPath)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
router := string(content)
|
|
for _, module := range GoAutoModules() {
|
|
want := []string{
|
|
"path: '" + module.Path + "'",
|
|
"component: () => import('@/views" + module.Component + "')",
|
|
"name: '" + module.RouteName + "'",
|
|
}
|
|
for _, fragment := range want {
|
|
if !strings.Contains(router, fragment) {
|
|
t.Fatalf("Web router is inconsistent with module %s: missing %q", module.Key, fragment)
|
|
}
|
|
}
|
|
}
|
|
}
|