Skip to content

Instantly share code, notes, and snippets.

@pchab
Created June 30, 2021 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pchab/57301f6560fa07946152672cfaab0d4c to your computer and use it in GitHub Desktop.
Save pchab/57301f6560fa07946152672cfaab0d4c to your computer and use it in GitHub Desktop.
validation code saga marble test part 1
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