MCPcopy Index your code
hub / github.com/coder/coder / TestEnterpriseMembers

Function TestEnterpriseMembers

enterprise/members_test.go:18–180  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestEnterpriseMembers(t *testing.T) {
19 t.Parallel()
20
21 t.Run("Remove", func(t *testing.T) {
22 t.Parallel()
23 owner, first := coderdenttest.New(t, &coderdenttest.Options{
24 LicenseOptions: &coderdenttest.LicenseOptions{
25 Features: license.Features{
26 codersdk.FeatureMultipleOrganizations: 1,
27 codersdk.FeatureTemplateRBAC: 1,
28 },
29 },
30 })
31
32 secondOrg := coderdenttest.CreateOrganization(t, owner, coderdenttest.CreateOrganizationOptions{})
33
34 orgAdminClient, orgAdmin := coderdtest.CreateAnotherUser(t, owner, secondOrg.ID, rbac.ScopedRoleOrgAdmin(secondOrg.ID))
35 _, user := coderdtest.CreateAnotherUser(t, owner, secondOrg.ID)
36
37 ctx := testutil.Context(t, testutil.WaitMedium)
38
39 // Groups exist to ensure a user removed from the org loses their
40 // group access.
41 g1, err := orgAdminClient.CreateGroup(ctx, secondOrg.ID, codersdk.CreateGroupRequest{
42 Name: "foo",
43 DisplayName: "Foo",
44 })
45 require.NoError(t, err)
46
47 g2, err := orgAdminClient.CreateGroup(ctx, secondOrg.ID, codersdk.CreateGroupRequest{
48 Name: "bar",
49 DisplayName: "Bar",
50 })
51 require.NoError(t, err)
52
53 // Verify the org of 3 members
54 members, err := orgAdminClient.OrganizationMembers(ctx, secondOrg.ID)
55 require.NoError(t, err)
56 require.Len(t, members, 3)
57 require.ElementsMatch(t,
58 []uuid.UUID{first.UserID, user.ID, orgAdmin.ID},
59 slice.List(members, onlyIDs))
60
61 // Add the member to some groups
62 _, err = orgAdminClient.PatchGroup(ctx, g1.ID, codersdk.PatchGroupRequest{
63 AddUsers: []string{user.ID.String()},
64 })
65 require.NoError(t, err)
66
67 _, err = orgAdminClient.PatchGroup(ctx, g2.ID, codersdk.PatchGroupRequest{
68 AddUsers: []string{user.ID.String()},
69 })
70 require.NoError(t, err)
71
72 // Verify group membership
73 userGroups, err := orgAdminClient.Groups(ctx, codersdk.GroupArguments{
74 HasMember: user.ID.String(),
75 })

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
CreateOrganizationFunction · 0.92
CreateAnotherUserFunction · 0.92
ScopedRoleOrgAdminFunction · 0.92
ContextFunction · 0.92
ListFunction · 0.92
ScopedRoleOrgUserAdminFunction · 0.92
CreateGroupMethod · 0.80
PatchGroupMethod · 0.80
RunMethod · 0.65
OrganizationMembersMethod · 0.65

Tested by

no test coverage detected