Skip to content

Commit c07187d

Browse files
test: fix multi-tenant flakes (#12983)
1 parent 0e8ac0b commit c07187d

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

packages/plugin-multi-tenant/src/providers/TenantSelectionProvider/index.client.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,15 @@ export const TenantSelectionProviderClient = ({
187187
// Users with no cookie set and only 1 tenant should set that tenant automatically
188188
setTenant({ id: tenantOptionsFromProps[0]?.value, refresh: true })
189189
setTenantOptions(tenantOptionsFromProps)
190-
} else if ((!tenantOptions || tenantOptions.length === 0) && tenantOptionsFromProps) {
190+
} else if (
191+
(!tenantOptions || tenantOptions.length === 0) &&
192+
tenantOptionsFromProps.length > 0
193+
) {
194+
// If there are no tenant options, set them from the props
195+
setTenantOptions(tenantOptionsFromProps)
196+
}
197+
} else if (userID && tenantCookie) {
198+
if ((!tenantOptions || tenantOptions.length === 0) && tenantOptionsFromProps.length > 0) {
191199
// If there are no tenant options, set them from the props
192200
setTenantOptions(tenantOptionsFromProps)
193201
}

test/plugin-multi-tenant/e2e.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ test.describe('Multi Tenant', () => {
160160
data: credentials.admin,
161161
})
162162
await page.goto(globalMenuURL.list)
163-
await page.waitForURL(globalMenuURL.create)
164163
await expect(page.locator('.collection-edit')).toBeVisible()
165164
})
166165

@@ -282,6 +281,7 @@ test.describe('Multi Tenant', () => {
282281
urlUtil: tenantsURL,
283282
})
284283

284+
await expect(page.locator('#field-name')).toBeVisible()
285285
await page.locator('#field-name').fill('Red Dog')
286286
await saveDocAndAssert(page)
287287

test/plugin-multi-tenant/payload-types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ export interface User {
159159
hash?: string | null;
160160
loginAttempts?: number | null;
161161
lockUntil?: string | null;
162+
sessions?:
163+
| {
164+
id: string;
165+
createdAt?: string | null;
166+
expiresAt: string;
167+
}[]
168+
| null;
162169
password?: string | null;
163170
}
164171
/**
@@ -291,6 +298,13 @@ export interface UsersSelect<T extends boolean = true> {
291298
hash?: T;
292299
loginAttempts?: T;
293300
lockUntil?: T;
301+
sessions?:
302+
| T
303+
| {
304+
id?: T;
305+
createdAt?: T;
306+
expiresAt?: T;
307+
};
294308
}
295309
/**
296310
* This interface was referenced by `Config`'s JSON-Schema

0 commit comments

Comments
 (0)