Skip to content

Commit

Permalink
fix(notifier): fix notifier redisHelper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
e11sy committed Feb 2, 2025
1 parent 70507ec commit 0cb1d65
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions workers/notifier/tests/redisHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ describe('RedisHelper', () => {
it('should return event count', async () => {
const ruleId = 'ruleId';
const groupHash = 'groupHash';
const projectId = 'projectId';
const thresholdPeriod = 1000;

const currentEventCount = await redisHelper.computeEventCountForPeriod(ruleId, groupHash, thresholdPeriod);
const currentEventCount = await redisHelper.computeEventCountForPeriod(projectId, ruleId, groupHash, thresholdPeriod);

expect(currentEventCount).toBe(1);
});
Expand All @@ -72,21 +73,22 @@ describe('RedisHelper', () => {
const ruleId = 'ruleId';
const currentDate = Date.now();
const groupHash = 'groupHash';
const projectId = 'projectId';
const thresholdPeriod = 1000;

/**
* Send several events to increment counter
*/
await redisHelper.computeEventCountForPeriod(ruleId, groupHash, thresholdPeriod);
await redisHelper.computeEventCountForPeriod(ruleId, groupHash, thresholdPeriod);
await redisHelper.computeEventCountForPeriod(ruleId, groupHash, thresholdPeriod);
await redisHelper.computeEventCountForPeriod(projectId, ruleId, groupHash, thresholdPeriod);
await redisHelper.computeEventCountForPeriod(projectId, ruleId, groupHash, thresholdPeriod);
await redisHelper.computeEventCountForPeriod(projectId, ruleId, groupHash, thresholdPeriod);

/**
* Update current date for threshold period expiration
*/
jest.spyOn(global.Date, 'now').mockImplementation(() => currentDate + 2 * thresholdPeriod + 1);

const currentEventCount = await redisHelper.computeEventCountForPeriod(ruleId, groupHash, thresholdPeriod);
const currentEventCount = await redisHelper.computeEventCountForPeriod(projectId, ruleId, groupHash, thresholdPeriod);
const currentlyStoredTimestamp = await redisClient.hGet(`${ruleId}:${groupHash}:${thresholdPeriod}`, 'timestamp');

expect(currentEventCount).toBe(1);
Expand Down

0 comments on commit 0cb1d65

Please sign in to comment.