package auth import ( "context" "fmt" "math/rand" "testing" "time" "perms-system-server/internal/model/perm" "perms-system-server/internal/model/productmember" "perms-system-server/internal/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) // TC-0534: GetUserPerms 委托到 UserDetailsLoader.Load() func TestGetUserPerms_DelegatesToLoader(t *testing.T) { ctx := context.Background() svcCtx := newTestSvcCtx() conn := testutil.GetTestSqlConn() now := time.Now().Unix() pc := fmt.Sprintf("tp_delegate_%d", rand.Intn(100000)) userId := int64(900000 + rand.Intn(10000)) pmRes, err := svcCtx.SysProductMemberModel.Insert(ctx, &productmember.SysProductMember{ ProductCode: pc, UserId: userId, MemberType: "ADMIN", Status: 1, CreateTime: now, UpdateTime: now, }) require.NoError(t, err) pmId, _ := pmRes.LastInsertId() p1Res, err := svcCtx.SysPermModel.Insert(ctx, &perm.SysPerm{ ProductCode: pc, Name: "del_p1", Code: fmt.Sprintf("del_c1_%d", rand.Intn(100000)), Status: 1, CreateTime: now, UpdateTime: now, }) require.NoError(t, err) p1Id, _ := p1Res.LastInsertId() t.Cleanup(func() { testutil.CleanTable(ctx, conn, "`sys_product_member`", pmId) testutil.CleanTable(ctx, conn, "`sys_perm`", p1Id) }) ud := svcCtx.UserDetailsLoader.Load(ctx, userId, pc) perms, memberType, err := GetUserPerms(ctx, svcCtx, userId, 0, pc, false) require.NoError(t, err, "GetUserPerms should always return nil error") assert.Equal(t, ud.Perms, perms, "Perms should match UserDetailsLoader.Load() result") assert.Equal(t, ud.MemberType, memberType, "MemberType should match UserDetailsLoader.Load() result") }