| 886 | } |
| 887 | |
| 888 | func (o *orgGroupAssert) Assert(t *testing.T, orgID uuid.UUID, db database.Store, user database.User) { |
| 889 | t.Helper() |
| 890 | |
| 891 | ctx := context.Background() |
| 892 | |
| 893 | userGroups, err := db.GetGroups(ctx, database.GetGroupsParams{ |
| 894 | OrganizationID: orgID, |
| 895 | HasMemberID: user.ID, |
| 896 | }) |
| 897 | require.NoError(t, err) |
| 898 | if o.ExpectedGroups == nil { |
| 899 | o.ExpectedGroups = make([]uuid.UUID, 0) |
| 900 | } |
| 901 | if len(o.ExpectedGroupNames) > 0 && len(o.ExpectedGroups) > 0 { |
| 902 | t.Fatal("ExpectedGroups and ExpectedGroupNames are mutually exclusive") |
| 903 | } |
| 904 | |
| 905 | // Everyone groups mess up our asserts |
| 906 | userGroups = slices.DeleteFunc(userGroups, func(row database.GetGroupsRow) bool { |
| 907 | return row.Group.ID == row.Group.OrganizationID |
| 908 | }) |
| 909 | |
| 910 | if len(o.ExpectedGroupNames) > 0 { |
| 911 | found := slice.List(userGroups, func(g database.GetGroupsRow) string { |
| 912 | return g.Group.Name |
| 913 | }) |
| 914 | require.ElementsMatch(t, o.ExpectedGroupNames, found, "user groups by name") |
| 915 | require.Len(t, o.ExpectedGroups, 0, "ExpectedGroups should be empty") |
| 916 | } else { |
| 917 | // Check by ID, recommended |
| 918 | found := slice.List(userGroups, func(g database.GetGroupsRow) uuid.UUID { |
| 919 | return g.Group.ID |
| 920 | }) |
| 921 | require.ElementsMatch(t, o.ExpectedGroups, found, "user groups") |
| 922 | require.Len(t, o.ExpectedGroupNames, 0, "ExpectedGroupNames should be empty") |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | //nolint:revive |
| 927 | func (o orgRoleAssert) Assert(t *testing.T, orgID uuid.UUID, db database.Store, notMember bool, user database.User) { |