From 8c814f9fc0225ab7aa33aa45a8ebfa4e39382824 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 10 Dec 2015 21:36:11 +0200 Subject: [PATCH] Add a few schema-manager tests --- karma.conf.js | 1 + tests/unit/schema-manager.spec.js | 48 ++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 8ccff747..32bc9c92 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -12,6 +12,7 @@ module.exports = function (config) { jspm: { config: 'system.config.js', loadFiles: ['tests/**/*.spec.js', 'lib/**/*.js'], + serveFiles: ['tests/schemas/**/*.json'], nocache: true }, diff --git a/tests/unit/schema-manager.spec.js b/tests/unit/schema-manager.spec.js index 7417c613..f174119e 100644 --- a/tests/unit/schema-manager.spec.js +++ b/tests/unit/schema-manager.spec.js @@ -14,29 +14,43 @@ describe("Schema manager", () => { (new SchemaManager()).should.be.equal(schemaMgr); }); - describe("load method", ()=> { - let req = null; - let xhr = null; - before(function () { - // fake XHR - xhr = sinon.useFakeXMLHttpRequest(); + it("load should return a promise", ()=> { + schemaMgr.load('/tests/schemas/extended-petstore.json').should.be.instanceof(Promise); + }); + + 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") }); + }); - - it("should return a promise", ()=> { - schemaMgr.load('http://test').should.be.instanceof(Promise); - }); - - it("should reject promise for non-existing schema", (done)=> { - schemaMgr.load('http://test').then(() => { - throw new Error("Should not be called") - }, (err) => { + describe("Schema manager with loaded schema", ()=> { + before(function (done) { + schemaMgr.load('/tests/schemas/extended-petstore.json').then(() => { done(); + }, (err) => { + throw new Error("Error handler should not be called") }); }); - after(function () { - xhr.restore(); + + 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" + }); }); }) })