redoc/tests/unit/schema-manager.spec.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-12-10 00:46:27 +03:00
import SchemaManager from 'lib/utils/SchemaManager';
describe("Schema manager", () => {
let schemaMgr;
beforeEach(() => {
schemaMgr = new SchemaManager();
});
it("Should initialize with empty schema", ()=> {
schemaMgr.schema.should.be.empty;
});
it("Should be a singleton", ()=> {
(new SchemaManager()).should.be.equal(schemaMgr);
});
2015-12-10 22:36:11 +03:00
it("load should return a promise", ()=> {
schemaMgr.load('/tests/schemas/extended-petstore.json').should.be.instanceof(Promise);
});
2015-12-10 00:46:27 +03:00
2015-12-10 22:36:11 +03:00
it("load should resolve promise for valid url", (done)=> {
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
done();
}, (err) => {
throw new Error("Error handler should not be called")
2015-12-10 00:46:27 +03:00
});
2015-12-10 22:36:11 +03:00
});
2015-12-10 00:46:27 +03:00
2015-12-10 22:36:11 +03:00
describe("Schema manager with loaded schema", ()=> {
before(function (done) {
schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => {
2015-12-10 00:46:27 +03:00
done();
2015-12-10 22:36:11 +03:00
}, (err) => {
throw new Error("Error handler should not be called")
2015-12-10 00:46:27 +03:00
});
});
2015-12-10 22:36:11 +03:00
it("should contain non-empty schema", ()=> {
schemaMgr.schema.should.be.an("object");
schemaMgr.schema.should.be.not.empty;
});
it("should correctly init api url", ()=> {
schemaMgr.apiUrl.should.be.equal("http://petstore.swagger.io/v2");
});
it("byPointer should return correct schema part", ()=> {
var part = schemaMgr.byPointer('/tags/3');
part.should.be.deep.equal({
name: "store",
description: "Access to Petstore orders"
});
2015-12-10 00:46:27 +03:00
});
})
})