|
@@ -40,4 +40,20 @@ describe('test/app/lib/js_validator.test.js', () => {
|
|
|
assert(convertRule === expectRule);
|
|
|
});
|
|
|
|
|
|
+ it('test js validator', function* () {
|
|
|
+ const ctx = app.mockContext();
|
|
|
+ const jsValidator = new JsValidator(ctx);
|
|
|
+
|
|
|
+ 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 },
|
|
|
+ };
|
|
|
+ const jsCode = jsValidator.convert(rule).build();
|
|
|
+ assert(jsCode !== '');
|
|
|
+ });
|
|
|
+
|
|
|
});
|