-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #700 from magiclabs/jerryliu-PDEEXP-70-add-whitela…
…bel-events-in-magic-js-add-whitelabel-events-in-magic-js Enable whitelabel for updateEmail flow
- Loading branch information
Showing
8 changed files
with
222 additions
and
120 deletions.
There are no files selected for viewing
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
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
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
78 changes: 78 additions & 0 deletions
78
packages/@magic-sdk/provider/test/spec/modules/auth/updateEmailWithUI.whitelabel.spec.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import browserEnv from '@ikscodes/browser-env'; | ||
import { RecencyCheckEventEmit, UpdateEmailEventEmit } from '@magic-sdk/types'; | ||
import { createMagicSDK } from '../../../factories'; | ||
|
||
beforeEach(() => { | ||
browserEnv.restore(); | ||
}); | ||
|
||
test('Generate JSON RPC request payload with method `magic_auth_update_email` whitelabel and start recency check', async () => { | ||
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.updateEmailWithUI({ email: 'test', showUI: false }); | ||
|
||
const troll_otp = '123456'; | ||
handle.emit(RecencyCheckEventEmit.VerifyEmailOtp, troll_otp); | ||
handle.emit(RecencyCheckEventEmit.Cancel); | ||
|
||
const verifyEvent = magic.auth.createIntermediaryEvent.mock.calls[0]; | ||
expect(verifyEvent[0]).toBe(RecencyCheckEventEmit.VerifyEmailOtp); | ||
expect(createIntermediaryEventFn.mock.calls[0][0]).toBe(troll_otp); | ||
|
||
const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[1][0]; | ||
expect(intermediaryEventSecondMethod).toBe(RecencyCheckEventEmit.Cancel); | ||
}); | ||
|
||
test('Whitelabel `magic_auth_update_email`, recency check Retry event', async () => { | ||
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.updateEmailWithUI({ email: 'test', showUI: false }); | ||
|
||
handle.emit(RecencyCheckEventEmit.Retry); | ||
|
||
const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[0][0]; | ||
expect(intermediaryEventSecondMethod).toBe(RecencyCheckEventEmit.Retry); | ||
}); | ||
|
||
test('Whitelabel `magic_auth_update_email`, Update Email, fire retry with Email event', async () => { | ||
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.updateEmailWithUI({ email: 'test', showUI: false }); | ||
|
||
const alternativeEmail = '[email protected]'; | ||
|
||
handle.emit(UpdateEmailEventEmit.RetryWithNewEmail, alternativeEmail); | ||
|
||
const intermediaryEventFirstMethod = magic.auth.createIntermediaryEvent.mock.calls[0][0]; | ||
expect(intermediaryEventFirstMethod).toBe(UpdateEmailEventEmit.RetryWithNewEmail); | ||
expect(createIntermediaryEventFn.mock.calls[0][0]).toBe(alternativeEmail); | ||
}); | ||
|
||
test('Generate JSON RPC request payload with method `magic_auth_update_email` whitelabel and start verify Email otp ', async () => { | ||
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.updateEmailWithUI({ email: 'test', showUI: false }); | ||
|
||
const troll_otp = '123456'; | ||
handle.emit(UpdateEmailEventEmit.VerifyEmailOtp, troll_otp); | ||
handle.emit(UpdateEmailEventEmit.Cancel); | ||
|
||
const verifyEvent = magic.auth.createIntermediaryEvent.mock.calls[0]; | ||
expect(verifyEvent[0]).toBe(UpdateEmailEventEmit.VerifyEmailOtp); | ||
expect(createIntermediaryEventFn.mock.calls[0][0]).toBe(troll_otp); | ||
|
||
const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[1][0]; | ||
expect(intermediaryEventSecondMethod).toBe(UpdateEmailEventEmit.Cancel); | ||
}); |
49 changes: 0 additions & 49 deletions
49
packages/@magic-sdk/provider/test/spec/modules/user/updateEmail.spec.ts
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.