Skip to content

Commit

Permalink
Added tests for introduced option and usecase of it
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishal Shingala committed Sep 21, 2020
1 parent fb95896 commit d34775d
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 1 deletion.
29 changes: 29 additions & 0 deletions test/data/valid_openapi/absolute-remote-refs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
parameters:
- $ref: 'https://raw.githubusercontent.com/postmanlabs/openapi-to-postman/develop/test/data/petstore%20separate%20yaml/spec/parameters.yaml#/tagsParam'
- $ref: 'https://raw.githubusercontent.com/postmanlabs/openapi-to-postman/develop/test/data/petstore%20separate%20yaml/spec/parameters.yaml#/limitsParam'
responses:
'200':
description: An paged array of pets
content:
application/json:
schema:
$ref: "https://raw.githubusercontent.com/postmanlabs/openapi-to-postman/develop/test/data/petstore%20separate%20yaml/spec/Pet.yaml"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "https://raw.githubusercontent.com/postmanlabs/openapi-to-postman/develop/test/data/petstore%20separate%20yaml/common/Error.yaml"
29 changes: 29 additions & 0 deletions test/data/valid_openapi/relative-remote-refs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
parameters:
- $ref: './spec/parameters.yaml#/tagsParam'
- $ref: './spec/parameters.yaml#/limitsParam'
responses:
'200':
description: An paged array of pets
content:
application/json:
schema:
$ref: "./spec/Pet.yaml"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "./common/Error.yaml"
77 changes: 76 additions & 1 deletion test/unit/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ describe('CONVERT FUNCTION TESTS ', function() {
tagsFolderSpec = path.join(__dirname, VALID_OPENAPI_PATH + '/petstore-detailed.yaml'),
securityTestCases = path.join(__dirname, VALID_OPENAPI_PATH + '/security-test-cases.yaml'),
emptySecurityTestCase = path.join(__dirname, VALID_OPENAPI_PATH + '/empty-security-test-case.yaml'),
rootUrlServerWithVariables = path.join(__dirname, VALID_OPENAPI_PATH + '/root_url_server_with_variables.json');
rootUrlServerWithVariables = path.join(__dirname, VALID_OPENAPI_PATH + '/root_url_server_with_variables.json'),
absoluteRemoteRefs = path.join(__dirname, VALID_OPENAPI_PATH + '/absolute-remote-refs.yaml'),
relativeRemoteRefs = path.join(__dirname, VALID_OPENAPI_PATH + '/relative-remote-refs.yaml');


it('Should add collection level auth with type as `bearer`' +
Expand Down Expand Up @@ -905,6 +907,79 @@ describe('CONVERT FUNCTION TESTS ', function() {
done();
});
});

it('should correctly resolve absolute remote refs when option resolveRemoteRefs enabled', function (done) {
var openapi = fs.readFileSync(absoluteRemoteRefs, 'utf8');
Converter.convert({ type: 'string', data: openapi }, { resolveRemoteRefs: true }, (err, conversionResult) => {
let collection,
collectionRequest,
responseBody1,
responseBody2;

// Increased timeout for resolution
this.timeout(10000);

console.log('*****', err, conversionResult);
expect(err).to.be.null;
expect(conversionResult.result).to.be.true;

collection = conversionResult.output[0].data;
expect(collection.item).to.have.lengthOf(1);

collectionRequest = collection.item[0];
expect(collectionRequest.request.url.query).to.have.lengthOf(2);
expect(collectionRequest.request.url.query[0].key).to.eql('tags');
expect(collectionRequest.request.url.query[1].key).to.eql('limit');

responseBody1 = JSON.parse(collectionRequest.response[0].body);
expect(responseBody1).to.have.property('id').that.is.a('integer');
expect(responseBody1).to.have.property('name').that.is.a('string');
expect(responseBody1).to.have.property('tag').that.is.a('string');

responseBody2 = JSON.parse(collectionRequest.response[0].body);
expect(responseBody2).to.have.property('code').that.is.a('integer');
expect(responseBody2).to.have.property('message').that.is.a('string');
done();
});
});

it('should correctly resolve relative remote refs when option resolveRemoteRefs enabled and sourceUrl is provided',
function (done) {
var openapi = fs.readFileSync(relativeRemoteRefs, 'utf8'),
options = {
resolveRemoteRefs: true,
sourceUrl: 'https://raw.githubusercontent.com/postmanlabs/openapi-to-postman' +
'/develop/test/data/petstore%20separate%20yaml/openapi.yaml'
};

Converter.convert({ type: 'string', data: openapi }, options, (err, conversionResult) => {
let collection,
collectionRequest,
responseBody1,
responseBody2;

expect(err).to.be.null;
expect(conversionResult.result).to.be.true;

collection = conversionResult.output[0].data;
expect(collection.item).to.have.lengthOf(1);

collectionRequest = collection.item[0];
expect(collectionRequest.request.url.query).to.have.lengthOf(2);
expect(collectionRequest.request.url.query[0].key).to.eql('tags');
expect(collectionRequest.request.url.query[1].key).to.eql('limit');

responseBody1 = JSON.parse(collectionRequest.response[0].body);
expect(responseBody1).to.have.property('id').that.is.a('integer');
expect(responseBody1).to.have.property('name').that.is.a('string');
expect(responseBody1).to.have.property('tag').that.is.a('string');

responseBody2 = JSON.parse(collectionRequest.response[0].body);
expect(responseBody2).to.have.property('code').that.is.a('integer');
expect(responseBody2).to.have.property('message').that.is.a('string');
done();
});
});
});

describe('requestNameSource option', function() {
Expand Down

0 comments on commit d34775d

Please sign in to comment.