mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Added test coverage to mw-api-version-mismatch
refs https://github.com/TryGhost/Toolbox/issues/292 - There's no good reason to not write tests!
This commit is contained in:
parent
f21a403538
commit
d5d594c72a
2 changed files with 37 additions and 8 deletions
|
@ -1,8 +0,0 @@
|
|||
const assert = require('assert');
|
||||
|
||||
describe('Hello world', function () {
|
||||
it('Runs a test', function () {
|
||||
// TODO: Write me!
|
||||
assert.equal('hello', 'hello');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,37 @@
|
|||
const assert = require('assert');
|
||||
const sinon = require('sinon');
|
||||
const errors = require('@tryghost/errors');
|
||||
|
||||
const versionMismatchMW = require('../index');
|
||||
|
||||
describe('mw-api-version-mismatch', function () {
|
||||
it('Does call handle mismatch when a generic RequestNotAcceptableError is used', function (done) {
|
||||
const APIVersionCompatibilityService = {
|
||||
handleMismatch: sinon.stub().resolves()
|
||||
};
|
||||
const req = {
|
||||
headers: {}
|
||||
};
|
||||
const res = {
|
||||
locals: {}
|
||||
};
|
||||
|
||||
versionMismatchMW(APIVersionCompatibilityService)(new errors.RequestNotAcceptableError({
|
||||
code: 'UPDATE_CLIENT'
|
||||
}), req, res, () => {
|
||||
assert.equal(APIVersionCompatibilityService.handleMismatch.called, true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Does NOT call handle mismatch when a generic RequestNotAcceptableError is used', function (done) {
|
||||
const APIVersionCompatibilityService = {
|
||||
handleMismatch: sinon.stub().resolves()
|
||||
};
|
||||
|
||||
versionMismatchMW(APIVersionCompatibilityService)(new errors.RequestNotAcceptableError(), {}, {}, () => {
|
||||
assert.equal(APIVersionCompatibilityService.handleMismatch.called, false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue