From a6e19e06d663c9fc8aa36b8d0e66182369af6d23 Mon Sep 17 00:00:00 2001 From: code-xhyun Date: Tue, 21 May 2024 18:02:19 +0900 Subject: [PATCH] test: add tests for countJobs method in Pulse class --- test/unit/pulse.spec.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/unit/pulse.spec.ts b/test/unit/pulse.spec.ts index eda7506..ce03269 100644 --- a/test/unit/pulse.spec.ts +++ b/test/unit/pulse.spec.ts @@ -339,5 +339,42 @@ describe('Test Pulse', () => { }); }); }); + + describe('Test countJobs', () => { + test('returns zero when there are no jobs', async () => { + const count = await globalPulseInstance.countJobs(); + expect(count).toBe(0); + }); + + test('counts jobs correctly', async () => { + const job1 = globalPulseInstance.create('testJob1', {}); + const job2 = globalPulseInstance.create('testJob2', {}); + await job1.save(); + await job2.save(); + + const count = await globalPulseInstance.countJobs(); + expect(count).toBe(2); + }); + + test('counts jobs with query', async () => { + const job1 = globalPulseInstance.create('testJob1', { type: 'email' }); + const job2 = globalPulseInstance.create('testJob2', { type: 'sms' }); + await job1.save(); + await job2.save(); + + const count = await globalPulseInstance.countJobs({ 'data.type': 'email' }); + expect(count).toBe(1); + }); + + test('counts jobs with options', async () => { + const job1 = globalPulseInstance.create('testJob1', { type: 'email' }); + const job2 = globalPulseInstance.create('testJob2', { type: 'sms' }); + await job1.save(); + await job2.save(); + + const count = await globalPulseInstance.countJobs({}, { limit: 1 }); + expect(count).toBe(1); + }); + }); }); });