Comparing version 1.0.0 to 1.0.1
13
index.js
@@ -0,6 +1,17 @@ | ||
var _ = require('lodash'); | ||
exports.configuration = { | ||
header: 'X-API-Version' | ||
}; | ||
exports.config = function (options) { | ||
exports.configuration = options || {}; | ||
options = options || {}; | ||
exports.configuration = _.extend(exports.configuration, options); | ||
}; | ||
exports.limit = function (version) { | ||
if ('string' !== typeof(version)) { | ||
throw new Error('Please supply a version for this route.'); | ||
} | ||
return function (req, res, next) { | ||
@@ -7,0 +18,0 @@ var header; |
@@ -9,6 +9,8 @@ { | ||
}, | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"repository": "git://github.com/originalmachine/apogee.git", | ||
"main": "index.js", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"lodash": "^2.4.1" | ||
}, | ||
"devDependencies": { | ||
@@ -15,0 +17,0 @@ "chai": "^1.9.1", |
@@ -6,2 +6,12 @@ var apogee = require('../') | ||
describe('Configuration', function () { | ||
it('should default to the standard x-api-version header', function () { | ||
expect(apogee.configuration.header).to.equal('X-API-Version'); | ||
}); | ||
it('should set the default version to undefined', function () { | ||
expect(apogee.configuration.default).to.equal(undefined); | ||
}); | ||
}); | ||
describe('API Versioning', function () { | ||
@@ -69,2 +79,21 @@ beforeEach(function () { | ||
}); | ||
it('should respond with 404 Not Found if no matching version is found, and no default exists', function (done) { | ||
var app = express(); | ||
apogee.config({ header: 'x-apogee-version' }); | ||
app.route('/widgets').all(apogee.limit('v2')).get(function (req, res) { | ||
res.json({ message: 'v2' }); | ||
}); | ||
app.route('/widgets').all(apogee.limit('v1')).get(function (req, res) { | ||
res.json({ message: 'v1' }); | ||
}); | ||
app.use(require('errorhandler')()); | ||
request(app) | ||
.get('/widgets') | ||
.set('x-apogee-version', 'v3') | ||
.expect(404, done); | ||
}); | ||
}); |
7273
108
1
+ Addedlodash@^2.4.1
+ Addedlodash@2.4.2(transitive)