fix: fix GetOrganizationsByUserID error when multiple organizations exist (#12257)

* test: fetching user orgs fails if multi orgs in pg db
* fix: GetOrganizationsByUserID fixed if multi orgs exist
This commit is contained in:
Steven Masley 2024-02-22 08:14:48 -06:00 committed by GitHub
parent da376549a3
commit d4d8424ce0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

View File

@ -3540,7 +3540,7 @@ SELECT
FROM
organizations
WHERE
id = (
id = ANY(
SELECT
organization_id
FROM

View File

@ -38,7 +38,7 @@ SELECT
FROM
organizations
WHERE
id = (
id = ANY(
SELECT
organization_id
FROM

View File

@ -12,6 +12,28 @@ import (
"github.com/coder/coder/v2/testutil"
)
func TestMultiOrgFetch(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
_ = coderdtest.CreateFirstUser(t, client)
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
makeOrgs := []string{"foo", "bar", "baz"}
for _, name := range makeOrgs {
_, err := client.CreateOrganization(ctx, codersdk.CreateOrganizationRequest{
Name: name,
})
require.NoError(t, err)
}
orgs, err := client.OrganizationsByUser(ctx, codersdk.Me)
require.NoError(t, err)
require.NotNil(t, orgs)
require.Len(t, orgs, len(makeOrgs)+1)
}
func TestOrganizationsByUser(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)