* feat: improve code * chore: update version * feat: api service * fix: api services * feat: improve code * feat: improve code * feat: improve code * feat: pm socket * fix: test errors * feat: add built-in plugins before upgrade * feat: update docs * feat: improve code * fix: after load
75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
import { Database } from '@nocobase/database';
|
|
import UsersPlugin from '@nocobase/plugin-users';
|
|
import { MockServer } from '@nocobase/test';
|
|
import { prepareApp } from './prepare';
|
|
|
|
describe('configuration', () => {
|
|
let app: MockServer;
|
|
let db: Database;
|
|
let admin;
|
|
let adminAgent;
|
|
let user;
|
|
let userAgent;
|
|
let guestAgent;
|
|
|
|
afterEach(async () => {
|
|
await app.destroy();
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
app = await prepareApp();
|
|
db = app.db;
|
|
|
|
await db.getRepository('roles').create({
|
|
values: {
|
|
name: 'test1',
|
|
allowConfigure: true,
|
|
},
|
|
});
|
|
|
|
await db.getRepository('roles').create({
|
|
values: {
|
|
name: 'test2',
|
|
},
|
|
});
|
|
|
|
const UserRepo = db.getCollection('users').repository;
|
|
admin = await UserRepo.create({
|
|
values: {
|
|
roles: ['test1']
|
|
}
|
|
});
|
|
user = await UserRepo.create({
|
|
values: {
|
|
roles: ['test2']
|
|
}
|
|
});
|
|
|
|
const userPlugin = app.getPlugin('users') as UsersPlugin;
|
|
adminAgent = app.agent().auth(userPlugin.jwtService.sign({
|
|
userId: admin.get('id'),
|
|
}), { type: 'bearer' });
|
|
|
|
userAgent = app.agent().auth(userPlugin.jwtService.sign({
|
|
userId: user.get('id'),
|
|
}), { type: 'bearer' });
|
|
|
|
guestAgent = app.agent();
|
|
});
|
|
|
|
it('should list collections', async () => {
|
|
expect((await userAgent.resource('collections').create()).statusCode).toEqual(403);
|
|
expect((await userAgent.resource('collections').list()).statusCode).toEqual(200);
|
|
});
|
|
|
|
it('should not create/list collections', async () => {
|
|
expect((await guestAgent.resource('collections').create()).statusCode).toEqual(403);
|
|
expect((await guestAgent.resource('collections').list()).statusCode).toEqual(403);
|
|
});
|
|
|
|
it('should allow when role has allowConfigure with true value', async () => {
|
|
expect((await adminAgent.resource('collections').create()).statusCode).toEqual(200);
|
|
expect((await adminAgent.resource('collections').list()).statusCode).toEqual(200);
|
|
});
|
|
});
|