Something went wrong. Try again.
Mirrored from GitHub github.com/roostorg/coop
Something went wrong. Try again.
1.4 kB · 41 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142import { RuleAlarmStatus } from '../moderationConfigService/index.js';import makeGetCurrentPeriodRuleAlarmStatuses from './getCurrentPeriodRuleAlarmStatuses.js';
describe('getCurrentPeriodRuleAlarmStatuses', () => { test('returns INSUFFICIENT_DATA when rule history has no matching entry', async () => { const ruleId = 'rule-without-history'; const ruleVersion = new Date('2026-08-22T00:00:00.000Z'); const currentPeriod = { ruleId, approxRuleVersion: ruleVersion, windowStart: new Date('2026-08-22T00:00:00.000Z'), passCount: 50, passingUsersCount: 50, runsCount: 1000, }; const historicalPeriods = Array.from({ length: 25 }, (_, index) => ({ ruleId, approxRuleVersion: ruleVersion, windowStart: new Date( Date.parse('2026-08-22T00:00:00.000Z') - (index + 1) * 60 * 60 * 1000, ), passCount: index < 4 ? 1 : 0, passingUsersCount: index < 4 ? 1 : 0, runsCount: 200, })); const getStatuses = makeGetCurrentPeriodRuleAlarmStatuses( async () => [currentPeriod, ...historicalPeriods], async () => [], );
await expect(getStatuses()).resolves.toEqual({ [ruleId]: { status: RuleAlarmStatus.INSUFFICIENT_DATA, meta: { lastPeriodPassRate: undefined, secondToLastPeriodPassRate: undefined, }, }, }); });});