mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
100 lines
3.6 KiB
JavaScript
100 lines
3.6 KiB
JavaScript
|
|
const expect = require('chai').expect,
|
|
{ jsonPointerEncodeAndReplace,
|
|
getJsonPointerRelationToRoot,
|
|
concatJsonPointer,
|
|
getKeyInComponents } = require('./../../lib/jsonPointer');
|
|
|
|
describe('getKeyInComponents function', function () {
|
|
it('should return ["schemas", "pet.yaml"] when is pointing the entire file', function () {
|
|
const result = getKeyInComponents(['components', 'schemas'], 'pet.yaml');
|
|
expect(result.length).to.equal(2);
|
|
expect(result[0]).to.equal('schemas');
|
|
expect(result[1]).to.equal('pet.yaml');
|
|
});
|
|
|
|
it('should return ["schemas", "pet.yaml", "definitions", "world"] when is pointing to a local ref',
|
|
function () {
|
|
const result = getKeyInComponents(['components', 'schemas'], 'pet.yaml', '/definitions/world');
|
|
expect(result.length).to.equal(2);
|
|
expect(result[0]).to.equal('schemas');
|
|
expect(result[1]).to.equal('pet.yaml#/definitions/world');
|
|
});
|
|
|
|
it('should return ["components", "schemas", "folder/pet.yaml"] when there is an scaped slash', function () {
|
|
const result = getKeyInComponents(['components', 'schemas'], 'folder~1pet.yaml');
|
|
expect(result.length).to.equal(2);
|
|
expect(result[0]).to.equal('schemas');
|
|
expect(result[1]).to.equal('folder/pet.yaml');
|
|
});
|
|
});
|
|
|
|
|
|
describe('getJsonPointerRelationToRoot function', function () {
|
|
it('should return "#/components/schemas/Pets.yaml" no local path and schema', function () {
|
|
let res = getJsonPointerRelationToRoot(
|
|
jsonPointerEncodeAndReplace,
|
|
'Pets.yaml',
|
|
['schemas', 'Pets.yaml']
|
|
);
|
|
expect(res).to.equal('#/components/schemas/Pets.yaml');
|
|
});
|
|
it('should return "#/components/schemas/hello.yaml" no local path and schema', function () {
|
|
let res = getJsonPointerRelationToRoot(
|
|
jsonPointerEncodeAndReplace,
|
|
'hello.yaml#/definitions/world',
|
|
['schemas', 'hello.yaml']
|
|
);
|
|
expect(res).to.equal('#/components/schemas/hello.yaml');
|
|
});
|
|
it('should return "#/components/schemas/Error" no file path', function () {
|
|
let res = getJsonPointerRelationToRoot(
|
|
jsonPointerEncodeAndReplace,
|
|
'#/components/schemas/Error',
|
|
['components', 'schemas', 'Error']
|
|
);
|
|
expect(res).to.equal('#/components/schemas/Error');
|
|
});
|
|
});
|
|
|
|
describe('concatJsonPointer function ', function () {
|
|
it('should return "#/components/schemas/Pets.yaml" no local path and schema', function () {
|
|
let res = concatJsonPointer(
|
|
jsonPointerEncodeAndReplace,
|
|
['schemas', 'Pets.yaml']
|
|
);
|
|
expect(res).to.equal('#/components/schemas/Pets.yaml');
|
|
});
|
|
|
|
it('should return "#/components/schemas/other~1Pets.yaml" no local path and schema folder in filename', function () {
|
|
let res = concatJsonPointer(
|
|
jsonPointerEncodeAndReplace,
|
|
['schemas', 'other/Pets.yaml']
|
|
);
|
|
expect(res).to.equal('#/components/schemas/other~1Pets.yaml');
|
|
});
|
|
it('should return "#/components/schemas/some~1Pet" no local path and schema folder in filename', function () {
|
|
let res = concatJsonPointer(
|
|
jsonPointerEncodeAndReplace,
|
|
['schemas', 'some/Pet.yaml']
|
|
);
|
|
expect(res).to.equal('#/components/schemas/some~1Pet.yaml');
|
|
});
|
|
it('should return "#/components/schemas/hello.yaml" no local path and schema', function () {
|
|
let res = concatJsonPointer(
|
|
jsonPointerEncodeAndReplace,
|
|
['schemas', 'hello.yaml']
|
|
);
|
|
expect(res).to.equal('#/components/schemas/hello.yaml');
|
|
});
|
|
|
|
it('should return "#/components/schemas/~1Pets.yaml" no local path and schema', function () {
|
|
let res = concatJsonPointer(
|
|
jsonPointerEncodeAndReplace,
|
|
['schemas', '/Pets.yaml']
|
|
);
|
|
expect(res).to.equal('#/components/schemas/~1Pets.yaml');
|
|
});
|
|
|
|
});
|