mirror of https://github.com/coder/coder.git
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:
parent
da376549a3
commit
d4d8424ce0
|
@ -3540,7 +3540,7 @@ SELECT
|
|||
FROM
|
||||
organizations
|
||||
WHERE
|
||||
id = (
|
||||
id = ANY(
|
||||
SELECT
|
||||
organization_id
|
||||
FROM
|
||||
|
|
|
@ -38,7 +38,7 @@ SELECT
|
|||
FROM
|
||||
organizations
|
||||
WHERE
|
||||
id = (
|
||||
id = ANY(
|
||||
SELECT
|
||||
organization_id
|
||||
FROM
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue