Skip to content

Commit

Permalink
Including checks for securityDefinitions and responses
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinchernev committed Oct 18, 2016
1 parent 87f6cf5 commit 4f3641d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
1 change: 0 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @module index */
'use strict';


// Dependencies
var fs = require('fs');
var glob = require('glob');
Expand Down
54 changes: 53 additions & 1 deletion test/fixtures/testData.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Mock for Definitions Object. `definitions` is correct, not `definition`.
var testDataDefinitions = [
{
"definition": {
Expand Down Expand Up @@ -31,6 +32,7 @@ var testDataDefinitions = [
}
];

// Mock for Parameters Definitions Object. `parameters` is correct, not `parameter`.
var testDataParameters = [
{
"parameter": {
Expand All @@ -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,
};
26 changes: 23 additions & 3 deletions test/swagger-helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -50,4 +70,4 @@ describe('swagger-helpers submodule', function () {
});

});
/* jshint ignore:end */
/* jshint ignore:end */

0 comments on commit 4f3641d

Please sign in to comment.