|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -var chai = require('chai'), |
| 3 | +const chai = require('chai'), |
4 | 4 | expect = chai.expect, |
5 | 5 | chaiSinon = require('sinon-chai'), |
6 | 6 | request = require('supertest'); |
7 | 7 | chai.use(chaiSinon); |
8 | 8 |
|
9 | 9 | describe('input-validation middleware tests - Express', function () { |
10 | 10 | describe('init function tests', function () { |
11 | | - it('should reject the promise in case the file doesn\'t exists', function () { |
| 11 | + it('should throw an error in case the file doesn\'t exists', function () { |
12 | 12 | let middleware = require('../../src/middleware'); |
13 | | - |
14 | | - middleware.init('', { |
15 | | - ajvConfigBody: true, |
16 | | - firstError: 'dsadsa' |
17 | | - }); |
18 | | - return middleware.init('test/pet-store-swagger1.yaml') |
19 | | - .catch(function (err) { |
20 | | - expect(err).to.exist; |
21 | | - }); |
| 13 | + expect(() => { |
| 14 | + middleware.init('test/pet-store-swagger1.yaml') |
| 15 | + }).to.throw |
22 | 16 | }); |
23 | 17 | it('should resolve without formats', function () { |
24 | 18 | let rewire = require('rewire'); |
25 | 19 | let middleware = rewire('../../src/middleware'); |
26 | | - return middleware.init('test/pet-store-swagger.yaml'); |
| 20 | + middleware.init('test/pet-store-swagger.yaml'); |
27 | 21 | }); |
28 | 22 | }); |
29 | 23 | describe('Simple server - no options', function () { |
30 | | - var app; |
| 24 | + let app; |
31 | 25 | before(function () { |
32 | | - return require('./test-simple-server').then(function (testServer) { |
33 | | - app = testServer; |
34 | | - }); |
| 26 | + app = require('./test-simple-server')(); |
35 | 27 | }); |
36 | 28 | it('valid request - should pass validation', function (done) { |
37 | 29 | request(app) |
@@ -378,11 +370,9 @@ describe('input-validation middleware tests - Express', function () { |
378 | 370 | }); |
379 | 371 | }); |
380 | 372 | describe('Simple server - type coercion enabled', function () { |
381 | | - var app; |
| 373 | + let app; |
382 | 374 | before(function () { |
383 | | - return require('./test-simple-server-with-coercion').then(function (testServer) { |
384 | | - app = testServer; |
385 | | - }); |
| 375 | + app = require('./test-simple-server-with-coercion')(); |
386 | 376 | }); |
387 | 377 | it('request with wrong parameter type - should pass validation due to coercion', function (done) { |
388 | 378 | request(app) |
@@ -545,11 +535,9 @@ describe('input-validation middleware tests - Express', function () { |
545 | 535 | }); |
546 | 536 | }); |
547 | 537 | describe('Simple server - with base path', function () { |
548 | | - var app; |
| 538 | + let app; |
549 | 539 | before(function () { |
550 | | - return require('./test-simple-server-with-base-path').then(function (testServer) { |
551 | | - app = testServer; |
552 | | - }); |
| 540 | + app = require('./test-simple-server-with-base-path')(); |
553 | 541 | }); |
554 | 542 | it('valid request - should pass validation', function (done) { |
555 | 543 | request(app) |
@@ -939,11 +927,9 @@ describe('input-validation middleware tests - Express', function () { |
939 | 927 | }); |
940 | 928 | }); |
941 | 929 | describe('Simple server using routes', function () { |
942 | | - var app; |
| 930 | + let app; |
943 | 931 | before(function () { |
944 | | - return require('./test-simple-server-base-route').then(function (testServer) { |
945 | | - app = testServer; |
946 | | - }); |
| 932 | + app = require('./test-simple-server-base-route')(); |
947 | 933 | }); |
948 | 934 | it('valid request - should pass validation', function (done) { |
949 | 935 | request(app) |
@@ -1290,11 +1276,9 @@ describe('input-validation middleware tests - Express', function () { |
1290 | 1276 | }); |
1291 | 1277 | }); |
1292 | 1278 | describe('Server with options - beautify and one error', function () { |
1293 | | - var app; |
| 1279 | + let app; |
1294 | 1280 | before(function () { |
1295 | | - return require('./test-server-with-options').then(function (testServer) { |
1296 | | - app = testServer; |
1297 | | - }); |
| 1281 | + app = require('./test-server-with-options')(); |
1298 | 1282 | }); |
1299 | 1283 | it('valid request - should pass validation', function (done) { |
1300 | 1284 | request(app) |
@@ -1685,11 +1669,9 @@ describe('input-validation middleware tests - Express', function () { |
1685 | 1669 | }); |
1686 | 1670 | }); |
1687 | 1671 | describe('Server with options - Only beautify errors', function () { |
1688 | | - var app; |
| 1672 | + let app; |
1689 | 1673 | before(function () { |
1690 | | - return require('./test-server-with-options-more-than-1-error').then(function (testServer) { |
1691 | | - app = testServer; |
1692 | | - }); |
| 1674 | + app = require('./test-server-with-options-more-than-1-error')(); |
1693 | 1675 | }); |
1694 | 1676 | it('valid request - should pass validation', function (done) { |
1695 | 1677 | request(app) |
@@ -2039,11 +2021,9 @@ describe('input-validation middleware tests - Express', function () { |
2039 | 2021 | }); |
2040 | 2022 | }); |
2041 | 2023 | describe('Inheritance', function () { |
2042 | | - var app; |
| 2024 | + let app; |
2043 | 2025 | before(function () { |
2044 | | - return require('./test-server-inheritance').then(function (testServer) { |
2045 | | - app = testServer; |
2046 | | - }); |
| 2026 | + app = require('./test-server-inheritance')(); |
2047 | 2027 | }); |
2048 | 2028 | it('should pass', function (done) { |
2049 | 2029 | request(app) |
@@ -2207,11 +2187,9 @@ describe('input-validation middleware tests - Express', function () { |
2207 | 2187 | }); |
2208 | 2188 | }); |
2209 | 2189 | describe('FormData', function () { |
2210 | | - var app; |
| 2190 | + let app; |
2211 | 2191 | before(function () { |
2212 | | - return require('./test-server-formdata').then(function (testServer) { |
2213 | | - app = testServer; |
2214 | | - }); |
| 2192 | + app = require('./test-server-formdata')(); |
2215 | 2193 | }); |
2216 | 2194 | it('only required files exists should pass', function (done) { |
2217 | 2195 | request(app) |
@@ -2310,11 +2288,9 @@ describe('input-validation middleware tests - Express', function () { |
2310 | 2288 | }); |
2311 | 2289 | }); |
2312 | 2290 | describe('Keywords', function () { |
2313 | | - var app; |
| 2291 | + let app; |
2314 | 2292 | before(function () { |
2315 | | - return require('./test-server-keywords').then(function (testServer) { |
2316 | | - app = testServer; |
2317 | | - }); |
| 2293 | + app = require('./test-server-keywords')(); |
2318 | 2294 | }); |
2319 | 2295 | it('should pass the validation by the range keyword', function (done) { |
2320 | 2296 | request(app) |
|
0 commit comments