Ghost/ghost/mw-api-version-mismatch/test/mw-api-version-mismatch.test.js
2022-04-21 20:29:52 +08:00

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();
});
});
});