diff --git a/lib/scheduler.registry.ts b/lib/scheduler.registry.ts index 74005aa8..539f1a06 100644 --- a/lib/scheduler.registry.ts +++ b/lib/scheduler.registry.ts @@ -8,7 +8,7 @@ export class SchedulerRegistry { private readonly timeouts = new Map(); private readonly intervals = new Map(); - isExists(type: 'cron' | 'timeout' | 'interval', name: string) { + doesExists(type: 'cron' | 'timeout' | 'interval', name: string) { switch (type) { case 'cron': return this.cronJobs.has(name); @@ -20,7 +20,7 @@ export class SchedulerRegistry { return false; } } - + getCronJob(name: string) { const ref = this.cronJobs.get(name); if (!ref) { diff --git a/tests/e2e/cron-jobs.spec.ts b/tests/e2e/cron-jobs.spec.ts index 71a8e556..080b8996 100644 --- a/tests/e2e/cron-jobs.spec.ts +++ b/tests/e2e/cron-jobs.spec.ts @@ -172,6 +172,20 @@ describe('Cron', () => { expect(clock.countTimers()).toBe(0); }); + it('should return true for dynamic cron job', async () => { + const service: CronService = app.get(CronService); + await app.init(); + + service.addCronJob(); + expect(service.doesExists('dynamic')).toEqual(true); + }); + + it('should return false for dynamic cron job', async () => { + const service: CronService = app.get(CronService); + await app.init(); + expect(service.doesExists('dynamic')).toEqual(false); + }); + afterEach(async () => { await app.close(); }); diff --git a/tests/e2e/interval.spec.ts b/tests/e2e/interval.spec.ts index a84d08df..31532482 100644 --- a/tests/e2e/interval.spec.ts +++ b/tests/e2e/interval.spec.ts @@ -98,6 +98,20 @@ describe('Interval', () => { expect(jest.getTimerCount()).toBe(0); }); + it('should return true for dynamic interval', async () => { + const service: IntervalService = app.get(IntervalService); + await app.init(); + + service.addInterval(); + expect(service.doesExists('dynamic')).toEqual(true); + }); + + it('should return false for dynamic interval', async () => { + const service: IntervalService = app.get(IntervalService); + await app.init(); + expect(service.doesExists('dynamic')).toEqual(false); + }); + afterEach(async () => { await app.close(); }); diff --git a/tests/e2e/timeout.spec.ts b/tests/e2e/timeout.spec.ts index 8c742383..9e10d2f9 100644 --- a/tests/e2e/timeout.spec.ts +++ b/tests/e2e/timeout.spec.ts @@ -98,6 +98,20 @@ describe('Timeout', () => { expect(jest.getTimerCount()).toBe(0); }); + it('should return true for dynamic timeout', async () => { + const service: TimeoutService = app.get(TimeoutService); + await app.init(); + + service.addTimeout(); + expect(service.doesExists('dynamic')).toEqual(true); + }); + + it('should return false for dynamic timeout', async () => { + const service: TimeoutService = app.get(TimeoutService); + await app.init(); + expect(service.doesExists('dynamic')).toEqual(false); + }); + afterEach(async () => { await app.close(); }); diff --git a/tests/src/cron.service.ts b/tests/src/cron.service.ts index 7a897b44..ce380934 100644 --- a/tests/src/cron.service.ts +++ b/tests/src/cron.service.ts @@ -68,4 +68,8 @@ export class CronService { this.schedulerRegistry.addCronJob('dynamic', job); return job; } + + doesExists(name: string): boolean { + return this.schedulerRegistry.doesExists('cron', name); + } } diff --git a/tests/src/interval.service.ts b/tests/src/interval.service.ts index f7e173b8..f5b72804 100644 --- a/tests/src/interval.service.ts +++ b/tests/src/interval.service.ts @@ -26,4 +26,8 @@ export class IntervalService { (intervalRef as unknown) as number, ); } + + doesExists(name: string): boolean { + return this.schedulerRegistry.doesExists('interval', name); + } } diff --git a/tests/src/timeout.service.ts b/tests/src/timeout.service.ts index 4897f940..fdafa212 100644 --- a/tests/src/timeout.service.ts +++ b/tests/src/timeout.service.ts @@ -25,4 +25,8 @@ export class TimeoutService { (timeoutRef as unknown) as number, ); } + + doesExists(name: string): boolean { + return this.schedulerRegistry.doesExists('timeout', name); + } }