chore: seed migration objects batch 5
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/model"
|
||||
)
|
||||
|
||||
func TestCompanyDepartmentIsImPlatformAdmin(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), consts.ContextHTTPKey, &model.Context{
|
||||
User: &model.Identity{Id: 14, TenantId: 1, DeptType: consts.DeptTypeCompany, RoleKey: "imManage"},
|
||||
})
|
||||
if !isImPlatformAdmin(ctx, 14) {
|
||||
t.Fatal("expected company department IM manager to use platform tenant selection")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveImAdminBoundTenant(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
identity *model.Identity
|
||||
want int64
|
||||
}{
|
||||
{
|
||||
name: "tenant department with tenant binding",
|
||||
identity: &model.Identity{
|
||||
TenantId: 2,
|
||||
DeptType: consts.DeptTypeTenant,
|
||||
},
|
||||
want: 2,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), consts.ContextHTTPKey, &model.Context{User: tt.identity})
|
||||
got, err := resolveImAdminBoundTenant(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Fatalf("tenant binding mismatch: got %d, want %d", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveImAdminBoundTenantRejectsUnboundAccount(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), consts.ContextHTTPKey, &model.Context{
|
||||
User: &model.Identity{DeptType: consts.DeptTypeTenant, RoleKey: "tenantManager"},
|
||||
})
|
||||
if _, err := resolveImAdminBoundTenant(ctx); err == nil {
|
||||
t.Fatal("expected unbound account to be rejected")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user