From c64f15d4d98f17caf5960f4fc135314972a29543 Mon Sep 17 00:00:00 2001 From: Dan Ribbens Date: Fri, 23 Sep 2022 03:26:26 -0400 Subject: [PATCH] test: field level access for nested fields --- test/access-control/config.ts | 46 ++++++++++++++++++++++++++++++++- test/access-control/e2e.spec.ts | 26 ++++++++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/test/access-control/config.ts b/test/access-control/config.ts index 3cc59faf8..8eed5be93 100644 --- a/test/access-control/config.ts +++ b/test/access-control/config.ts @@ -25,7 +25,7 @@ const PublicReadabilityAccess: FieldAccess = ({ req: { user }, siblingData }) => return false; }; -export const requestHeaders = {authorization: 'Bearer testBearerToken'}; +export const requestHeaders = { authorization: 'Bearer testBearerToken' }; const UseRequestHeadersAccess: FieldAccess = ({ req: { headers } }) => { return !!headers && headers.authorization === requestHeaders.authorization; }; @@ -47,6 +47,50 @@ export default buildConfig({ update: () => false, }, }, + { + type: 'group', + name: 'group', + fields: [ + { + name: 'restrictedGroupText', + type: 'text', + access: { + read: () => false, + update: () => false, + create: () => false, + }, + }, + ], + }, + { + type: 'row', + fields: [ + { + name: 'restrictedRowText', + type: 'text', + access: { + read: () => false, + update: () => false, + create: () => false, + }, + }, + ], + }, + { + type: 'collapsible', + label: 'Access', + fields: [ + { + name: 'restrictedCollapsibleText', + type: 'text', + access: { + read: () => false, + update: () => false, + create: () => false, + }, + }, + ], + }, ], }, { diff --git a/test/access-control/e2e.spec.ts b/test/access-control/e2e.spec.ts index f248966fa..afbdbe64f 100644 --- a/test/access-control/e2e.spec.ts +++ b/test/access-control/e2e.spec.ts @@ -44,7 +44,31 @@ describe('access control', () => { await page.goto(url.edit(id)); - await expect(page.locator('input[name="restrictedField"]')).toHaveCount(0); + await expect(page.locator('#field-restrictedField')).toHaveCount(0); + }); + + test('field without read access inside a group should not show', async () => { + const { id } = await createDoc({ restrictedField: 'restricted' }); + + await page.goto(url.edit(id)); + + await expect(page.locator('#field-group__restrictedGroupText')).toHaveCount(0); + }); + + test('field without read access inside a collapsible should not show', async () => { + const { id } = await createDoc({ restrictedField: 'restricted' }); + + await page.goto(url.edit(id)); + + await expect(page.locator('#field-restrictedRowText')).toHaveCount(0); + }); + + test('field without read access inside a row should not show', async () => { + const { id } = await createDoc({ restrictedField: 'restricted' }); + + await page.goto(url.edit(id)); + + await expect(page.locator('#field-restrictedCollapsibleText')).toHaveCount(0); }); describe('restricted collection', () => {