Skip to content

Commit

Permalink
feat: add tests for login with email otp whitelabel
Browse files Browse the repository at this point in the history
  • Loading branch information
sherzod-bakhodirov committed Oct 25, 2024
1 parent e26191d commit 18364c7
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,30 @@ test('Generates JSON RPC pending for lost-device', () => {

const handle = magic.auth.loginWithEmailOTP({ email: expectedEmail, showUI: false });

const recovery_code = '10epf6fk';
handle.emit('lost-device', recovery_code);
handle.emit('lost-device');
handle.emit('cancel');

const verifyEvent = magic.auth.createIntermediaryEvent.mock.calls[0];
expect(verifyEvent[0]).toBe('lost-device');

const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[1][0];
expect(intermediaryEventSecondMethod).toBe('cancel');
});

test('Generates JSON RPC pending for verify-recovery-code', () => {
const magic = createMagicSDK();
magic.auth.overlay.post = jest.fn().mockImplementation(() => new Promise(() => {}));
const createIntermediaryEventFn = jest.fn();
magic.auth.createIntermediaryEvent = jest.fn().mockImplementation(() => createIntermediaryEventFn);

const handle = magic.auth.loginWithEmailOTP({ email: expectedEmail, showUI: false });

const recovery_code = '10epf6fk';
handle.emit('verify-recovery-code', recovery_code);
handle.emit('cancel');

const verifyEvent = magic.auth.createIntermediaryEvent.mock.calls[0];
expect(verifyEvent[0]).toBe('verify-recovery-code');
expect(createIntermediaryEventFn.mock.calls[0][0]).toBe(recovery_code);

const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[1][0];
Expand Down

0 comments on commit 18364c7

Please sign in to comment.