forked from aws-amplify/amplify-js
-
Notifications
You must be signed in to change notification settings - Fork 0
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 aws-amplify#986 from powerful23/auth-verifyContact…
…-fix fix(aws-amplify-react): Verify contact before signed in
- Loading branch information
Showing
28 changed files
with
708 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ describe('ConfirmSignIn', () => { | |
}); | ||
|
||
const wrapper = shallow(<ConfirmSignIn/>); | ||
const spyon2 = jest.spyOn(wrapper.instance(), 'changeState'); | ||
const spyon2 = jest.spyOn(wrapper.instance(), 'checkContact'); | ||
wrapper.setProps({ | ||
authState: acceptedStates[0], | ||
theme: AmplifyTheme, | ||
|
@@ -115,7 +115,7 @@ describe('ConfirmSignIn', () => { | |
expect.assertions(3); | ||
expect(spyon.mock.calls[0][0]).toBe('user'); | ||
expect(spyon.mock.calls[0][1]).toBe('123456'); | ||
expect(spyon2).toBeCalledWith('signedIn', 'user'); | ||
expect(spyon2).toBeCalled(); | ||
|
||
spyon.mockClear(); | ||
spyon2.mockClear(); | ||
|
@@ -136,4 +136,52 @@ describe('ConfirmSignIn', () => { | |
spyon2.mockClear(); | ||
}); | ||
}); | ||
}) | ||
|
||
describe('checkContact test', () => { | ||
test('contact verified', async () => { | ||
const wrapper = shallow(<ConfirmSignIn/>); | ||
const confirmSignIn = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'verifiedContact').mockImplementationOnce(() => { | ||
return Promise.resolve({ | ||
verified: { | ||
email: '[email protected]' | ||
} | ||
}) | ||
}); | ||
|
||
const spyon2 = jest.spyOn(confirmSignIn, 'changeState'); | ||
|
||
await confirmSignIn.checkContact({ | ||
user: 'user' | ||
}); | ||
|
||
expect(spyon2).toBeCalledWith('signedIn', {user: 'user'}); | ||
|
||
spyon.mockClear(); | ||
spyon2.mockClear(); | ||
}); | ||
|
||
test('contact not verified', async () => { | ||
const wrapper = shallow(<ConfirmSignIn/>); | ||
const confirmSignIn = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'verifiedContact').mockImplementationOnce(() => { | ||
return Promise.resolve({ | ||
verified: {} | ||
}) | ||
}); | ||
|
||
const spyon2 = jest.spyOn(confirmSignIn, 'changeState'); | ||
|
||
await confirmSignIn.checkContact({ | ||
user: 'user' | ||
}); | ||
|
||
expect(spyon2).toBeCalledWith('verifyContact', {user: 'user', 'verified': {}}); | ||
|
||
spyon.mockClear(); | ||
spyon2.mockClear(); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -90,7 +90,7 @@ describe('RequireNewPassword test', () => { | |
res('user'); | ||
}); | ||
}); | ||
const spyon2 = jest.spyOn(RequireNewPassword.prototype, 'changeState').mockImplementationOnce(() => { return; }); | ||
const spyon2 = jest.spyOn(RequireNewPassword.prototype, 'checkContact').mockImplementationOnce(() => { return; }); | ||
|
||
const wrapper = shallow(<RequireNewPassword/>); | ||
const requireNewPassword = wrapper.instance(); | ||
|
@@ -106,7 +106,7 @@ describe('RequireNewPassword test', () => { | |
'password', | ||
'requiredAttributes'); | ||
|
||
expect(spyon2).toBeCalledWith('signedIn', 'user'); | ||
expect(spyon2).toBeCalledWith('user'); | ||
spyon.mockClear(); | ||
}); | ||
|
||
|
@@ -212,5 +212,53 @@ describe('RequireNewPassword test', () => { | |
spyon2.mockClear(); | ||
}); | ||
}); | ||
|
||
describe('checkContact test', () => { | ||
test('contact verified', async () => { | ||
const wrapper = shallow(<RequireNewPassword/>); | ||
const rnp = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'verifiedContact').mockImplementationOnce(() => { | ||
return Promise.resolve({ | ||
verified: { | ||
email: '[email protected]' | ||
} | ||
}) | ||
}); | ||
|
||
const spyon2 = jest.spyOn(rnp, 'changeState'); | ||
|
||
await rnp.checkContact({ | ||
user: 'user' | ||
}); | ||
|
||
expect(spyon2).toBeCalledWith('signedIn', {user: 'user'}); | ||
|
||
spyon.mockClear(); | ||
spyon2.mockClear(); | ||
}); | ||
|
||
test('contact not verified', async () => { | ||
const wrapper = shallow(<RequireNewPassword/>); | ||
const rnp = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'verifiedContact').mockImplementationOnce(() => { | ||
return Promise.resolve({ | ||
verified: {} | ||
}) | ||
}); | ||
|
||
const spyon2 = jest.spyOn(rnp, 'changeState'); | ||
|
||
await rnp.checkContact({ | ||
user: 'user' | ||
}); | ||
|
||
expect(spyon2).toBeCalledWith('verifyContact', {user: 'user', 'verified': {}}); | ||
|
||
spyon.mockClear(); | ||
spyon2.mockClear(); | ||
}); | ||
}); | ||
}); | ||
|
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 |
---|---|---|
|
@@ -64,10 +64,10 @@ describe('TOTPSetup', () => { | |
const wrapper = shallow(<TOTPSetup/>); | ||
const TOTPSetupInstance = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(TOTPSetupInstance, 'changeState'); | ||
const spyon = jest.spyOn(TOTPSetupInstance, 'checkContact'); | ||
TOTPSetupInstance.onTOTPEvent('Setup TOTP', 'SUCCESS', 'user'); | ||
|
||
expect(spyon).toBeCalledWith('signedIn', 'user'); | ||
expect(spyon).toBeCalledWith('user'); | ||
spyon.mockClear(); | ||
}); | ||
|
||
|
@@ -82,4 +82,52 @@ describe('TOTPSetup', () => { | |
spyon.mockClear(); | ||
}); | ||
}); | ||
|
||
describe('checkContact test', () => { | ||
test('contact verified', async () => { | ||
const wrapper = shallow(<TOTPSetup/>); | ||
const totpSetup = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'verifiedContact').mockImplementationOnce(() => { | ||
return Promise.resolve({ | ||
verified: { | ||
email: '[email protected]' | ||
} | ||
}) | ||
}); | ||
|
||
const spyon2 = jest.spyOn(totpSetup, 'changeState'); | ||
|
||
await totpSetup.checkContact({ | ||
user: 'user' | ||
}); | ||
|
||
expect(spyon2).toBeCalledWith('signedIn', {user: 'user'}); | ||
|
||
spyon.mockClear(); | ||
spyon2.mockClear(); | ||
}); | ||
|
||
test('contact not verified', async () => { | ||
const wrapper = shallow(<TOTPSetup/>); | ||
const totpSetup = wrapper.instance(); | ||
|
||
const spyon = jest.spyOn(Auth, 'verifiedContact').mockImplementationOnce(() => { | ||
return Promise.resolve({ | ||
verified: {} | ||
}) | ||
}); | ||
|
||
const spyon2 = jest.spyOn(totpSetup, 'changeState'); | ||
|
||
await totpSetup.checkContact({ | ||
user: 'user' | ||
}); | ||
|
||
expect(spyon2).toBeCalledWith('verifyContact', {user: 'user', 'verified': {}}); | ||
|
||
spyon.mockClear(); | ||
spyon2.mockClear(); | ||
}); | ||
}); | ||
}) |
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.