First account of the auth collection always becomes admin
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
561a9e2bb7
commit
78f4f5c16b
@@ -117,3 +117,26 @@ describe('forms collection: public read, editor+ write, Emails hidden from plain
|
||||
expect(emails.access?.read?.({ req: { user: editor } })).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('roles field: the first account becomes admin', () => {
|
||||
const hook = async (totalDocs: number, value: string[]) => {
|
||||
const config = await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: false })(empty())
|
||||
const users = config.collections?.find((c) => c.slug === 'users') as CollectionConfig
|
||||
const roles = users.fields.find((f) => 'name' in f && f.name === 'roles') as { hooks?: { beforeChange?: ((a: unknown) => unknown)[] } }
|
||||
const count = vi.fn(async () => ({ totalDocs }))
|
||||
return roles.hooks?.beforeChange?.[0]?.({
|
||||
collection: { slug: 'users' },
|
||||
operation: 'create',
|
||||
req: { payload: { count } },
|
||||
value,
|
||||
})
|
||||
}
|
||||
|
||||
test('empty collection → admin, whatever was sent', async () => {
|
||||
expect(await hook(0, ['user'])).toEqual(['admin'])
|
||||
})
|
||||
|
||||
test('later accounts keep what access allowed', async () => {
|
||||
expect(await hook(1, ['user'])).toEqual(['user'])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user