2020-09-01 12:47:12 +00:00
|
|
|
import {
|
|
|
|
Limit,
|
|
|
|
incLimitedValue,
|
|
|
|
isLimitReached,
|
|
|
|
resetAllLimits,
|
|
|
|
setMaxLimit,
|
|
|
|
} from './limits';
|
2019-10-14 11:15:37 +00:00
|
|
|
|
|
|
|
describe('lib/workers/global/limits', () => {
|
2020-09-01 12:47:12 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
resetAllLimits();
|
2019-10-14 11:15:37 +00:00
|
|
|
});
|
2020-09-01 12:47:12 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
resetAllLimits();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('increments limited value', () => {
|
|
|
|
setMaxLimit(Limit.Commits, 3);
|
|
|
|
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBe(false);
|
|
|
|
|
|
|
|
incLimitedValue(Limit.Commits, 2);
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBe(false);
|
|
|
|
|
|
|
|
incLimitedValue(Limit.Commits);
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBe(true);
|
|
|
|
|
|
|
|
incLimitedValue(Limit.Commits);
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('defaults to unlimited', () => {
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('increments undefined', () => {
|
|
|
|
incLimitedValue(Limit.Commits);
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBe(false);
|
2020-12-11 08:26:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('resets counter', () => {
|
2020-09-01 12:47:12 +00:00
|
|
|
setMaxLimit(Limit.Commits, 1);
|
2020-12-11 08:26:47 +00:00
|
|
|
incLimitedValue(Limit.Commits);
|
2020-09-01 12:47:12 +00:00
|
|
|
expect(isLimitReached(Limit.Commits)).toBe(true);
|
2020-12-11 08:26:47 +00:00
|
|
|
setMaxLimit(Limit.Commits, 1);
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('resets limit', () => {
|
|
|
|
setMaxLimit(Limit.Commits, 1);
|
|
|
|
incLimitedValue(Limit.Commits);
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBe(true);
|
|
|
|
setMaxLimit(Limit.Commits, null);
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets non-positive limit as reached', () => {
|
|
|
|
setMaxLimit(Limit.Commits, 0);
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBeTrue();
|
|
|
|
setMaxLimit(Limit.Commits, -1000);
|
|
|
|
expect(isLimitReached(Limit.Commits)).toBeTrue();
|
2019-10-14 11:15:37 +00:00
|
|
|
});
|
|
|
|
});
|