tachybase_todo/packages/plugin-acl/src/__tests__/scope.test.ts
ChengLei Shao bd285e0ba9
Plugin acl (#166)
* feat: getRepository

* getRepository return type

* export action

* add: acl

* feat: setResourceAction

* feat: action alias

* chore: code struct

* feat: removeResourceAction

* chore: file name

* ignorecase

* remove ACL

* feat: ACL

* feat: role toJSON

* using emit

* chore: test

* feat: plugin-acl

* feat: acl with predicate

* grant universal action test

* grant action test

* update resource action test

* revoke resource action

* usingActionsConfig switch

* plugin-ui-schema-storage

* remove global acl instance

* fix: collection manager with sqlite

* add own action listener

* add acl middleware

* add acl allowConfigure strategy option

* add plugin-acl allowConfigure

* change acl resourceName

* add acl middleware merge params

* bugfix

* append fields on acl action params

* acl middleware parse template

* fix: collection-manager migrate

Co-authored-by: chenos <chenlinxh@gmail.com>
2022-01-24 14:10:35 +08:00

52 lines
1.1 KiB
TypeScript

import { prepareApp } from './prepare';
import { MockServer } from '@nocobase/test';
import { Database } from '@nocobase/database';
describe('scope api', () => {
let app: MockServer;
let db: Database;
afterEach(async () => {
await app.destroy();
});
beforeEach(async () => {
app = await prepareApp();
db = app.db;
await db.getRepository('roles').create({
values: {
name: 'admin',
title: 'Admin User',
allowConfigure: true,
},
});
});
it('should create scope of resource', async () => {
const response = await app
.agent()
.resource('rolesResourcesScopes')
.create({
values: {
resourceName: 'posts',
name: 'published posts',
scope: {
published: true,
},
},
});
expect(response.statusCode).toEqual(200);
const scope = await db.getRepository('rolesResourcesScopes').findOne({
filter: {
name: 'published posts',
},
});
expect(scope.get('scope')).toMatchObject({
published: true,
});
});
});