Skip to content

chore!: allow CreateUser to accept multiple organizations #14383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add unit test to add multiple users at once
  • Loading branch information
Emyrk committed Aug 22, 2024
commit a8fcd4274708c905993f396acafa3c81654e1b9c
42 changes: 42 additions & 0 deletions enterprise/coderd/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,46 @@ func TestEnterprisePostUser(t *testing.T) {
})
require.ErrorContains(t, err, "No organization specified")
})

t.Run("MultipleOrganizations", func(t *testing.T) {
t.Parallel()
dv := coderdtest.DeploymentValues(t)
dv.Experiments = []string{string(codersdk.ExperimentMultiOrganization)}

client, _ := coderdenttest.New(t, &coderdenttest.Options{
Options: &coderdtest.Options{
DeploymentValues: dv,
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureMultipleOrganizations: 1,
},
},
})

// Add an extra org to assign member into
second := coderdenttest.CreateOrganization(t, client, coderdenttest.CreateOrganizationOptions{})
third := coderdenttest.CreateOrganization(t, client, coderdenttest.CreateOrganizationOptions{})

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

// nolint:gocritic // intentional using the owner.
// Manually making a user with the request instead of the coderdtest util
user, err := client.CreateUser(ctx, codersdk.CreateUserRequest{
Email: "another@user.org",
Username: "someone-else",
Password: "SomeSecurePassword!",
OrganizationIDs: []uuid.UUID{
second.ID,
third.ID,
},
})
require.NoError(t, err)

memberedOrgs, err := client.OrganizationsByUser(ctx, user.ID.String())
require.NoError(t, err)
require.Len(t, memberedOrgs, 2)
require.ElementsMatch(t, []uuid.UUID{second.ID, third.ID}, []uuid.UUID{memberedOrgs[0].ID, memberedOrgs[1].ID})
})
}
Loading