mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
d5d594c72a
refs https://github.com/TryGhost/Toolbox/issues/292 - There's no good reason to not write tests!
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
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();
|
|
});
|
|
});
|
|
});
|