|  | @@ -11,32 +11,6 @@ const { app, assert } = require('egg-mock/bootstrap');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  describe('test/app/extend/helper.test.js', () => {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    it('validateConvert test', function* () {
 | 
	
		
			
				|  |  | -        // 创建 ctx
 | 
	
		
			
				|  |  | -        const ctx = app.mockContext();
 | 
	
		
			
				|  |  | -        const rule = {
 | 
	
		
			
				|  |  | -            username: { type: 'string', required: true, allowEmpty: false, min: 4, max: 10 },
 | 
	
		
			
				|  |  | -            group_id: { type: 'integer', required: true, allowEmpty: false, min: 4, max: 10 },
 | 
	
		
			
				|  |  | -            password: { type: 'password', required: true, allowEmpty: false, min: 4 },
 | 
	
		
			
				|  |  | -            confirm_password: { type: 'password', required: true, allowEmpty: false, min: 4, compare: 'password' },
 | 
	
		
			
				|  |  | -            ip: { type: 'ip', allowEmpty: false },
 | 
	
		
			
				|  |  | -            telephone: { type: 'mobile', allowEmpty: false },
 | 
	
		
			
				|  |  | -        };
 | 
	
		
			
				|  |  | -        // 转换为json验证
 | 
	
		
			
				|  |  | -        let convertRule = ctx.helper.validateConvert(rule);
 | 
	
		
			
				|  |  | -        convertRule = JSON.stringify(convertRule);
 | 
	
		
			
				|  |  | -        let expectRule = {
 | 
	
		
			
				|  |  | -            username: { required: true, minlength: 4, maxlength: 10 },
 | 
	
		
			
				|  |  | -            group_id: { required: true, min: 4, max: 10 },
 | 
	
		
			
				|  |  | -            password: { required: true, minlength: 4 },
 | 
	
		
			
				|  |  | -            confirm_password: { required: true, minlength: 4, equalTo: '#password' },
 | 
	
		
			
				|  |  | -            ip: { ip: true, required: true },
 | 
	
		
			
				|  |  | -            telephone: { mobile: true, required: true },
 | 
	
		
			
				|  |  | -        };
 | 
	
		
			
				|  |  | -        expectRule = JSON.stringify(expectRule);
 | 
	
		
			
				|  |  | -        assert(convertRule === expectRule);
 | 
	
		
			
				|  |  | -    });
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      it('generateRandomString test', function* () {
 | 
	
		
			
				|  |  |          // 创建 ctx
 | 
	
		
			
				|  |  |          const ctx = app.mockContext();
 | 
	
	
		
			
				|  | @@ -98,4 +72,21 @@ describe('test/app/extend/helper.test.js', () => {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          assert(result);
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    it('test permission', function* () {
 | 
	
		
			
				|  |  | +        // 创建 ctx
 | 
	
		
			
				|  |  | +        const ctx = app.mockContext();
 | 
	
		
			
				|  |  | +        ctx.session = {
 | 
	
		
			
				|  |  | +            sessionUser: {
 | 
	
		
			
				|  |  | +                permission: '1,2,3,4',
 | 
	
		
			
				|  |  | +            },
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        const permission = require('../../../config/permission');
 | 
	
		
			
				|  |  | +        let result = ctx.helper.hasPermission(permission.permission.VIEW_STAGE_MEASURE);
 | 
	
		
			
				|  |  | +        assert(!result);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 多个权限判断
 | 
	
		
			
				|  |  | +        result = ctx.helper.hasPermission([permission.permission.CREATE_TENDER, permission.permission.VIEW_ALL_TENDER]);
 | 
	
		
			
				|  |  | +        assert(result);
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  |  });
 |