mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-31 14:50:26 +08:00
fix: 高级mock 匹配 data: [{item: XXX}] 时匹配不成功
This commit is contained in:
parent
053589ed70
commit
8e2839e2e8
@ -6,6 +6,7 @@
|
||||
#### Bug Fixed
|
||||
|
||||
* 接口path中写入 ?name=xxx bug
|
||||
* 高级mock 匹配 data: [{item: XXX}] 时匹配不成功
|
||||
|
||||
### v1.3.22
|
||||
|
||||
|
@ -18,6 +18,9 @@ function getLength(object) {
|
||||
|
||||
function Compare(objA, objB) {
|
||||
if (!isObj(objA) && !isObj(objB)) {
|
||||
if (isArray(objA) && isArray(objB)) {
|
||||
return CompareArray(objA, objB, true);
|
||||
}
|
||||
return objA == objB;
|
||||
}
|
||||
if (!isObj(objA) || !isObj(objB)) return false;
|
||||
@ -25,6 +28,18 @@ function Compare(objA, objB) {
|
||||
return CompareObj(objA, objB, true);
|
||||
}
|
||||
|
||||
function CompareArray(objA, objB, flag) {
|
||||
if (objA.length != objB.length) return false;
|
||||
for (let i in objB) {
|
||||
if (!Compare(objA[i], objB[i])) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
function CompareObj(objA, objB, flag) {
|
||||
for (var key in objA) {
|
||||
if (!flag) break;
|
||||
@ -60,6 +75,7 @@ function CompareObj(objA, objB, flag) {
|
||||
exports.jsonEqual = Compare;
|
||||
|
||||
exports.isDeepMatch = function(obj, properties) {
|
||||
|
||||
if (!properties || typeof properties !== 'object' || Object.keys(properties).length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ var hooks = {
|
||||
},
|
||||
/**
|
||||
* 客户端删除接口成功后触发
|
||||
* @param data 删除接口的详细信息
|
||||
* @param data 接口id
|
||||
*/
|
||||
interface_del: {
|
||||
type: 'multi',
|
||||
|
@ -721,7 +721,7 @@ class interfaceController extends baseController {
|
||||
|
||||
// let inter = await this.Model.get(id);
|
||||
let result = await this.Model.del(id);
|
||||
yapi.emitHook('interface_del', data).then();
|
||||
yapi.emitHook('interface_del', id).then();
|
||||
await this.caseModel.delByInterfaceId(id);
|
||||
let username = this.getUsername();
|
||||
this.catModel.get(data.catid).then(cate => {
|
||||
@ -890,7 +890,7 @@ class interfaceController extends baseController {
|
||||
|
||||
interfaceData.forEach(async item => {
|
||||
try {
|
||||
yapi.emitHook('interface_del', item).then();
|
||||
yapi.emitHook('interface_del', item._id).then();
|
||||
await this.caseModel.delByInterfaceId(item._id);
|
||||
} catch (e) {
|
||||
yapi.commons.log(e.message, 'error');
|
||||
|
@ -148,7 +148,8 @@ class interfaceColController extends baseController {
|
||||
async testDelete(ctx) {
|
||||
try {
|
||||
let params = ctx.request.query;
|
||||
ctx.body = yapi.commons.resReturn(params);
|
||||
let body = ctx.request.body;
|
||||
ctx.body = yapi.commons.resReturn(body);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ var hooks = {
|
||||
},
|
||||
/**
|
||||
* 客户端删除接口成功后触发
|
||||
* @param data 删除接口的详细信息
|
||||
* @param data 接口id
|
||||
*/
|
||||
interface_del: {
|
||||
type: 'multi',
|
||||
|
@ -165,4 +165,16 @@ test('isDeepMatch', t=>{
|
||||
params: { a: 'x', b: 'y' },
|
||||
res_body: '111',
|
||||
code: 1 }, {t:'1'}))
|
||||
})
|
||||
})
|
||||
|
||||
test('isDeepMatch', t=>{
|
||||
t.true(lib.isDeepMatch({ t:[{a: 1}]}, { t:[{a: 1}]}))
|
||||
})
|
||||
|
||||
test('isDeepMatch', t=>{
|
||||
t.false(lib.isDeepMatch({ t:[{a: 1, b: 12}]}, { t:[{a: 1}]}))
|
||||
})
|
||||
|
||||
test('isDeepMatch', t=>{
|
||||
t.true(lib.isDeepMatch([{a: 1}], [{a: 1}]))
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user