chore: global sync per minute safety limit (#2765)

This commit is contained in:
Karol Sójko
2024-01-11 15:26:09 +01:00
committed by GitHub
parent 3d895ca499
commit cf4b5ccf0a
11 changed files with 140 additions and 10 deletions

View File

@@ -0,0 +1,38 @@
import { SyncFrequencyGuard } from './SyncFrequencyGuard'
describe('SyncFrequencyGuard', () => {
const createUseCase = () => new SyncFrequencyGuard(3)
it('should return false when sync calls threshold is not reached', () => {
const useCase = createUseCase()
expect(useCase.isSyncCallsThresholdReachedThisMinute()).toBe(false)
})
it('should return true when sync calls threshold is reached', () => {
const useCase = createUseCase()
useCase.incrementCallsPerMinute()
useCase.incrementCallsPerMinute()
useCase.incrementCallsPerMinute()
expect(useCase.isSyncCallsThresholdReachedThisMinute()).toBe(true)
})
it('should return false when sync calls threshold is reached but a new minute has started', () => {
const spyOnGetCallsPerMinuteKey = jest.spyOn(SyncFrequencyGuard.prototype as any, 'getCallsPerMinuteKey')
spyOnGetCallsPerMinuteKey.mockReturnValueOnce('2020-1-1T1:1')
const useCase = createUseCase()
useCase.incrementCallsPerMinute()
useCase.incrementCallsPerMinute()
useCase.incrementCallsPerMinute()
spyOnGetCallsPerMinuteKey.mockReturnValueOnce('2020-1-1T1:2')
expect(useCase.isSyncCallsThresholdReachedThisMinute()).toBe(false)
spyOnGetCallsPerMinuteKey.mockRestore()
})
})