@@ -40,7 +40,9 @@ describe('CONVERT FUNCTION TESTS ', function() {
4040 tagsFolderSpec = path . join ( __dirname , VALID_OPENAPI_PATH + '/petstore-detailed.yaml' ) ,
4141 securityTestCases = path . join ( __dirname , VALID_OPENAPI_PATH + '/security-test-cases.yaml' ) ,
4242 emptySecurityTestCase = path . join ( __dirname , VALID_OPENAPI_PATH + '/empty-security-test-case.yaml' ) ,
43- rootUrlServerWithVariables = path . join ( __dirname , VALID_OPENAPI_PATH + '/root_url_server_with_variables.json' ) ;
43+ rootUrlServerWithVariables = path . join ( __dirname , VALID_OPENAPI_PATH + '/root_url_server_with_variables.json' ) ,
44+ absoluteRemoteRefs = path . join ( __dirname , VALID_OPENAPI_PATH + '/absolute-remote-refs.yaml' ) ,
45+ relativeRemoteRefs = path . join ( __dirname , VALID_OPENAPI_PATH + '/relative-remote-refs.yaml' ) ;
4446
4547
4648 it ( 'Should add collection level auth with type as `bearer`' +
@@ -905,6 +907,79 @@ describe('CONVERT FUNCTION TESTS ', function() {
905907 done ( ) ;
906908 } ) ;
907909 } ) ;
910+
911+ it ( 'should correctly resolve absolute remote refs when option resolveRemoteRefs enabled' , function ( done ) {
912+ var openapi = fs . readFileSync ( absoluteRemoteRefs , 'utf8' ) ;
913+ Converter . convert ( { type : 'string' , data : openapi } , { resolveRemoteRefs : true } , ( err , conversionResult ) => {
914+ let collection ,
915+ collectionRequest ,
916+ responseBody1 ,
917+ responseBody2 ;
918+
919+ // Increased timeout for resolution
920+ this . timeout ( 10000 ) ;
921+
922+ console . log ( '*****' , err , conversionResult ) ;
923+ expect ( err ) . to . be . null ;
924+ expect ( conversionResult . result ) . to . be . true ;
925+
926+ collection = conversionResult . output [ 0 ] . data ;
927+ expect ( collection . item ) . to . have . lengthOf ( 1 ) ;
928+
929+ collectionRequest = collection . item [ 0 ] ;
930+ expect ( collectionRequest . request . url . query ) . to . have . lengthOf ( 2 ) ;
931+ expect ( collectionRequest . request . url . query [ 0 ] . key ) . to . eql ( 'tags' ) ;
932+ expect ( collectionRequest . request . url . query [ 1 ] . key ) . to . eql ( 'limit' ) ;
933+
934+ responseBody1 = JSON . parse ( collectionRequest . response [ 0 ] . body ) ;
935+ expect ( responseBody1 ) . to . have . property ( 'id' ) . that . is . a ( 'integer' ) ;
936+ expect ( responseBody1 ) . to . have . property ( 'name' ) . that . is . a ( 'string' ) ;
937+ expect ( responseBody1 ) . to . have . property ( 'tag' ) . that . is . a ( 'string' ) ;
938+
939+ responseBody2 = JSON . parse ( collectionRequest . response [ 0 ] . body ) ;
940+ expect ( responseBody2 ) . to . have . property ( 'code' ) . that . is . a ( 'integer' ) ;
941+ expect ( responseBody2 ) . to . have . property ( 'message' ) . that . is . a ( 'string' ) ;
942+ done ( ) ;
943+ } ) ;
944+ } ) ;
945+
946+ it ( 'should correctly resolve relative remote refs when option resolveRemoteRefs enabled and sourceUrl is provided' ,
947+ function ( done ) {
948+ var openapi = fs . readFileSync ( relativeRemoteRefs , 'utf8' ) ,
949+ options = {
950+ resolveRemoteRefs : true ,
951+ sourceUrl : 'https://raw.githubusercontent.com/postmanlabs/openapi-to-postman' +
952+ '/develop/test/data/petstore%20separate%20yaml/openapi.yaml'
953+ } ;
954+
955+ Converter . convert ( { type : 'string' , data : openapi } , options , ( err , conversionResult ) => {
956+ let collection ,
957+ collectionRequest ,
958+ responseBody1 ,
959+ responseBody2 ;
960+
961+ expect ( err ) . to . be . null ;
962+ expect ( conversionResult . result ) . to . be . true ;
963+
964+ collection = conversionResult . output [ 0 ] . data ;
965+ expect ( collection . item ) . to . have . lengthOf ( 1 ) ;
966+
967+ collectionRequest = collection . item [ 0 ] ;
968+ expect ( collectionRequest . request . url . query ) . to . have . lengthOf ( 2 ) ;
969+ expect ( collectionRequest . request . url . query [ 0 ] . key ) . to . eql ( 'tags' ) ;
970+ expect ( collectionRequest . request . url . query [ 1 ] . key ) . to . eql ( 'limit' ) ;
971+
972+ responseBody1 = JSON . parse ( collectionRequest . response [ 0 ] . body ) ;
973+ expect ( responseBody1 ) . to . have . property ( 'id' ) . that . is . a ( 'integer' ) ;
974+ expect ( responseBody1 ) . to . have . property ( 'name' ) . that . is . a ( 'string' ) ;
975+ expect ( responseBody1 ) . to . have . property ( 'tag' ) . that . is . a ( 'string' ) ;
976+
977+ responseBody2 = JSON . parse ( collectionRequest . response [ 0 ] . body ) ;
978+ expect ( responseBody2 ) . to . have . property ( 'code' ) . that . is . a ( 'integer' ) ;
979+ expect ( responseBody2 ) . to . have . property ( 'message' ) . that . is . a ( 'string' ) ;
980+ done ( ) ;
981+ } ) ;
982+ } ) ;
908983 } ) ;
909984
910985 describe ( 'requestNameSource option' , function ( ) {
0 commit comments