123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- import {api} from "./restful";
- import {Resp} from "@util/Resp";
- import {models} from "@core-models/Models";
- import {AcsModule} from "@core-models/AcsModule";
- import {AcsRole} from "@core-models/AcsRole";
- import {AcsFunction} from "@core-models/AcsFunction";
- import {AcsUserRole} from "@core-models/AcsUserRole";
- const globalAny: any = global;
- let sqls = [
- `insert into ${AcsModule.table_name} (id, tag, name, pid, path, path_name)
- values (200000, 'test1', '一级', null, '200000', 'test1'),
- (200001, 'test2', '一级', 200000, '200000.200001', 'test1.test2') ON CONFLICT DO NOTHING`,
- `insert into ${AcsFunction.table_name} (id, tag, name, module_id, api, check_auth)
- values (200000, 'function1', '功能项', 200001, 'test1.test2.function1', true),
- (200001, 'function2', '功能项', 200001, 'test1.test2.function2', true) ON CONFLICT DO NOTHING`
- ]
- export const acs_role_test = () => {
- beforeAll(async (done) => {
- globalAny.user_id = 'admin';
- await globalAny.svr.init_data_models(models);
- let sequelize = AcsRole.sequelize!;
- for (let i = 0; i < sqls.length; i++) {
- await sequelize.query(sqls[i]);
- }
- done();
- }, 30000);
- test('添加角色', async () => {
- let result = await api('/api/acs.role.add', {
- role_id: 'role_id',
- role_name: 'role_name'
- });
- expect(result.code).toBe(Resp.OK.code);
- });
- test('获取角色列表', async () => {
- let result = await api('/api/acs.role.get_list', {
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.roles).toBeDefined();
- expect(result.data.roles.length).toBe(2);
- expect(result.data.roles).toContainEqual({id: 'role_id', name: 'role_name'})
- });
- test('修改角色', async () => {
- let result = await api('/api/acs.role.modify', {
- role_id: 'role_id',
- role_name: 'role_name_new'
- });
- expect(result.code).toBe(Resp.OK.code);
- });
- test('获取角色列表2', async () => {
- let result = await api('/api/acs.role.get_list', {
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.roles).toBeDefined();
- expect(result.data.roles).toContainEqual({id: 'role_id', name: 'role_name_new'})
- });
- test('获取角色列表2', async () => {
- let result = await api('/api/acs.role.get_list', {
- keyword: 'role_name'
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.roles).toBeDefined();
- expect(result.data.roles.length).toBe(1);
- expect(result.data.roles).toContainEqual({id: 'role_id', name: 'role_name_new'})
- });
- test('获取角色对应的功能项', async () => {
- // await AcsUserRole.sequelize!.query(`insert into ${AcsUserRole.table_name} values ('admin', 'role_id')`);
- let result = await api('/api/acs.role.get_funcs', {
- role_id: 'role_id',
- module_id: 6
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.funcs).toBeDefined();
- });
- test('设置角色对应的功能项', async () => {
- let result = await api('/api/acs.role.set_funcs', {
- role_id: 'role_id',
- funcs: [
- {
- id: 35, enabled: true
- },
- {
- id: 36, enabled: true
- }
- ]
- });
- expect(result.code).toBe(Resp.OK.code);
- });
- test('获取角色对应的功能项', async () => {
- let result = await api('/api/acs.role.get_funcs', {
- role_id: 'role_id',
- module_id: 6
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.funcs).toBeDefined();
- expect(result.data.funcs).toContainEqual(
- {
- api: 'acs.role.get_funcs', name: '获取角色对应的功能项', id: 35, enabled: true
- }
- );
- expect(result.data.funcs).toContainEqual(
- {
- api: 'acs.role.set_funcs', name: '设置角色对应的功能项', id: 36, enabled: true
- }
- );
- });
- test('设置角色对应的功能项', async () => {
- let result = await api('/api/acs.role.set_funcs', {
- role_id: 'role_id',
- funcs: [
- {
- id: 35, enabled: true
- },
- {
- id: 36, enabled: false
- }
- ]
- });
- expect(result.code).toBe(Resp.OK.code);
- });
- test('获取角色对应的功能项', async () => {
- let result = await api('/api/acs.role.get_funcs', {
- role_id: 'role_id',
- module_id: 6
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.funcs).toBeDefined();
- expect(result.data.funcs).toContainEqual(
- {
- api: 'acs.role.get_funcs', name: '获取角色对应的功能项', id: 35, enabled: true
- }
- );
- expect(result.data.funcs).toContainEqual(
- {
- api: 'acs.role.set_funcs', name: '设置角色对应的功能项', id: 36, enabled: false
- }
- );
- });
- test('删除角色', async () => {
- let result = await api('/api/acs.role.remove', {
- role_id: 'role_id'
- });
- expect(result.code).toBe(Resp.OK.code);
- });
- test('获取角色列表', async () => {
- let result = await api('/api/acs.role.get_list', {
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.roles).toBeDefined();
- expect(result.data.roles.length).toBe(1);
- });
- }
|