fix(admin): standardize resource initialization and lists

This commit is contained in:
2026-08-05 12:19:13 +08:00
parent d88e18bd09
commit 2162fe5e11
36 changed files with 419 additions and 267 deletions

View File

@@ -7,6 +7,7 @@ import (
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
"github.com/DATA-DOG/go-sqlmock"
"github.com/google/uuid"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
@@ -18,6 +19,32 @@ func TestFilterFieldsKeepsOnlyAllowedKeys(t *testing.T) {
}
}
func TestStripClientManagedCreateFields(t *testing.T) {
input := map[string]any{"id": float64(99), "identity": "client-value", "name": "气站"}
stripClientManagedCreateFields(input)
if _, exists := input["id"]; exists {
t.Fatal("client supplied database ID was retained")
}
if _, exists := input["identity"]; exists {
t.Fatal("client supplied identity was retained")
}
if input["name"] != "气站" {
t.Fatalf("business fields changed: %#v", input)
}
}
func TestNewEntityGeneratesUUIDV7Identity(t *testing.T) {
first := NewEntity(StatusDraft)
second := NewEntity(StatusDraft)
if first.Identity == second.Identity {
t.Fatal("generated identities must be unique")
}
parsed, err := uuid.Parse(first.Identity)
if err != nil || parsed.Version() != 7 {
t.Fatalf("identity = %q, want UUID V7", first.Identity)
}
}
func TestOperationalQueriesExcludeArchivedRecords(t *testing.T) {
sqlDatabase, _, err := sqlmock.New()
if err != nil {