import { DEFAULT_VARROA_THRESHOLD_MITES_PER_DAY, varroaThresholdOf, } from './varroa-threshold'; describe('varroaThresholdOf', () => { it('uses the default when no rule exists yet (default rule is active)', () => { expect(varroaThresholdOf(null)).toBe( DEFAULT_VARROA_THRESHOLD_MITES_PER_DAY, ); expect(DEFAULT_VARROA_THRESHOLD_MITES_PER_DAY).toBe(10); }); it('returns null for an inactive rule', () => { expect( varroaThresholdOf({ active: false, config: { thresholdMitesPerDay: 7 }, }), ).toBeNull(); }); it('returns the configured threshold of an active rule', () => { expect( varroaThresholdOf({ active: true, config: { thresholdMitesPerDay: 7 } }), ).toBe(7); }); it.each([ ['a string', { thresholdMitesPerDay: 'x' }], ['zero', { thresholdMitesPerDay: 0 }], ['a negative number', { thresholdMitesPerDay: -1 }], ['NaN', { thresholdMitesPerDay: Number.NaN }], ['a missing key', {}], ['a null config', null], ])('falls back to the default for %s', (_label, config) => { expect(varroaThresholdOf({ active: true, config })).toBe( DEFAULT_VARROA_THRESHOLD_MITES_PER_DAY, ); }); });