(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func 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 | }) |
nothing calls this directly
no test coverage detected