made some changes

This commit is contained in:
Dhroov Gupta
2019-07-17 14:42:19 +05:30
parent 59f1bd8378
commit 1e42c881a9
2 changed files with 8 additions and 21 deletions

View File

@@ -13,7 +13,6 @@ const sdk = require('postman-collection'),
URLENCODED = 'application/x-www-form-urlencoded',
APP_JSON = 'application/json',
APP_JS = 'application/javascript',
APP_XML = 'application/xml',
TEXT_XML = 'text/xml',
TEXT_PLAIN = 'text/plain',
TEXT_HTML = 'text/html',
@@ -114,7 +113,7 @@ module.exports = {
* @param {string} cTypeHeader - the content type header string
* @returns {string} format of content type header
*/
getContentTypeHeader: function(cTypeHeader) {
getContentTypeHeaderFormat: function(cTypeHeader) {
if (cTypeHeader.startsWith('application') && cTypeHeader.endsWith('json')) {
return 'json';
}
@@ -594,7 +593,7 @@ module.exports = {
}
for (let cType in contentObj) {
if (this.getContentTypeHeader(cType)) {
if (this.getContentTypeHeaderFormat(cType)) {
cTypeHeader = cType;
hasComputedType = true;
}
@@ -617,7 +616,7 @@ module.exports = {
}
responseBody = this.convertToPmBodyData(contentObj[cTypeHeader], cTypeHeader, this.options.indentCharacter);
if (this.getContentTypeHeader(cTypeHeader) === 'json') {
if (this.getContentTypeHeaderFormat(cTypeHeader) === 'json') {
responseBody = JSON.stringify(responseBody, null, this.options.indentCharacter);
}
else if (typeof responseBody !== 'string') {
@@ -730,7 +729,7 @@ module.exports = {
bodyObj.schema = this.getRefObject(bodyObj.schema.$ref);
}
if (this.options.schemaFaker) {
if (this.getContentTypeHeader(contentType) === 'xml') {
if (this.getContentTypeHeaderFormat(contentType) === 'xml') {
schemaType = SCHEMA_FORMATS.XML;
}
bodyData = safeSchemaFaker(bodyObj.schema || {}, this.components, schemaType, indentCharacter);
@@ -1169,23 +1168,11 @@ module.exports = {
if (responseBodyWrapper.contentTypeHeader) {
// we could infer the content-type header from the body
responseHeaders.push({ key: 'Content-Type', value: responseBodyWrapper.contentTypeHeader });
if (this.getContentTypeHeader(responseBodyWrapper.contentTypeHeader) === 'json' &&
responseBodyWrapper.contentTypeHeader.endsWith('json')) {
previewLanguage = 'json';
}
else if (this.getContentTypeHeader(responseBodyWrapper.contentTypeHeader) === 'xml' &&
responseBodyWrapper.contentTypeHeader.endsWith('xml')) {
previewLanguage = 'xml';
}
previewLanguage = this.getContentTypeHeaderFormat(responseBodyWrapper.contentTypeHeader);
}
else if (response.content && Object.keys(response.content).length > 0) {
responseHeaders.push({ key: 'Content-Type', value: Object.keys(response.content)[0] });
if (Object.keys(response.content)[0] === APP_JSON) {
previewLanguage = 'json';
}
else if (Object.keys(response.content)[0] === APP_XML) {
previewLanguage = 'xml';
}
previewLanguage = this.getContentTypeHeaderFormat(Object.keys(response.content)[0]);
}
else {
responseHeaders.push({ key: 'Content-Type', value: TEXT_PLAIN });

View File

@@ -166,12 +166,12 @@ describe('INTERFACE FUNCTION TESTS ', function () {
describe('Validate content type header function', function() {
it('should checks for custom type JSON header', function() {
let result = utils.getContentTypeHeader('application/vnd.retailer+json');
let result = utils.getContentTypeHeaderFormat('application/vnd.retailer+json');
expect(result).to.equal('json');
});
it('should checks for custom type xml header', function() {
let result = utils.getContentTypeHeader('application/vnd.retailer+xml');
let result = utils.getContentTypeHeaderFormat('application/vnd.retailer+xml');
expect(result).to.equal('xml');
});
});