Added test coverage for flag type of limits

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

- This is by no means an thorought test coverage but ensures the basics work and provides examples of how the limit should be used. To be continued :)
This commit is contained in:
Naz 2021-05-03 12:02:01 +04:00
parent a5eba60c23
commit 47a6956175

View File

@ -3,9 +3,46 @@
require('./utils');
const errors = require('./fixtures/errors');
const {MaxLimit, AllowlistLimit} = require('../lib/limit');
const {MaxLimit, AllowlistLimit, FlagLimit} = require('../lib/limit');
describe('Limit Service', function () {
describe('Flag Limit', function () {
it('do nothing if is over limit', async function () {
// NOTE: the behavior of flag limit in "is over limit" usecase is flawed and should not be relied on
// possible solution could be throwing an error to prevent clients from using it?
const config = {
disabled: true
};
const limit = new FlagLimit({name: 'flaggy', config, errors});
const result = await limit.errorIfIsOverLimit();
should(result).be.undefined();
});
it('throws if would go over limit', async function () {
const config = {
disabled: true
};
const limit = new FlagLimit({name: 'flaggy', config, errors});
try {
await limit.errorIfWouldGoOverLimit();
should.fail(limit, 'Should have errored');
} catch (err) {
should.exist(err);
should.exist(err.errorType);
should.equal(err.errorType, 'HostLimitError');
should.exist(err.errorDetails);
should.equal(err.errorDetails.name, 'flaggy');
should.exist(err.message);
should.equal(err.message, 'Your plan does not support flaggy. Please upgrade to enable flaggy.');
}
});
});
describe('Max Limit', function () {
describe('Constructor', function () {
it('throws if initialized without a max limit', function () {