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

Fix/fix assert.true #187

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,16 @@ function getData(swagger, apiPath, operation, response, config, info) {
// if we have requestData, fill the path params accordingly
var mockParameters = {};

data.pathParameters.forEach(function(parameter) {
// find the mock data for this parameter name
mockParameters[parameter.name] = data.requestData.filter(function(mock) {
return mock.hasOwnProperty(parameter.name);
})[0][parameter.name];
});
// only write parameters if they are not already defined in config
// @todo we should rework this with code above to be more readable
if (!config.pathParams) {
if (config.pathParams) {
data.pathParams = config.pathParams;
} else {
// no path params in config, get them from per-endpoint data
data.pathParameters.forEach(function(parameter) {
// find the mock data for this parameter name
mockParameters[parameter.name] = data.requestData.filter(function(mock) {
return mock.hasOwnProperty(parameter.name);
})[0][parameter.name];
});
data.pathParams = mockParameters;
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/request/delete/delete.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
validator.validate(body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
{{/is}}
{{else}}
{{#is assertion 'expect'}}
Expand Down
2 changes: 1 addition & 1 deletion templates/request/get/get.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
validator.validate(body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
{{/is}}
{{else}}
{{#isPdfMediaType returnType}}
Expand Down
2 changes: 1 addition & 1 deletion templates/request/patch/patch.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
validator.validate(body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
{{/is}}
{{else}}
{{#isPdfMediaType returnType}}
Expand Down
2 changes: 1 addition & 1 deletion templates/request/post/post.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
validator.validate(body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
{{/is}}
{{else}}
{{#isPdfMediaType returnType}}
Expand Down
2 changes: 1 addition & 1 deletion templates/request/put/put.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
validator.validate(body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
{{/is}}
{{else}}
{{#isPdfMediaType returnType}}
Expand Down
4 changes: 2 additions & 2 deletions templates/supertest/delete/delete.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
validator.validate(res.body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
{{/is}}
{{else}}
{{#is assertion 'expect'}}
Expand All @@ -53,7 +53,7 @@
res.body.should.equal(null); // non-json response or no schema
{{/is}}
{{#is assertion 'assert'}}
assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
{{/is}}
{{/validateResponse}}
done();
Expand Down
4 changes: 2 additions & 2 deletions templates/supertest/get/get.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
validator.validate(res.body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
{{/is}}
{{else}}
{{#isPdfMediaType returnType}}
Expand All @@ -64,7 +64,7 @@
res.body.should.equal(null); // non-json response or no schema
{{/is}}
{{#is assertion 'assert'}}
assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
{{/is}}
{{/isPdfMediaType}}
{{/validateResponse}}
Expand Down
4 changes: 2 additions & 2 deletions templates/supertest/options/options.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
validator.validate(res.body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
{{/is}}
{{else}}
{{#is assertion 'expect'}}
Expand All @@ -53,7 +53,7 @@
res.body.should.equal(null); // non-json response or no schema
{{/is}}
{{#is assertion 'assert'}}
assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
{{/is}}
{{/validateResponse}}
done();
Expand Down
4 changes: 2 additions & 2 deletions templates/supertest/patch/patch.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
validator.validate(res.body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
{{/is}}
{{else}}
{{#isPdfMediaType returnType}}
Expand All @@ -89,7 +89,7 @@
res.body.should.equal(null); // non-json response or no schema
{{/is}}
{{#is assertion 'assert'}}
assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
{{/is}}
{{/isPdfMediaType}}
{{/validateResponse}}
Expand Down
4 changes: 2 additions & 2 deletions templates/supertest/post/post.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
validator.validate(res.body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
{{/is}}
{{else}}
{{#isPdfMediaType returnType}}
Expand All @@ -88,7 +88,7 @@
res.body.should.equal(null); // non-json response or no schema
{{/is}}
{{#is assertion 'assert'}}
assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
{{/is}}
{{/isPdfMediaType}}
{{/validateResponse}}
Expand Down
4 changes: 2 additions & 2 deletions templates/supertest/put/put.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
validator.validate(res.body, schema).should.be.true;
{{/is}}
{{#is assertion 'assert'}}
assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
{{/is}}
{{else}}
{{#isPdfMediaType returnType}}
Expand All @@ -88,7 +88,7 @@
res.body.should.equal(null); // non-json response or no schema
{{/is}}
{{#is assertion 'assert'}}
assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
{{/is}}
{{/isPdfMediaType}}
{{/validateResponse}}
Expand Down
12 changes: 6 additions & 6 deletions test/loadTest/compare/request/assert/base-path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('/', function() {

assert.equal(res.statusCode, 200);

assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
done();
});
});
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('/', function() {

assert.equal(res.statusCode, 400);

assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
done();
});
});
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('/', function() {

assert.equal(res.statusCode, 500);

assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
done();
});
});
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('/', function() {

assert.equal(res.statusCode, 200);

assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
done();
});
});
Expand Down Expand Up @@ -242,7 +242,7 @@ describe('/', function() {

assert.equal(res.statusCode, 400);

assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
done();
});
});
Expand Down Expand Up @@ -274,7 +274,7 @@ describe('/', function() {

assert.equal(res.statusCode, 500);

assert.true(validator.validate(body, schema));
assert(validator.validate(body, schema), 'Schema validation failed');
done();
});
});
Expand Down
12 changes: 6 additions & 6 deletions test/loadTest/compare/supertest/assert/base-path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
done();
});
});
Expand All @@ -107,7 +107,7 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
done();
});
});
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
done();
});
});
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
done();
});
});
Expand All @@ -212,7 +212,7 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
done();
});
});
Expand All @@ -239,7 +239,7 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

assert.true(validator.validate(res.body, schema));
assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors()));
done();
});
});
Expand Down
22 changes: 11 additions & 11 deletions test/loadTest/compare/supertest/assert/user-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand All @@ -174,7 +174,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand All @@ -193,7 +193,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand All @@ -215,7 +215,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand Down Expand Up @@ -270,7 +270,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand Down Expand Up @@ -325,7 +325,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand Down Expand Up @@ -380,7 +380,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand All @@ -396,7 +396,7 @@ describe('/user', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/minimal/compare/supertest/assert/base-path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('/', function() {
.end(function(err, res) {
if (err) return done(err);

assert.isNull(res.body); // non-json response or no schema
assert((Object.keys(res.body).length === 0) || (res.body === null)); // non-json response (sets body to empty obj) or no schema
done();
});
});
Expand Down
Loading