Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
add xml2js's config to param config of testgen function
Browse files Browse the repository at this point in the history
  • Loading branch information
SrHuevo committed Mar 9, 2018
1 parent c31bf4e commit 2974eb3
Show file tree
Hide file tree
Showing 18 changed files with 259 additions and 136 deletions.
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ function isEmpty(val) {
return val == null || val.length <= 0;
}

/**
* To get xml2js's config as a string
* @private
* @param {object} xml2jsConfig a xml2js's config
* @returns {string} return xml2js's config as a string
*/
function getStringXml2jsConfig(xml2jsConfig) {
return JSON.stringify(xml2jsConfig || {}).replace(/"(.+)":/, '$1: ').replace('"', '\'');
}

/**
* Populate property of the swagger project
* @private
Expand Down Expand Up @@ -89,6 +99,8 @@ function getData(swagger, apiPath, operation, response, config, info) {
data.pathParams = config.pathParams;
}

data.xml2jsConfig = getStringXml2jsConfig(config.xml2js);

// used for checking requestData table
var requestPath = (swagger.basePath) ? path.posix.join(swagger.basePath, apiPath) : apiPath;

Expand Down
4 changes: 3 additions & 1 deletion templates/request/delete/delete.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
done();
{{/isJsonMediaType}}
{{#isXmlMediaType returnType}}
parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {{xml2jsConfig}};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
{{#is assertion 'expect'}}
expect(validator.validate(body, schema)).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion templates/request/get/get.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
done();
{{/isJsonMediaType}}
{{#isXmlMediaType returnType}}
parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {{xml2jsConfig}};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
{{#is assertion 'expect'}}
expect(validator.validate(result, schema)).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion templates/request/patch/patch.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
done();
{{/isJsonMediaType}}
{{#isXmlMediaType returnType}}
parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {{xml2jsConfig}};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
{{#is assertion 'expect'}}
expect(validator.validate(body, schema)).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion templates/request/post/post.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
done();
{{/isJsonMediaType}}
{{#isXmlMediaType returnType}}
parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {{xml2jsConfig}};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
{{#is assertion 'expect'}}
expect(validator.validate(result, schema)).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion templates/request/put/put.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
done();
{{/isJsonMediaType}}
{{#isXmlMediaType returnType}}
parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {{xml2jsConfig}};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
{{#is assertion 'expect'}}
expect(validator.validate(body, schema)).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion templates/supertest/delete/delete.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
done();
{{/isJsonMediaType}}
{{#isXmlMediaType returnType}}
parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {{xml2jsConfig}};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if(parseErr) return done(parseErr);
{{#is assertion 'expect'}}
expect(validator.validate(result, schema)).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion templates/supertest/get/get.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
done();
{{/isJsonMediaType}}
{{#isXmlMediaType returnType}}
parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {{xml2jsConfig}};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
{{#is assertion 'expect'}}
expect(validator.validate(result, schema)).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion templates/supertest/patch/patch.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
done();
{{/isJsonMediaType}}
{{#isXmlMediaType returnType}}
parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {{xml2jsConfig}};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
{{#is assertion 'expect'}}
expect(validator.validate(result, schema)).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion templates/supertest/post/post.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
done();
{{/isJsonMediaType}}
{{#isXmlMediaType returnType}}
parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {{xml2jsConfig}};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
{{#is assertion 'expect'}}
expect(validator.validate(result, schema)).to.be.true;
Expand Down
4 changes: 3 additions & 1 deletion templates/supertest/put/put.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
done();
{{/isJsonMediaType}}
{{#isXmlMediaType returnType}}
parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {{xml2jsConfig}};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
{{#is assertion 'expect'}}
expect(validator.validate(result, schema)).to.be.true;
Expand Down
24 changes: 18 additions & 6 deletions test/xmlConsumeTypeTest/compare/request/assert/base-path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ describe('/', function() {

assert.equal(res.statusCode, 200);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down Expand Up @@ -124,7 +126,9 @@ describe('/', function() {

assert.equal(res.statusCode, 400);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down Expand Up @@ -171,7 +175,9 @@ describe('/', function() {

assert.equal(res.statusCode, 500);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down Expand Up @@ -220,7 +226,9 @@ describe('/', function() {

assert.equal(res.statusCode, 200);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down Expand Up @@ -255,7 +263,9 @@ describe('/', function() {

assert.equal(res.statusCode, 400);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down Expand Up @@ -290,7 +300,9 @@ describe('/', function() {

assert.equal(res.statusCode, 500);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down
24 changes: 18 additions & 6 deletions test/xmlConsumeTypeTest/compare/request/expect/base-path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ describe('/', function() {

expect(res.statusCode).to.equal(200);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
expect(validator.validate(result, schema)).to.be.true;
done();
Expand Down Expand Up @@ -124,7 +126,9 @@ describe('/', function() {

expect(res.statusCode).to.equal(400);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
expect(validator.validate(result, schema)).to.be.true;
done();
Expand Down Expand Up @@ -171,7 +175,9 @@ describe('/', function() {

expect(res.statusCode).to.equal(500);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
expect(validator.validate(result, schema)).to.be.true;
done();
Expand Down Expand Up @@ -220,7 +226,9 @@ describe('/', function() {

expect(res.statusCode).to.equal(200);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
expect(validator.validate(result, schema)).to.be.true;
done();
Expand Down Expand Up @@ -255,7 +263,9 @@ describe('/', function() {

expect(res.statusCode).to.equal(400);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
expect(validator.validate(result, schema)).to.be.true;
done();
Expand Down Expand Up @@ -290,7 +300,9 @@ describe('/', function() {

expect(res.statusCode).to.equal(500);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
expect(validator.validate(result, schema)).to.be.true;
done();
Expand Down
24 changes: 18 additions & 6 deletions test/xmlConsumeTypeTest/compare/request/should/base-path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ describe('/', function() {

res.statusCode.should.equal(200);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
validator.validate(result, schema).should.be.true;
done();
Expand Down Expand Up @@ -125,7 +127,9 @@ describe('/', function() {

res.statusCode.should.equal(400);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
validator.validate(result, schema).should.be.true;
done();
Expand Down Expand Up @@ -172,7 +176,9 @@ describe('/', function() {

res.statusCode.should.equal(500);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
validator.validate(result, schema).should.be.true;
done();
Expand Down Expand Up @@ -221,7 +227,9 @@ describe('/', function() {

res.statusCode.should.equal(200);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
validator.validate(result, schema).should.be.true;
done();
Expand Down Expand Up @@ -256,7 +264,9 @@ describe('/', function() {

res.statusCode.should.equal(400);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
validator.validate(result, schema).should.be.true;
done();
Expand Down Expand Up @@ -291,7 +301,9 @@ describe('/', function() {

res.statusCode.should.equal(500);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
validator.validate(result, schema).should.be.true;
done();
Expand Down
24 changes: 18 additions & 6 deletions test/xmlConsumeTypeTest/compare/supertest/assert/base-path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down Expand Up @@ -111,7 +113,9 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down Expand Up @@ -151,7 +155,9 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down Expand Up @@ -195,7 +201,9 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down Expand Up @@ -225,7 +233,9 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down Expand Up @@ -255,7 +265,9 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

parseString(res.text, function(parseErr, result) {
var xml2jsConfig = {explicitArray: false};

parseString(res.text, xml2jsConfig, function(parseErr, result) {
if (parseErr) return done(parseErr);
assert.true(validator.validate(result, schema));
done();
Expand Down
Loading

0 comments on commit 2974eb3

Please sign in to comment.