This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("throttle events for multiple users in 5 second frames", () => { | |
const payload = generatePayload(); | |
const secondPayload = generatePayload(); | |
testScheduler.run(({ hot, expectObservable }) => { | |
const events$ = hot("-uvu-vu- 5s --vuuv-|", { | |
u: new ValidationCodeGeneratedEvent(payload), | |
v: new ValidationCodeGeneratedEvent(secondPayload), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const VALIDATION_CODE_THROTTLE_TIME_IN_MS = 5000; | |
const getUserId = ({ payload: { user } }: ValidationCodeGeneratedEvent): User["id"] => user.id; | |
@Injectable() | |
export class ValidationCodeSagas { | |
@Saga() | |
ValidationCodeRequested = (event$: Observable<IEvent>): Observable<SendValidationCodeCommand> => { | |
return event$.pipe( | |
ofType(ValidationCodeGeneratedEvent), | |
groupBy(getUserId), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const generatePayload = (): SendValidationCodeCommandPayload => { | |
const user = { | |
id: faker.random.uuid() as User["id"], | |
} as UserInContext; | |
return { | |
user, | |
code: faker.random.word(), | |
channel: VALIDATION_CODE_CHANNEL.TEXT, | |
reason: GenerateValidationCodeReason.PHONE_NUMBER_VERIFICATION, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const VALIDATION_CODE_THROTTLE_TIME_IN_MS = 5000; | |
@Injectable() | |
export class ValidationCodeSagas { | |
@Saga() | |
ValidationCodeRequested = (event$: Observable<IEvent>): Observable<SendValidationCodeCommand> => { | |
return event$.pipe( | |
ofType(ValidationCodeGeneratedEvent), | |
throttleTime(VALIDATION_CODE_THROTTLE_TIME_IN_MS), | |
map(({ payload }) => new SendValidationCodeCommand(payload)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class ValidationCodeSagas { | |
@Saga() | |
ValidationCodeRequested = (event$: Observable<IEvent>): Observable<SendValidationCodeCommand> => { | |
return event$.pipe( | |
ofType(ValidationCodeGeneratedEvent), | |
map(({ payload }) => new SendValidationCodeCommand(payload)), | |
); | |
}; | |
} |