|
@@ -30,8 +30,8 @@ describe('test/app/extend/helper.test.js', () => {
|
|
|
group_id: { required: true, min: 4, max: 10 },
|
|
|
password: { required: true, minlength: 4 },
|
|
|
confirm_password: { required: true, minlength: 4, equalTo: '#password' },
|
|
|
- ip: { type: 'ip', allowEmpty: false },
|
|
|
- telephone: { type: 'mobile', allowEmpty: false },
|
|
|
+ ip: { ip: true, required: true },
|
|
|
+ telephone: { mobile: true, required: true },
|
|
|
};
|
|
|
expectRule = JSON.stringify(expectRule);
|
|
|
assert(convertRule === expectRule);
|
|
@@ -80,4 +80,22 @@ describe('test/app/extend/helper.test.js', () => {
|
|
|
assert(responseData.data.ip === '116.7.222.12');
|
|
|
});
|
|
|
|
|
|
+ it('explode paths', function* () {
|
|
|
+ // 创建 ctx
|
|
|
+ const ctx = app.mockContext();
|
|
|
+ const paths = ['1.2.3.4.5', '1.2.3.5.7'];
|
|
|
+ const normal = ctx.helper.explodePath(paths, '.');
|
|
|
+ const normalExpect = ['1', '1.2', '1.2.3', '1.2.3.4', '1.2.3.4.5', '1.2.3.5', '1.2.3.5.7'];
|
|
|
+ let result = true;
|
|
|
+ try {
|
|
|
+ for (const index in normal) {
|
|
|
+ if (normal[index] !== normalExpect[index]) {
|
|
|
+ throw '数据错误';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ assert(result);
|
|
|
+ });
|
|
|
});
|