import * as Scope from './Scope.js' describe('schema.Zone', () => { test('accepts concrete read and write scopes', () => { expect( ['zone:421700005:read', 'zone:421700005:write'].map((scope) => Scope.schema.Zone.safeParse(scope), ), ).toMatchObject([{ success: true }, { success: true }]) }) test('rejects templates and unsupported access levels', () => { expect( ['zone::read', 'zone:421700005:admin'].map((scope) => Scope.schema.Zone.safeParse(scope), ), ).toMatchObject([{ success: false }, { success: false }]) }) }) describe('extend', () => { test('appends host scopes to the built-in catalog', () => { expect( Scope.extend([ { description: 'Read project accounts.', scope: 'accounts:read', selfServe: true, }, ]), ).toEqual([ ...Scope.catalog, Scope.zoneEntry, Scope.zoneWriteEntry, { description: 'Read project accounts.', scope: 'accounts:read', selfServe: true, }, ]) }) test('rejects duplicate scope identifiers', () => { expect(() => Scope.extend([ { description: 'Duplicate data scope.', scope: 'data:read', selfServe: true, }, ]), ).toThrowErrorMatchingInlineSnapshot(`[Error: Duplicate scope \`data:read\`.]`) }) }) describe('expandAliases', () => { test('adds the current scope for a legacy Zone read scope', () => { expect( Scope.expandAliases(['data:read', 'zone:1424310001:read', 'zone:1424310001:write']), ).toEqual([ 'data:read', 'zone:1424310001:read', 'zone:1424310001:write', 'zone:1424310003:read', ]) }) test('does not duplicate an existing current scope', () => { expect(Scope.expandAliases(['zone:1424310001:read', 'zone:1424310003:read'])).toEqual([ 'zone:1424310001:read', 'zone:1424310003:read', ]) }) })