Files
fastapi-openapi-to-postman/test/unit/x20schemapack.test.js
2022-04-14 15:17:40 -05:00

62 lines
1.9 KiB
JavaScript

const SchemaPack = require('../..').SchemaPack,
expect = require('chai').expect,
fs = require('fs'),
path = require('path'),
SWAGGER_20_FOLDER_JSON = '../data/valid_swagger/json/';
describe('SchemaPack instance creation', function() {
it('Should create an instance of SchemaPack when input is a string', function() {
const fileSource = path.join(__dirname, SWAGGER_20_FOLDER_JSON + '/sampleswagger.json'),
fileData = fs.readFileSync(fileSource, 'utf8'),
input = {
type: 'string',
data: fileData
},
schemapack = new SchemaPack(input);
expect(schemapack);
});
it('Should create an instance of SchemaPack when input is a file', function() {
const fileSource = path.join(__dirname, SWAGGER_20_FOLDER_JSON + '/sampleswagger.json'),
input = {
type: 'file',
data: fileSource
},
schemapack = new SchemaPack(input);
expect(schemapack);
});
});
describe('getMetaData method', function() {
it('Should return the provided input metadata', function() {
const fileSource = path.join(__dirname, SWAGGER_20_FOLDER_JSON + 'sampleswagger.json'),
input = {
type: 'file',
data: fileSource
},
schemapack = new SchemaPack(input);
schemapack.getMetaData((error, result) => {
expect(error).to.be.null;
expect(result.result).to.be.true;
expect(result.name).to.be.equal('Swagger Petstore');
});
});
});
describe('Convert method', function() {
it('Should convert an example file from: ', function(done) {
const fileSource = path.join(__dirname, SWAGGER_20_FOLDER_JSON, 'sampleswagger.json'),
fileData = fs.readFileSync(fileSource, 'utf8'),
input = {
type: 'string',
data: fileData
},
schemapack = new SchemaPack(input);
schemapack.convert((error, result) => {
expect(error).to.be.null;
expect(result.result).to.be.true;
});
done();
});
});