@itentialopensource/adapter-utils
Advanced tools
Comparing version 4.27.3 to 4.27.4
## 4.27.4 [01-07-2020] | ||
* fix for the mock path return data | ||
See merge request itentialopensource/adapter-utils!149 | ||
--- | ||
## 4.27.3 [12-30-2019] | ||
@@ -3,0 +11,0 @@ |
@@ -25,12 +25,15 @@ /* @copyright Itential, LLC 2018 */ | ||
*/ | ||
function matchResponse(uriPath, method, type, responseKeys) { | ||
// Go through the response keys to find the proper one | ||
for (let p = 0; p < responseKeys.length; p += 1) { | ||
// is this the response for this call | ||
if (responseKeys[p].name && uriPath === responseKeys[p].name) { | ||
if (responseKeys[p].method && method.toUpperCase() === responseKeys[p].method.toUpperCase()) { | ||
if (responseKeys[p].type && type === responseKeys[p].type.toUpperCase()) { | ||
function matchResponse(uriPath, method, type, mockresponses) { | ||
// Go through the mock data keys to find the proper data to return | ||
for (let p = 0; p < mockresponses.length; p += 1) { | ||
// is this the mock data for this call | ||
if (Object.hasOwnProperty.call(mockresponses[p], 'name') | ||
&& uriPath === mockresponses[p].name) { | ||
if (Object.hasOwnProperty.call(mockresponses[p], 'method') | ||
&& method.toUpperCase() === mockresponses[p].method.toUpperCase()) { | ||
if (Object.hasOwnProperty.call(mockresponses[p], 'type') | ||
&& type.toUpperCase() === mockresponses[p].type.toUpperCase()) { | ||
// This is the Key we really want as it best matches the request | ||
if (Object.hasOwnProperty.call(responseKeys[p], 'key')) { | ||
return responseKeys[p].key; | ||
if (Object.hasOwnProperty.call(mockresponses[p], 'key')) { | ||
return mockresponses[p].key; | ||
} | ||
@@ -45,2 +48,56 @@ } | ||
/* | ||
* INTERNAL FUNCTION: recursively inspect body data if heirarchical | ||
*/ | ||
function checkBodyData(uriPath, method, reqBdObj, mockresponses) { | ||
let specificResp = null; | ||
if (reqBdObj) { | ||
const reqBKeys = Object.keys(reqBdObj); | ||
// go through each key in the passed in object | ||
for (let k = 0; k < reqBKeys.length; k += 1) { | ||
const bVal = reqBdObj[reqBKeys[k]]; | ||
if (bVal !== undefined && bVal !== null && bVal !== '') { | ||
// if the field is an object and not an array - recursively call with the new field value | ||
if (typeof bVal === 'object' && !Array.isArray(bVal)) { | ||
specificResp = checkBodyData(uriPath, method, bVal, mockresponses); | ||
} else if (Array.isArray(bVal) && bVal.length > 0 && (typeof bVal[0] === 'object')) { | ||
// if the field is an array containing objects - recursively call with each object in the array | ||
for (let a = 0; a < bVal.length; a += 1) { | ||
specificResp = checkBodyData(uriPath, method, bVal[a], mockresponses); | ||
// if the data match is found break the for loop - will return below | ||
if (specificResp !== null) { | ||
break; | ||
} | ||
} | ||
} else if (Array.isArray(bVal)) { | ||
// if an array of data, need to check each data in the array | ||
for (let a = 0; a < bVal.length; a += 1) { | ||
// should match fieldName-fieldValue | ||
const compStr = `${reqBKeys[k]}-${bVal[a]}`; | ||
specificResp = matchResponse(uriPath, method, compStr, mockresponses); | ||
// if the data match is found break the for loop - will return below | ||
if (specificResp !== null) { | ||
break; | ||
} | ||
} | ||
} else { | ||
// should match fieldName-fieldValue | ||
const compStr = `${reqBKeys[k]}-${bVal}`; | ||
specificResp = matchResponse(uriPath, method, compStr, mockresponses); | ||
} | ||
if (specificResp !== null) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
return specificResp; | ||
} | ||
/** | ||
@@ -114,6 +171,6 @@ * INTERNAL FUNCTION | ||
// if there is a request body, see if there is something that matches a specific input | ||
if (reqBody && (!entitySchema || !entitySchema.responseDatatype | ||
|| entitySchema.responseDatatype.toUpperCase() === 'JSON' || entitySchema.responseDatatype.toUpperCase() === 'URLENCODE')) { | ||
if (reqBody && (!entitySchema || !entitySchema.requestDatatype | ||
|| entitySchema.requestDatatype.toUpperCase() === 'JSON' || entitySchema.requestDatatype.toUpperCase() === 'URLENCODE')) { | ||
let reqBdObj = null; | ||
if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'URLENCODE') { | ||
if (entitySchema && entitySchema.requestDatatype && entitySchema.requestDatatype.toUpperCase() === 'URLENCODE') { | ||
reqBdObj = querystring.parse(reqBody.trim()); | ||
@@ -123,12 +180,4 @@ } else { | ||
} | ||
const reqBKeys = Object.keys(reqBdObj); | ||
for (let k = 0; k < reqBKeys.length; k += 1) { | ||
const bVal = `${reqBKeys[k]}-${reqBdObj[reqBKeys[k]]}`; | ||
respObjKey = matchResponse(uriPath, method, bVal.toUpperCase(), responseKeys); | ||
if (respObjKey !== null) { | ||
break; | ||
} | ||
} | ||
respObjKey = checkBodyData(uriPath, method, reqBdObj, responseKeys); | ||
} | ||
@@ -159,3 +208,3 @@ | ||
if (uriArray[i].indexOf('{pathv') >= 0) { | ||
respObjKey = matchResponse(uriPath, method, actArray[i].toUpperCase(), responseKeys); | ||
respObjKey = matchResponse(uriPath, method, actArray[i], responseKeys); | ||
@@ -172,10 +221,15 @@ if (respObjKey !== null) { | ||
if (respObjKey === null && reqPath.indexOf('?') >= 0) { | ||
const queries = reqPath.substring(reqPath.indexOf('?')); | ||
const queries = reqPath.substring(reqPath.indexOf('?') + 1); | ||
const queryArr = queries.split('&'); | ||
for (let q = 0; q < queryArr.length; q += 1) { | ||
respObjKey = matchResponse(uriPath, method, queryArr[q].toUpperCase(), responseKeys); | ||
let qval = queryArr[q]; | ||
if (qval !== undefined && qval !== null && qval !== '') { | ||
// stringifies it - in case it was not a string | ||
qval = `${qval}`; | ||
respObjKey = matchResponse(uriPath, method, qval, responseKeys); | ||
if (respObjKey !== null) { | ||
break; | ||
if (respObjKey !== null) { | ||
break; | ||
} | ||
} | ||
@@ -182,0 +236,0 @@ } |
{ | ||
"name": "@itentialopensource/adapter-utils", | ||
"version": "4.27.3", | ||
"version": "4.27.4", | ||
"description": "Itential Adapter Utility Libraries", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -708,16 +708,16 @@ { | ||
}, | ||
"replSet": { | ||
"password": { | ||
"type": "string", | ||
"description": "The replica set for the database", | ||
"description": "The password to connect to the database with", | ||
"default": "", | ||
"examples": [ | ||
"my_repolica_set" | ||
"password" | ||
] | ||
}, | ||
"password": { | ||
"replSet": { | ||
"type": "string", | ||
"description": "The password to connect to the database with", | ||
"description": "The replica set for the database", | ||
"default": "", | ||
"examples": [ | ||
"password" | ||
"my_repolica_set" | ||
] | ||
@@ -724,0 +724,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1579951
13704