From f2d4907be864f11ac3fc39d5d967ebe0f164d66d Mon Sep 17 00:00:00 2001 From: dmitryyy Date: Wed, 24 Mar 2021 09:26:06 +0200 Subject: [PATCH 1/6] assert.true -> assert. Added schema validation fail message, only to asserts tho --- templates/request/delete/delete.handlebars | 2 +- templates/request/get/get.handlebars | 2 +- templates/request/patch/patch.handlebars | 2 +- templates/request/post/post.handlebars | 2 +- templates/request/put/put.handlebars | 2 +- templates/supertest/delete/delete.handlebars | 2 +- templates/supertest/get/get.handlebars | 2 +- templates/supertest/options/options.handlebars | 2 +- templates/supertest/patch/patch.handlebars | 2 +- templates/supertest/post/post.handlebars | 2 +- templates/supertest/put/put.handlebars | 2 +- .../compare/request/assert/base-path-test.js | 12 ++++++------ .../compare/supertest/assert/base-path-test.js | 12 ++++++------ test/robust/compare/request/assert/base-path-test.js | 12 ++++++------ .../compare/supertest/assert/base-path-test.js | 12 ++++++------ 15 files changed, 35 insertions(+), 35 deletions(-) diff --git a/templates/request/delete/delete.handlebars b/templates/request/delete/delete.handlebars index df4e360..f3a324a 100644 --- a/templates/request/delete/delete.handlebars +++ b/templates/request/delete/delete.handlebars @@ -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'}} diff --git a/templates/request/get/get.handlebars b/templates/request/get/get.handlebars index a8c07c8..65eb642 100644 --- a/templates/request/get/get.handlebars +++ b/templates/request/get/get.handlebars @@ -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}} diff --git a/templates/request/patch/patch.handlebars b/templates/request/patch/patch.handlebars index e72bc10..89960cb 100644 --- a/templates/request/patch/patch.handlebars +++ b/templates/request/patch/patch.handlebars @@ -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}} diff --git a/templates/request/post/post.handlebars b/templates/request/post/post.handlebars index 0b1d8b0..45dce50 100644 --- a/templates/request/post/post.handlebars +++ b/templates/request/post/post.handlebars @@ -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}} diff --git a/templates/request/put/put.handlebars b/templates/request/put/put.handlebars index d0bcc4c..70852b3 100644 --- a/templates/request/put/put.handlebars +++ b/templates/request/put/put.handlebars @@ -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}} diff --git a/templates/supertest/delete/delete.handlebars b/templates/supertest/delete/delete.handlebars index c7b8581..60cabf0 100644 --- a/templates/supertest/delete/delete.handlebars +++ b/templates/supertest/delete/delete.handlebars @@ -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)); {{/is}} {{else}} {{#is assertion 'expect'}} diff --git a/templates/supertest/get/get.handlebars b/templates/supertest/get/get.handlebars index c217952..290d0cd 100644 --- a/templates/supertest/get/get.handlebars +++ b/templates/supertest/get/get.handlebars @@ -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)); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/supertest/options/options.handlebars b/templates/supertest/options/options.handlebars index d4a71a9..645397b 100644 --- a/templates/supertest/options/options.handlebars +++ b/templates/supertest/options/options.handlebars @@ -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)); {{/is}} {{else}} {{#is assertion 'expect'}} diff --git a/templates/supertest/patch/patch.handlebars b/templates/supertest/patch/patch.handlebars index 2f6553b..ce61db4 100644 --- a/templates/supertest/patch/patch.handlebars +++ b/templates/supertest/patch/patch.handlebars @@ -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)); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/supertest/post/post.handlebars b/templates/supertest/post/post.handlebars index f5672d5..baceeb5 100644 --- a/templates/supertest/post/post.handlebars +++ b/templates/supertest/post/post.handlebars @@ -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)); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/supertest/put/put.handlebars b/templates/supertest/put/put.handlebars index 05bddd2..d31dba7 100644 --- a/templates/supertest/put/put.handlebars +++ b/templates/supertest/put/put.handlebars @@ -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)); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/test/loadTest/compare/request/assert/base-path-test.js b/test/loadTest/compare/request/assert/base-path-test.js index 93972bd..2d3e637 100644 --- a/test/loadTest/compare/request/assert/base-path-test.js +++ b/test/loadTest/compare/request/assert/base-path-test.js @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); diff --git a/test/loadTest/compare/supertest/assert/base-path-test.js b/test/loadTest/compare/supertest/assert/base-path-test.js index dde725f..c9c6ffc 100644 --- a/test/loadTest/compare/supertest/assert/base-path-test.js +++ b/test/loadTest/compare/supertest/assert/base-path-test.js @@ -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)); done(); }); }); @@ -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)); done(); }); }); @@ -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)); done(); }); }); @@ -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)); done(); }); }); @@ -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)); done(); }); }); @@ -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)); done(); }); }); diff --git a/test/robust/compare/request/assert/base-path-test.js b/test/robust/compare/request/assert/base-path-test.js index 786e010..09df808 100644 --- a/test/robust/compare/request/assert/base-path-test.js +++ b/test/robust/compare/request/assert/base-path-test.js @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); diff --git a/test/robust/compare/supertest/assert/base-path-test.js b/test/robust/compare/supertest/assert/base-path-test.js index ee3ad4a..5489fd5 100644 --- a/test/robust/compare/supertest/assert/base-path-test.js +++ b/test/robust/compare/supertest/assert/base-path-test.js @@ -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)); done(); }); }); @@ -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)); done(); }); }); @@ -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)); done(); }); }); @@ -183,7 +183,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)); done(); }); }); @@ -208,7 +208,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)); done(); }); }); @@ -233,7 +233,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)); done(); }); }); From c585da7d02caa785cb81d4d8b42bf47d935d412e Mon Sep 17 00:00:00 2001 From: dmitryyy Date: Wed, 24 Mar 2021 09:45:14 +0200 Subject: [PATCH 2/6] added missing schema validation fail message --- templates/supertest/delete/delete.handlebars | 2 +- templates/supertest/get/get.handlebars | 2 +- templates/supertest/options/options.handlebars | 2 +- templates/supertest/patch/patch.handlebars | 2 +- templates/supertest/post/post.handlebars | 2 +- templates/supertest/put/put.handlebars | 2 +- .../compare/supertest/assert/base-path-test.js | 12 ++++++------ .../compare/supertest/assert/base-path-test.js | 12 ++++++------ 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/templates/supertest/delete/delete.handlebars b/templates/supertest/delete/delete.handlebars index 60cabf0..4a1cbc1 100644 --- a/templates/supertest/delete/delete.handlebars +++ b/templates/supertest/delete/delete.handlebars @@ -43,7 +43,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#is assertion 'expect'}} diff --git a/templates/supertest/get/get.handlebars b/templates/supertest/get/get.handlebars index 290d0cd..1651e44 100644 --- a/templates/supertest/get/get.handlebars +++ b/templates/supertest/get/get.handlebars @@ -43,7 +43,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/supertest/options/options.handlebars b/templates/supertest/options/options.handlebars index 645397b..cba25d0 100644 --- a/templates/supertest/options/options.handlebars +++ b/templates/supertest/options/options.handlebars @@ -43,7 +43,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#is assertion 'expect'}} diff --git a/templates/supertest/patch/patch.handlebars b/templates/supertest/patch/patch.handlebars index ce61db4..c6bfea4 100644 --- a/templates/supertest/patch/patch.handlebars +++ b/templates/supertest/patch/patch.handlebars @@ -68,7 +68,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/supertest/post/post.handlebars b/templates/supertest/post/post.handlebars index baceeb5..756b0bd 100644 --- a/templates/supertest/post/post.handlebars +++ b/templates/supertest/post/post.handlebars @@ -67,7 +67,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/supertest/put/put.handlebars b/templates/supertest/put/put.handlebars index d31dba7..0ba5d44 100644 --- a/templates/supertest/put/put.handlebars +++ b/templates/supertest/put/put.handlebars @@ -67,7 +67,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/test/loadTest/compare/supertest/assert/base-path-test.js b/test/loadTest/compare/supertest/assert/base-path-test.js index c9c6ffc..370a401 100644 --- a/test/loadTest/compare/supertest/assert/base-path-test.js +++ b/test/loadTest/compare/supertest/assert/base-path-test.js @@ -82,7 +82,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); @@ -107,7 +107,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); @@ -144,7 +144,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); @@ -185,7 +185,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); @@ -212,7 +212,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); @@ -239,7 +239,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); diff --git a/test/robust/compare/supertest/assert/base-path-test.js b/test/robust/compare/supertest/assert/base-path-test.js index 5489fd5..508ea1a 100644 --- a/test/robust/compare/supertest/assert/base-path-test.js +++ b/test/robust/compare/supertest/assert/base-path-test.js @@ -82,7 +82,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); @@ -107,7 +107,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); @@ -144,7 +144,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); @@ -183,7 +183,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); @@ -208,7 +208,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); @@ -233,7 +233,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema)); + assert(validator.validate(res.body, schema), 'Schema validation failed'); done(); }); }); From b4bc9725aae3d01e30f745ce3d50a14f0b40ac82 Mon Sep 17 00:00:00 2001 From: dmitryyy Date: Thu, 20 May 2021 19:14:46 +0300 Subject: [PATCH 3/6] added printout of schema validation errors --- templates/supertest/delete/delete.handlebars | 2 +- templates/supertest/get/get.handlebars | 2 +- templates/supertest/options/options.handlebars | 2 +- templates/supertest/patch/patch.handlebars | 2 +- templates/supertest/post/post.handlebars | 2 +- templates/supertest/put/put.handlebars | 2 +- .../compare/supertest/assert/base-path-test.js | 12 ++++++------ .../compare/supertest/assert/base-path-test.js | 12 ++++++------ 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/templates/supertest/delete/delete.handlebars b/templates/supertest/delete/delete.handlebars index 4a1cbc1..fa0c671 100644 --- a/templates/supertest/delete/delete.handlebars +++ b/templates/supertest/delete/delete.handlebars @@ -43,7 +43,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#is assertion 'expect'}} diff --git a/templates/supertest/get/get.handlebars b/templates/supertest/get/get.handlebars index 1651e44..903b355 100644 --- a/templates/supertest/get/get.handlebars +++ b/templates/supertest/get/get.handlebars @@ -43,7 +43,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/supertest/options/options.handlebars b/templates/supertest/options/options.handlebars index cba25d0..25d0d83 100644 --- a/templates/supertest/options/options.handlebars +++ b/templates/supertest/options/options.handlebars @@ -43,7 +43,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#is assertion 'expect'}} diff --git a/templates/supertest/patch/patch.handlebars b/templates/supertest/patch/patch.handlebars index c6bfea4..db2346c 100644 --- a/templates/supertest/patch/patch.handlebars +++ b/templates/supertest/patch/patch.handlebars @@ -68,7 +68,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/supertest/post/post.handlebars b/templates/supertest/post/post.handlebars index 756b0bd..cc60066 100644 --- a/templates/supertest/post/post.handlebars +++ b/templates/supertest/post/post.handlebars @@ -67,7 +67,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/templates/supertest/put/put.handlebars b/templates/supertest/put/put.handlebars index 0ba5d44..962bce9 100644 --- a/templates/supertest/put/put.handlebars +++ b/templates/supertest/put/put.handlebars @@ -67,7 +67,7 @@ validator.validate(res.body, schema).should.be.true; {{/is}} {{#is assertion 'assert'}} - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); {{/is}} {{else}} {{#isPdfMediaType returnType}} diff --git a/test/loadTest/compare/supertest/assert/base-path-test.js b/test/loadTest/compare/supertest/assert/base-path-test.js index 370a401..6787eb4 100644 --- a/test/loadTest/compare/supertest/assert/base-path-test.js +++ b/test/loadTest/compare/supertest/assert/base-path-test.js @@ -82,7 +82,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -107,7 +107,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -144,7 +144,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -185,7 +185,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -212,7 +212,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -239,7 +239,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); diff --git a/test/robust/compare/supertest/assert/base-path-test.js b/test/robust/compare/supertest/assert/base-path-test.js index 508ea1a..0573dbd 100644 --- a/test/robust/compare/supertest/assert/base-path-test.js +++ b/test/robust/compare/supertest/assert/base-path-test.js @@ -82,7 +82,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -107,7 +107,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -144,7 +144,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -183,7 +183,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -208,7 +208,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); @@ -233,7 +233,7 @@ describe('/', function() { .end(function(err, res) { if (err) return done(err); - assert(validator.validate(res.body, schema), 'Schema validation failed'); + assert(validator.validate(res.body, schema), 'Schema validation failed: ' + JSON.stringify(validator.getLastErrors())); done(); }); }); From 4f64869c65b9abde06b08d07cd008b433c86c5bc Mon Sep 17 00:00:00 2001 From: Dmitryyy Date: Sat, 22 May 2021 02:18:54 +0300 Subject: [PATCH 4/6] fix handling of path parameters --- index.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 9b3a921..a5614f4 100644 --- a/index.js +++ b/index.js @@ -208,17 +208,18 @@ 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; - } + } } return data; } From d557bfcb0a09a683f3daf0f1558b4c3012192302 Mon Sep 17 00:00:00 2001 From: Dmitry Yakovkin Date: Sat, 22 May 2021 01:35:23 +0200 Subject: [PATCH 5/6] fix lint errors --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a5614f4..c90194b 100644 --- a/index.js +++ b/index.js @@ -209,7 +209,7 @@ function getData(swagger, apiPath, operation, response, config, info) { var mockParameters = {}; if (config.pathParams) { - data.pathParams = config.pathParams + data.pathParams = config.pathParams; } else { // no path params in config, get them from per-endpoint data data.pathParameters.forEach(function(parameter) { @@ -217,9 +217,9 @@ function getData(swagger, apiPath, operation, response, config, info) { mockParameters[parameter.name] = data.requestData.filter(function(mock) { return mock.hasOwnProperty(parameter.name); })[0][parameter.name]; - }); + }); data.pathParams = mockParameters; - } + } } return data; } From 359fb1389d375ff383ad7b956abf509692476536 Mon Sep 17 00:00:00 2001 From: Dmitry Yakovkin Date: Sat, 22 May 2021 01:44:47 +0200 Subject: [PATCH 6/6] fix assert templates to properly handle non-json responses --- templates/supertest/delete/delete.handlebars | 2 +- templates/supertest/get/get.handlebars | 2 +- .../supertest/options/options.handlebars | 2 +- templates/supertest/patch/patch.handlebars | 2 +- templates/supertest/post/post.handlebars | 2 +- templates/supertest/put/put.handlebars | 2 +- .../compare/supertest/assert/user-test.js | 22 +++++++++---------- .../supertest/assert/base-path-test.js | 2 +- .../compare/supertest/assert/user-test.js | 22 +++++++++---------- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/templates/supertest/delete/delete.handlebars b/templates/supertest/delete/delete.handlebars index fa0c671..4a2d828 100644 --- a/templates/supertest/delete/delete.handlebars +++ b/templates/supertest/delete/delete.handlebars @@ -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(); diff --git a/templates/supertest/get/get.handlebars b/templates/supertest/get/get.handlebars index 903b355..5b74f1b 100644 --- a/templates/supertest/get/get.handlebars +++ b/templates/supertest/get/get.handlebars @@ -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}} diff --git a/templates/supertest/options/options.handlebars b/templates/supertest/options/options.handlebars index 25d0d83..f89422d 100644 --- a/templates/supertest/options/options.handlebars +++ b/templates/supertest/options/options.handlebars @@ -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(); diff --git a/templates/supertest/patch/patch.handlebars b/templates/supertest/patch/patch.handlebars index db2346c..f364072 100644 --- a/templates/supertest/patch/patch.handlebars +++ b/templates/supertest/patch/patch.handlebars @@ -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}} diff --git a/templates/supertest/post/post.handlebars b/templates/supertest/post/post.handlebars index cc60066..5c6a4dc 100644 --- a/templates/supertest/post/post.handlebars +++ b/templates/supertest/post/post.handlebars @@ -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}} diff --git a/templates/supertest/put/put.handlebars b/templates/supertest/put/put.handlebars index 962bce9..c987674 100644 --- a/templates/supertest/put/put.handlebars +++ b/templates/supertest/put/put.handlebars @@ -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}} diff --git a/test/loadTest/compare/supertest/assert/user-test.js b/test/loadTest/compare/supertest/assert/user-test.js index 86efa3b..b4cf85f 100644 --- a/test/loadTest/compare/supertest/assert/user-test.js +++ b/test/loadTest/compare/supertest/assert/user-test.js @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); @@ -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(); }); }); diff --git a/test/minimal/compare/supertest/assert/base-path-test.js b/test/minimal/compare/supertest/assert/base-path-test.js index ba1a728..1c9e26b 100644 --- a/test/minimal/compare/supertest/assert/base-path-test.js +++ b/test/minimal/compare/supertest/assert/base-path-test.js @@ -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(); }); }); diff --git a/test/robust/compare/supertest/assert/user-test.js b/test/robust/compare/supertest/assert/user-test.js index 03d7810..8a685e5 100644 --- a/test/robust/compare/supertest/assert/user-test.js +++ b/test/robust/compare/supertest/assert/user-test.js @@ -16,7 +16,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(); }); }); @@ -29,7 +29,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(); }); }); @@ -42,7 +42,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(); }); }); @@ -64,7 +64,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(); }); }); @@ -83,7 +83,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(); }); }); @@ -102,7 +102,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(); }); }); @@ -124,7 +124,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(); }); }); @@ -143,7 +143,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(); }); }); @@ -162,7 +162,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(); }); }); @@ -181,7 +181,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(); }); }); @@ -197,7 +197,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(); }); });