0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Added incorrect 'max' usage error to MaxLimit

refs https://github.com/TryGhost/Team/issues/587

- When the 'max' configuration is missing the instance of the class breaks when used unexpectedly. Followed similar approach to currentCountQuery check  by failing fast in the constructor
This commit is contained in:
Naz 2021-04-01 17:20:56 +13:00
parent 299d3e3bd4
commit 57e24b3677
2 changed files with 17 additions and 0 deletions

View file

@ -31,6 +31,10 @@ class MaxLimit extends Limit {
constructor({name, config, helpLink, db}) {
super({name, error: config.error || '', helpLink, db});
if (config.max === undefined) {
throw new errors.IncorrectUsageError('Attempted to setup a max limit without a limit');
}
if (!config.currentCountQuery) {
throw new errors.IncorrectUsageError('Attempted to setup a max limit without a current count query');
}

View file

@ -6,6 +6,19 @@ const {MaxLimit} = require('../lib/limit');
describe('Limit Service', function () {
describe('Max Limit', function () {
it('throws if initialized without a max limit', function () {
const config = {};
try {
const limit = new MaxLimit({name: 'no limits!', config});
should.fail(limit, 'Should have errored');
} catch (err) {
should.exist(err);
should.exist(err.errorType);
should.equal(err.errorType, 'IncorrectUsageError');
}
});
it('throws if initialized without a current count query', function () {
const config = {};