123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import {api} from "./restful";
- import {Resp} from "@util/Resp";
- import {models} from "@core-models/Models";
- import {AcsModule} from "@core-models/AcsModule";
- 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`,
- ]
- export const acs_function_test = () => {
- let function_id;
- beforeAll(async (done) => {
- globalAny.user_id = 'admin';
- await globalAny.svr.init_data_models(models);
- let sequelize = AcsModule.sequelize!;
- for (let i = 0; i < sqls.length; i++) {
- await sequelize.query(sqls[i]);
- }
- done();
- }, 30000);
- test('添加功能项', async () => {
- let result = await api('/api/acs.function.add', {
- module_id: 200001,
- tag: 'function',
- name: '功能项',
- check_auth: true
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.id).toBeDefined();
- function_id = result.data.id;
- });
- test('获取功能项列表', async () => {
- let result = await api('/api/acs.function.get_list', {
- module_id: 200001
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.functions).toBeDefined();
- expect(result.data.functions.length).toBe(1);
- expect(result.data.functions[0].id).toBe(function_id);
- expect(result.data.functions[0].tag).toBe('function');
- expect(result.data.functions[0].name).toBe('功能项');
- expect(result.data.functions[0].api).toBe('test1.test2.function');
- expect(result.data.functions[0].check_auth).toBe(true);
- });
- test('修改功能项', async () => {
- let result = await api('/api/acs.function.modify', {
- id: function_id,
- name: '功能项new',
- check_auth: false
- });
- expect(result.code).toBe(Resp.OK.code);
- });
- test('获取功能项列表', async () => {
- let result = await api('/api/acs.function.get_list', {
- module_id: 200001
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.functions).toBeDefined();
- expect(result.data.functions.length).toBe(1);
- expect(result.data.functions[0].id).toBe(function_id);
- expect(result.data.functions[0].tag).toBe('function');
- expect(result.data.functions[0].name).toBe('功能项new');
- expect(result.data.functions[0].api).toBe('test1.test2.function');
- expect(result.data.functions[0].check_auth).toBe(false);
- });
- test('删除功能项', async () => {
- let result = await api('/api/acs.function.remove', {
- id: function_id
- });
- expect(result.code).toBe(Resp.Forbidden.code);
- });
- test('删除功能项', async () => {
- globalAny.user_id = 'administrator';
- let result = await api('/api/acs.function.remove', {
- id: function_id
- });
- expect(result.code).toBe(Resp.OK.code);
- });
- test('获取功能项列表', async () => {
- let result = await api('/api/acs.function.get_list', {
- module_id: 200001
- });
- expect(result.code).toBe(Resp.OK.code);
- expect(result.data).toBeDefined();
- expect(result.data.functions).toBeDefined();
- expect(result.data.functions.length).toBe(0);
- });
- }
|