Skip to content

Commit

Permalink
send cache full coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Feb 1, 2024
1 parent 3113697 commit e30a466
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/api/tests/send-cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('SendCache', () => {
expect(SendCache.check('id', 'target2')).to.equal(false);
});

it('purges the first item in teh cache when the cache is full (100 items)', async () => {
it('purges the first item in the cache when the target cache is full (100 items)', async () => {
const recordId = 'id';
// set 100 items in the cache to the same id
for (let i = 0; i < 100; i++) {
Expand All @@ -42,4 +42,29 @@ describe('SendCache', () => {
expect(SendCache.check(recordId, 'target-2')).to.equal(true);
expect(SendCache.check(recordId, 'target-new2')).to.equal(true);
});

it('purges the first item in the cache when the record cache is full (100 items)', async () => {
const target = 'target';
// set 100 items in the cache to the same id
for (let i = 0; i < 100; i++) {
SendCache.set(`record-${i}`, target);
}

// check that the first item is in the cache
expect(SendCache.check('record-0', target)).to.equal(true);

// set another item in the cache
SendCache.set('record-new', target);

// check that the first item is no longer in the cache but the one after it is as well as the new one.
expect(SendCache.check('record-0', target)).to.equal(false);
expect(SendCache.check('record-1', target)).to.equal(true);
expect(SendCache.check('record-new', target)).to.equal(true);

// add another item
SendCache.set('record-new2', target);
expect(SendCache.check('record-1', target)).to.equal(false);
expect(SendCache.check('record-2', target)).to.equal(true);
expect(SendCache.check('record-new2', target)).to.equal(true);
});
});

0 comments on commit e30a466

Please sign in to comment.