diff --git a/src/services/fluidConfig.service.spec.ts b/src/services/fluidConfig.service.spec.ts index 3714918d14345cca09ee437166f4a1bc2c4fc96d..2c944757f466effa6e1cadf56151795137d38051 100644 --- a/src/services/fluidConfig.service.spec.ts +++ b/src/services/fluidConfig.service.spec.ts @@ -9,11 +9,20 @@ describe('ConfigService service', () => { }) }) describe('getCronArgs', () => { - it('should return the args of a cron', () => { - const max = 5 - const min = 5 + it('should return minimum cron', () => { + const min = 7 + const max = 9 + jest.spyOn(global.Math, 'random').mockReturnValue(0) const result = configService.getCronArgs(min, max) - expect(typeof result).toEqual('string') + expect(result).toEqual(`0 0 ${min} * * *`) + }) + it('should return maximum cron', () => { + const min = 7 + const max = 9 + jest.spyOn(global.Math, 'random').mockReturnValue(0.9999) + + const result = configService.getCronArgs(min, max) + expect(result).toEqual(`59 59 ${max} * * *`) }) }) }) diff --git a/src/services/fluidConfig.service.ts b/src/services/fluidConfig.service.ts index 5341c940e9b26c2afb339c9d881708635439283d..0778668369ac5bc8afbb5986a596c0dee3365707 100644 --- a/src/services/fluidConfig.service.ts +++ b/src/services/fluidConfig.service.ts @@ -7,13 +7,14 @@ export default class ConfigService { } /** - * + * Generate a cron between min:00:00 and max:59:59 * @param min Minimum hour for cron * @param max Maximum hour for cron */ - public getCronArgs(min = 8, max = 9): string { + public getCronArgs(min: number, max: number): string { const randomHour = Math.floor(Math.random() * (max - min + 1) + min) // NOSONAR - const randomMinutes = Math.floor(Math.random() * 59) // NOSONAR - return `0 ${randomMinutes} ${randomHour} * * *` + const randomMinutes = Math.floor(Math.random() * 60) // NOSONAR + const randomSeconds = Math.floor(Math.random() * 60) // NOSONAR + return `${randomSeconds} ${randomMinutes} ${randomHour} * * *` } } diff --git a/src/services/triggers.service.ts b/src/services/triggers.service.ts index 3540fad12ceb7984bbe6baf52ee7c9bdddc9d852..5e363dbe5a34b8324a398a3532f8de596ab8e877 100644 --- a/src/services/triggers.service.ts +++ b/src/services/triggers.service.ts @@ -25,7 +25,7 @@ export default class TriggerService { private createTriggerAttributes(account: Account, konnector: Konnector) { const configService = new ConfigService() - const cronArgs = configService.getCronArgs() + const cronArgs = configService.getCronArgs(7, 9) const triggerAttributes: TriggerAttributes = buildAttributes({ account: account, cron: cronArgs,