refactor platform menus and entity statuses

This commit is contained in:
david
2026-07-29 13:18:52 +08:00
parent 978dc446d9
commit afd9dbdeb5
48 changed files with 510 additions and 421 deletions

View File

@@ -9,7 +9,7 @@ import (
"gorm.io/gorm"
)
func TestInitPlatformAccessSeedsEveryProtectedFrontendDomain(t *testing.T) {
func TestInitPlatformAccessSeedsRootRole(t *testing.T) {
sqlDatabase, mock, err := sqlmock.New()
if err != nil {
t.Fatal(err)
@@ -23,23 +23,7 @@ func TestInitPlatformAccessSeedsEveryProtectedFrontendDomain(t *testing.T) {
mock.ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "platform_role" WHERE role_code = $1 ORDER BY "platform_role"."id" LIMIT $2`)).
WithArgs("root", 1).
WillReturnRows(sqlmock.NewRows([]string{"id", "identity", "status", "version", "role_code", "name", "data_scope", "is_system"}).
AddRow(uint64(1), "root-role", "enabled", 1, "root", "Root", "global", true))
domains := []string{
"dashboard", "gas", "delivery", "staff", "user", "device",
"ec", "finance", "wallet", "content", "customer_service", "platform",
}
for index, domain := range domains {
menuID := uint64(index + 10)
mock.ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "platform_menu" WHERE menu_code = $1 ORDER BY "platform_menu"."id" LIMIT $2`)).
WithArgs(domain, 1).
WillReturnRows(sqlmock.NewRows([]string{"id", "identity", "status", "version", "parent_id", "menu_code", "name", "icon", "path", "sort_no"}).
AddRow(menuID, domain+"-menu", "enabled", 1, uint64(0), domain, domain, "", "/"+domain, index))
mock.ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "platform_role_menu" WHERE platform_role_id = $1 AND platform_menu_id = $2 ORDER BY "platform_role_menu"."id" LIMIT $3`)).
WithArgs(uint64(1), menuID, 1).
WillReturnRows(sqlmock.NewRows([]string{"id", "platform_role_id", "platform_menu_id"}).
AddRow(uint64(index+100), uint64(1), menuID))
}
AddRow(uint64(1), "root-role", 1, 1, "root", "Root", "global", true))
if err := InitPlatformAccess(database); err != nil {
t.Fatal(err)