From 4f3641d1fd24b4a5516d8bbb11a2829e4fb10051 Mon Sep 17 00:00:00 2001 From: Kalin Chernev Date: Tue, 18 Oct 2016 12:49:38 +0200 Subject: [PATCH] Including checks for securityDefinitions and responses --- lib/index.js | 1 - test/fixtures/testData.js | 54 +++++++++++++++++++++++++++++++++++- test/swagger-helpers-test.js | 26 +++++++++++++++-- 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index 224a122d..29cff040 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,6 @@ /** @module index */ 'use strict'; - // Dependencies var fs = require('fs'); var glob = require('glob'); diff --git a/test/fixtures/testData.js b/test/fixtures/testData.js index 07ffb065..d3368e20 100644 --- a/test/fixtures/testData.js +++ b/test/fixtures/testData.js @@ -1,3 +1,4 @@ +// Mock for Definitions Object. `definitions` is correct, not `definition`. var testDataDefinitions = [ { "definition": { @@ -31,6 +32,7 @@ var testDataDefinitions = [ } ]; +// Mock for Parameters Definitions Object. `parameters` is correct, not `parameter`. var testDataParameters = [ { "parameter": { @@ -55,9 +57,59 @@ var testDataParameters = [ } } } - ]; +]; + +// Mock for Security Definitions Object. `securityDefinitions` is correct, not `securityDefinition`. +var testDataSecurityDefinitions = [ + { + "securityDefinition": { + "basicAuth": { + "type": "basic", + "description": "HTTP Basic Authentication. Works over `HTTP` and `HTTPS`" + } + } + }, + { + "securityDefinitions": { + "api_key": { + "type": "apiKey", + "name": "api_key", + "in": "header" + }, + "petstore_auth": { + "type": "oauth2", + "authorizationUrl": "http://swagger.io/api/oauth/dialog", + "flow": "implicit", + "scopes": { + "write:pets": "modify pets in your account", + "read:pets": "read your pets" + } + }, + } + } +]; + +// Mock for Responses Definitions Object. `responses` is correct, not `response`. +var testDataResponses = [ + { + "response": { + "NotFound": { + "description": "Entity not found." + } + } + }, + { + "responses": { + "IllegalInput": { + "description": "Illegal input for operation." + } + } + } +]; module.exports = { definitions: testDataDefinitions, parameters: testDataParameters, + securityDefinitions: testDataSecurityDefinitions, + responses: testDataResponses, }; diff --git a/test/swagger-helpers-test.js b/test/swagger-helpers-test.js index 563d6cb9..5f015798 100644 --- a/test/swagger-helpers-test.js +++ b/test/swagger-helpers-test.js @@ -32,7 +32,7 @@ describe('swagger-helpers submodule', function () { expect(swaggerObject.definitions).to.include.keys('DefinitionPlural'); done(); }); - + it('addDataToSwaggerObject() handles "parameter" and "parameters"', function(done) { swaggerHelpers.addDataToSwaggerObject(swaggerObject, testData.parameters); expect(swaggerObject.parameters).to.exist; @@ -41,7 +41,27 @@ describe('swagger-helpers submodule', function () { // Case 'parameters'. expect(swaggerObject.parameters).to.include.keys('ParameterPlural'); done(); - }); + }); + + it('addDataToSwaggerObject() handles "securityDefinition" and "securityDefinitions"', function(done) { + swaggerHelpers.addDataToSwaggerObject(swaggerObject, testData.securityDefinitions); + expect(swaggerObject.securityDefinitions).to.exist; + // Case 'securityDefinition'. + expect(swaggerObject.securityDefinitions).to.include.keys('basicAuth'); + // Case 'securityDefinitions'. + expect(swaggerObject.securityDefinitions).to.include.keys('api_key'); + done(); + }); + + it('addDataToSwaggerObject() handles "response" and "responses"', function(done) { + swaggerHelpers.addDataToSwaggerObject(swaggerObject, testData.responses); + expect(swaggerObject.responses).to.exist; + // Case 'response'. + expect(swaggerObject.responses).to.include.keys('NotFound'); + // Case 'responses'. + expect(swaggerObject.responses).to.include.keys('IllegalInput'); + done(); + }); it('should have a method swaggerizeObj()', function (done) { expect(swaggerHelpers).to.include.keys('swaggerizeObj'); @@ -50,4 +70,4 @@ describe('swagger-helpers submodule', function () { }); }); -/* jshint ignore:end */ \ No newline at end of file +/* jshint ignore:end */