mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -3540,7 +3540,7 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
organizations
|
organizations
|
||||||
WHERE
|
WHERE
|
||||||
id = (
|
id = ANY(
|
||||||
SELECT
|
SELECT
|
||||||
organization_id
|
organization_id
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
organizations
|
organizations
|
||||||
WHERE
|
WHERE
|
||||||
id = (
|
id = ANY(
|
||||||
SELECT
|
SELECT
|
||||||
organization_id
|
organization_id
|
||||||
FROM
|
FROM
|
||||||
|
|||||||
@@ -12,6 +12,28 @@ import (
|
|||||||
"github.com/coder/coder/v2/testutil"
|
"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) {
|
func TestOrganizationsByUser(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
client := coderdtest.New(t, nil)
|
client := coderdtest.New(t, nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user