mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: assign user to multiple orgs in coderdtest user create (#13867)
* chore: coderdtest assign user to multiple orgs on create
This commit is contained in:
@ -3,9 +3,12 @@ package coderdtest_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/goleak"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/coderdtest"
|
||||
"github.com/coder/coder/v2/coderd/rbac"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@ -27,3 +30,20 @@ func TestNew(t *testing.T) {
|
||||
_, _ = coderdtest.NewGoogleInstanceIdentity(t, "example", false)
|
||||
_, _ = coderdtest.NewAWSInstanceIdentity(t, "an-instance")
|
||||
}
|
||||
|
||||
// TestOrganizationMember checks the coderdtest helper can add organization members
|
||||
// to multiple orgs.
|
||||
func TestOrganizationMember(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client := coderdtest.New(t, &coderdtest.Options{})
|
||||
owner := coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
second := coderdtest.CreateOrganization(t, client, coderdtest.CreateOrganizationOptions{})
|
||||
third := coderdtest.CreateOrganization(t, client, coderdtest.CreateOrganizationOptions{})
|
||||
|
||||
// Assign the user to 3 orgs in this 1 statement
|
||||
_, user := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.ScopedRoleOrgMember(second.ID), rbac.ScopedRoleOrgMember(third.ID))
|
||||
require.Len(t, user.OrganizationIDs, 3)
|
||||
require.ElementsMatch(t, user.OrganizationIDs, []uuid.UUID{owner.OrganizationID, second.ID, third.ID})
|
||||
}
|
||||
|
Reference in New Issue
Block a user