Skip to content

Commit

Permalink
Adding tests to verify
Browse files Browse the repository at this point in the history
Deprecated property names should display a warning only if they are not used inside "properties" objects.
  • Loading branch information
Tommy Frazier committed Dec 22, 2016
1 parent e0bcb38 commit 5ff7718
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
2 changes: 2 additions & 0 deletions example/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module.exports.setup = function(app) {
* type: string
* password:
* type: string
* path:
* type: string
*/

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/swagger-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ function addDataToSwaggerObject(swaggerObject, data) {
function seekWrong(list, wrongSet, problems) {
var iterator = new RecursiveIterator(list, 0, false);
for (var item = iterator.next(); !item.done; item = iterator.next()) {
var isDirectChildOfProperties = item.value.path[item.value.path.length - 2] === 'properties';
var isDirectChildOfProperties =
item.value.path[item.value.path.length - 2] === 'properties';

if (wrongSet.indexOf(item.value.key) > 0 && !isDirectChildOfProperties) {
problems.push(item.value.key);
}
Expand Down
22 changes: 17 additions & 5 deletions test/cli-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ describe('command line interface', function () {
done();
});
});


it('should warn when deprecated properties are used', function (done) {
var deprecatedProperties = process.env.PWD + '/bin/swagger-jsdoc.js -d example/swaggerDef.js test/fixtures/deprecated_routes.js';
exec(deprecatedProperties, function (error, stdout, stderr) {
if (error) {
throw new Error(error, stderr);
}
expect(stderr).to.contain('You are using properties to be deprecated');
done();
});
});

it('should require arguments with jsDoc data about an API', function (done) {
var missingApis = process.env.PWD + '/bin/swagger-jsdoc.js -d example/swaggerDef.js';
exec(missingApis, function (error, stdout, stderr) {
Expand All @@ -73,21 +84,22 @@ describe('command line interface', function () {
done();
});
});

it('should create swaggerSpec.json by default when the API input is good', function (done) {
var goodInput = process.env.PWD + '/bin/swagger-jsdoc.js -d example/swaggerDef.js example/routes.js';
exec(goodInput, function (error, stdout, stderr) {
if (error) {
throw new Error(error, stderr);
}
expect(stdout).to.contain('Swagger specification created successfully.');
expect(stderr).to.not.contain('You are using properties to be deprecated');
var specification = fs.statSync('swaggerSpec.json');
// Check that the physical file was created.
expect(specification.nlink).to.be.above(0);
done();
});
});

it('should accept custom configuration for output specification', function (done) {
var goodInput = process.env.PWD + '/bin/swagger-jsdoc.js -d example/swaggerDef.js -o customSpec.json example/routes.js';
exec(goodInput, function (error, stdout, stderr) {
Expand All @@ -100,8 +112,8 @@ describe('command line interface', function () {
expect(specification.nlink).to.be.above(0);
done();
});
});
});

// Cleanup test files if any.
after(function() {
var defaultSpecification = process.env.PWD + '/swaggerSpec.json';
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/deprecated_routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

module.exports.setup = function(app) {
/**
* @swagger
* /deprecated:
* get:
* description: Returns a string
* path: '/deprecated'
* responses:
* 200:
* description: deprecated path
*/
app.get('/deprecated', function(req, res) {
res.send('Deprecated "path" property!');
});
};
3 changes: 3 additions & 0 deletions test/swagger-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
},
"password": {
"type": "string"
},
"path": {
"type": "string"
}
}
}
Expand Down

0 comments on commit 5ff7718

Please sign in to comment.