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:
Steven Masley
2024-07-10 07:38:48 -10:00
committed by GitHub
parent 7bb3e0db4a
commit a588ec5b21
4 changed files with 62 additions and 15 deletions

View File

@ -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})
}