Skip to content

Commit 1b3ec51

Browse files
committed
fix tests
1 parent e9bb650 commit 1b3ec51

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

coderd/database/dbfake/dbfake.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -1413,10 +1413,7 @@ func (q *FakeQuerier) GetGroupsByOrganizationID(_ context.Context, organizationI
14131413

14141414
var groups []database.Group
14151415
for _, group := range q.groups {
1416-
// Omit the allUsers group.
1417-
if group.OrganizationID == organizationID && group.ID != organizationID {
1418-
groups = append(groups, group)
1419-
}
1416+
groups = append(groups, group)
14201417
}
14211418

14221419
return groups, nil

coderd/database/queries/groupmembers.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ SELECT
33
users.*
44
FROM
55
users
6-
LEFT JOIN
6+
RIGHT JOIN
77
group_members
88
ON
99
CASE WHEN @id:: uuid != @organization_id :: uuid THEN
1010
group_members.user_id = users.id
1111
END
12-
LEFT JOIN
12+
RIGHT JOIN
1313
organization_members
1414
ON
1515
CASE WHEN @id :: uuid = @organization_id :: uuid THEN

enterprise/coderd/groups_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ func TestPatchGroup(t *testing.T) {
420420
cerr, ok := codersdk.AsError(err)
421421
require.True(t, ok)
422422
require.Equal(t, http.StatusBadRequest, cerr.StatusCode())
423-
424423
})
425424

426425
t.Run("EveryoneGroup", func(t *testing.T) {
@@ -747,7 +746,8 @@ func TestGroups(t *testing.T) {
747746

748747
groups, err := client.GroupsByOrganization(ctx, user.OrganizationID)
749748
require.NoError(t, err)
750-
require.Len(t, groups, 2)
749+
// 'Everyone' group + 2 custom groups.
750+
require.Len(t, groups, 3)
751751
require.Contains(t, groups, group1)
752752
require.Contains(t, groups, group2)
753753
})

enterprise/coderd/userauth_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ func TestGroupSync(t *testing.T) {
525525
require.NoError(t, err)
526526

527527
for _, group := range orgGroups {
528-
if slice.Contains(tc.initialOrgGroups, group.Name) {
528+
if slice.Contains(tc.initialOrgGroups, group.Name) || group.OrganizationID == group.ID {
529529
require.Equal(t, group.Source, codersdk.GroupSourceUser)
530530
} else {
531531
require.Equal(t, group.Source, codersdk.GroupSourceOIDC)
@@ -543,6 +543,7 @@ func TestGroupSync(t *testing.T) {
543543
}
544544
delete(orgGroupsMap, expected)
545545
}
546+
delete(orgGroupsMap, database.AllUsersGroup)
546547
require.Empty(t, orgGroupsMap, "unexpected groups found")
547548

548549
expectedUserGroups := make(map[string]struct{})
@@ -554,7 +555,9 @@ func TestGroupSync(t *testing.T) {
554555
userInGroup := slice.ContainsCompare(group.Members, codersdk.User{Email: user.Email}, func(a, b codersdk.User) bool {
555556
return a.Email == b.Email
556557
})
557-
if _, ok := expectedUserGroups[group.Name]; ok {
558+
if group.ID == group.OrganizationID {
559+
require.True(t, userInGroup, "user cannot be removed from 'Everyone' group")
560+
} else if _, ok := expectedUserGroups[group.Name]; ok {
558561
require.Truef(t, userInGroup, "user should be in group %s", group.Name)
559562
} else {
560563
require.Falsef(t, userInGroup, "user should not be in group %s", group.Name)

0 commit comments

Comments
 (0)