32 lines
951 B
Go
32 lines
951 B
Go
package adminaudit
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"hfb_sys/backend/internal/database"
|
|
"hfb_sys/backend/internal/model"
|
|
"hfb_sys/backend/internal/tenancy"
|
|
)
|
|
|
|
func TestListIsScopedByOperatingTenant(t *testing.T) {
|
|
db := database.NewTestDB()
|
|
rows := []model.AuditLog{
|
|
{TenantID: 101, ActorType: "admin", ActorID: 1, Action: "tenant.a", BizType: "test"},
|
|
{TenantID: 202, ActorType: "admin", ActorID: 2, Action: "tenant.b", BizType: "test"},
|
|
{TenantID: 0, ActorType: "admin", ActorID: 3, Action: "platform", BizType: "test"},
|
|
}
|
|
if err := db.Create(&rows).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 101})
|
|
result, err := NewRepository(db).List(ctx, Query{Page: 1, PageSize: 20})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
items := result.Items.([]LogDTO)
|
|
if result.Total != 1 || len(items) != 1 || items[0].Action != "tenant.a" {
|
|
t.Fatalf("tenant audit list = %+v", result)
|
|
}
|
|
}
|