Created
June 30, 2021 17:10
-
-
Save pchab/57301f6560fa07946152672cfaab0d4c to your computer and use it in GitHub Desktop.
validation code saga marble test part 1
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, | |
}; | |
}; | |
describe("validation code saga", () => { | |
let testScheduler: TestScheduler; | |
beforeEach(() => { | |
testScheduler = new TestScheduler((actual, expected) => expect(actual).toStrictEqual(expected)); | |
}); | |
it("throttle events for one user in 5 second frames", () => { | |
const payload = generatePayload(); | |
testScheduler.run(({ hot, expectObservable }) => { | |
const events$ = hot("-vv-v- 5s -vv-|", { | |
v: new ValidationCodeGeneratedEvent(payload), | |
}); | |
const saga = new ValidationCodeSagas(); | |
const output$ = saga.ValidationCodeRequested(events$); | |
expectObservable(output$).toBe("-s---- 5s -s--|", { | |
s: new SendValidationCodeCommand(payload), | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment