11// tslint:disable: only-arrow-functions
22
3- /**
4- * NOTE: When debugging test cases, make use of the script dev-start-along-mock
5- * to spawn a proxy server along with a mock server using a specified
6- * OpenAPI file, e.g.
7- *
8- * npm run dev-start-along-mock -- test/schemas/v3/3-parameters.yaml
9- *
10- * Afterwards, you can use curl to reproduce the requests.
11- */
12-
13- import { assert } from 'chai' ;
3+ import { assert } from 'chai' ;
144import * as path from 'path' ;
155
16- import {
17- INVALID_TEST_REQUESTS ,
18- STRICTLY_INVALID_TEST_REQUESTS ,
19- STRICTLY_VALID_TEST_REQUESTS ,
20- VALID_TEST_REQUESTS ,
21- } from './test_data/test-requests' ;
22- import {
23- NON_COMPLIANT_SERVERS ,
24- STRICTLY_NON_COMPLIANT_SERVERS ,
25- } from './test_data/test-target-servers' ;
26- import { killProcesses } from './util/process' ;
27- import {
28- spawnProxyServer ,
29- testRequestForEachFile ,
30- testRequestForEachFileWithServers ,
31- } from './util/testing' ;
32-
6+ import { INVALID_TEST_REQUESTS , STRICTLY_INVALID_TEST_REQUESTS , } from './test-requests/invalid-requests' ;
7+ import { INVALID_RESPONSES , STRICTLY_INVALID_RESPONSES , } from './test-responses/invalid-responses' ;
8+ import { killProcesses } from './util/process' ;
9+ import { testRequestForEachFile , testRequestForEachFileWithServers , } from './util/testing' ;
10+ import { DEFAULT_OPENAPI_FILE , PROXY_PORT , SCHEMAS_DIR , TARGET_SERVER_PORT , } from './config' ;
11+ import { ChildProcess } from 'child_process' ;
12+ import { Readable } from 'stream' ;
13+ import axios , { AxiosRequestConfig } from 'axios' ;
14+ import { runProxy } from '../src/app' ;
15+ import { closeServer } from '../src/util' ;
16+ import { STRICTLY_VALID_TEST_REQUESTS , VALID_TEST_REQUESTS } from './test-requests/valid-requests' ;
17+ import { spawnProxyServer } from './util/server' ;
3318import findProcess = require( 'find-process' ) ;
34- import {
35- PROXY_PORT ,
36- TARGET_SERVER_PORT ,
37- SCHEMAS_DIR ,
38- DEFAULT_OPENAPI_FILE ,
39- } from './config' ;
40- import { ChildProcess } from 'child_process' ;
41- import { Readable } from 'stream' ;
42- import axios , { AxiosRequestConfig } from 'axios' ;
43- import { runProxy } from '../src/app' ;
44- import { closeServer } from '../src/util' ;
4519
46- describe ( 'integration.test.js' , function ( ) {
20+ describe ( 'integration.test.js' , function ( ) {
4721 this . slow ( 1000 * 15 ) ; // 15 seconds
4822
4923 const contentType = 'application/json' ;
5024 const clients = {
5125 proxy : axios . create ( {
5226 baseURL : `http://localhost:${ PROXY_PORT } ` ,
53- headers : { 'content-type' : contentType } ,
27+ headers : { 'content-type' : contentType } ,
5428 validateStatus : ( ) => true ,
5529 } ) ,
5630 target : axios . create ( {
5731 baseURL : `http://localhost:${ TARGET_SERVER_PORT } ` ,
58- headers : { 'content-type' : contentType } ,
32+ headers : { 'content-type' : contentType } ,
5933 validateStatus : ( ) => true ,
6034 } ) ,
6135 } ;
6236
63- before ( async function ( ) {
37+ before ( async function ( ) {
6438 // Kill active processes listening on any of the given ports
6539 const pid1 = await findProcess ( 'port' , PROXY_PORT ) ;
6640 const pid2 = await findProcess ( 'port' , TARGET_SERVER_PORT ) ;
@@ -71,10 +45,10 @@ describe('integration.test.js', function() {
7145 ] ) ;
7246 } ) ;
7347
74- describe ( 'OpenAPI v3' , function ( ) {
48+ describe ( 'OpenAPI v3' , function ( ) {
7549 const schemasDirV3 = path . join ( SCHEMAS_DIR , 'v3' ) ;
7650
77- describe ( 'Invariance tests' , function ( ) {
51+ describe ( 'Invariance tests' , function ( ) {
7852 testRequestForEachFile ( {
7953 testTitle :
8054 'should return the same status and response bodies as the target server in silent mode' ,
@@ -113,7 +87,7 @@ describe('integration.test.js', function() {
11387 } ) ;
11488 } ) ;
11589
116- it ( 'should return the source request object inside the response header' , async function ( ) {
90+ it ( 'should return the source request object inside the response header' , async function ( ) {
11791 console . log ( 'Starting proxy server...' ) ;
11892 const server = await runProxy ( {
11993 port : PROXY_PORT ,
@@ -126,7 +100,7 @@ describe('integration.test.js', function() {
126100 const originalRequest : AxiosRequestConfig = {
127101 method : 'GET' ,
128102 url : '/pets' ,
129- data : JSON . stringify ( { search : 'something' } ) ,
103+ data : JSON . stringify ( { search : 'something' } ) ,
130104 } ;
131105
132106 const proxyResponse = await clients . proxy . request ( originalRequest ) ;
@@ -178,7 +152,7 @@ describe('integration.test.js', function() {
178152 assert . isBoolean ( validationResults [ k ] [ 'valid' ] ) ;
179153 assert (
180154 validationResults [ k ] [ 'errors' ] === null ||
181- Array . isArray ( validationResults [ k ] [ 'errors' ] ) ,
155+ Array . isArray ( validationResults [ k ] [ 'errors' ] ) ,
182156 'validation error should be null or an array' ,
183157 ) ;
184158 if ( Array . isArray ( validationResults [ k ] [ 'errors' ] ) ) {
@@ -204,7 +178,7 @@ describe('integration.test.js', function() {
204178 } ,
205179 } ) ;
206180
207- it ( 'should fail when target server is not available' , async function ( ) {
181+ it ( 'should fail when target server is not available' , async function ( ) {
208182 this . timeout ( 10000 ) ;
209183
210184 console . log ( 'Starting proxy server...' ) ;
@@ -227,7 +201,7 @@ describe('integration.test.js', function() {
227201 }
228202 } ) ;
229203
230- clients . proxy . request ( { method : 'GET' , url : '/pets' } ) ;
204+ clients . proxy . request ( { method : 'GET' , url : '/pets' } ) ;
231205
232206 return new Promise ( ( resolve ) => {
233207 ps . on ( 'exit' , ( code : number ) => {
@@ -307,7 +281,7 @@ describe('integration.test.js', function() {
307281 testTitle :
308282 'should return correct validation errors for invalid RESponses' ,
309283 dir : schemasDirV3 ,
310- testServers : NON_COMPLIANT_SERVERS . v3 ,
284+ testServers : INVALID_RESPONSES . v3 ,
311285 client : clients ,
312286 callback ( proxyRes , targetRes , fileName , expectedError ) {
313287 assert . isDefined (
@@ -366,7 +340,7 @@ describe('integration.test.js', function() {
366340 testTitle :
367341 'should return correct validation errors for strictly invalid RESponses' ,
368342 dir : schemasDirV3 ,
369- testServers : STRICTLY_NON_COMPLIANT_SERVERS . v3 ,
343+ testServers : STRICTLY_INVALID_RESPONSES . v3 ,
370344 client : clients ,
371345 defaultForbidAdditionalProperties : true ,
372346 callback ( proxyRes , targetRes , fileName , expectedError ) {
0 commit comments