Skip to content

Commit d34775d

Browse files
author
Vishal Shingala
committed
Added tests for introduced option and usecase of it
1 parent fb95896 commit d34775d

File tree

3 files changed

+134
-1
lines changed

3 files changed

+134
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: http://petstore.swagger.io/v1
9+
paths:
10+
/pets:
11+
get:
12+
summary: List all pets
13+
operationId: listPets
14+
parameters:
15+
- $ref: 'https://raw.githubusercontent.com/postmanlabs/openapi-to-postman/develop/test/data/petstore%20separate%20yaml/spec/parameters.yaml#/tagsParam'
16+
- $ref: 'https://raw.githubusercontent.com/postmanlabs/openapi-to-postman/develop/test/data/petstore%20separate%20yaml/spec/parameters.yaml#/limitsParam'
17+
responses:
18+
'200':
19+
description: An paged array of pets
20+
content:
21+
application/json:
22+
schema:
23+
$ref: "https://raw.githubusercontent.com/postmanlabs/openapi-to-postman/develop/test/data/petstore%20separate%20yaml/spec/Pet.yaml"
24+
default:
25+
description: unexpected error
26+
content:
27+
application/json:
28+
schema:
29+
$ref: "https://raw.githubusercontent.com/postmanlabs/openapi-to-postman/develop/test/data/petstore%20separate%20yaml/common/Error.yaml"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: http://petstore.swagger.io/v1
9+
paths:
10+
/pets:
11+
get:
12+
summary: List all pets
13+
operationId: listPets
14+
parameters:
15+
- $ref: './spec/parameters.yaml#/tagsParam'
16+
- $ref: './spec/parameters.yaml#/limitsParam'
17+
responses:
18+
'200':
19+
description: An paged array of pets
20+
content:
21+
application/json:
22+
schema:
23+
$ref: "./spec/Pet.yaml"
24+
default:
25+
description: unexpected error
26+
content:
27+
application/json:
28+
schema:
29+
$ref: "./common/Error.yaml"

test/unit/base.test.js

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)