Skip to content

Commit

Permalink
Merge pull request aws-amplify#986 from powerful23/auth-verifyContact…
Browse files Browse the repository at this point in the history
…-fix

fix(aws-amplify-react): Verify contact before signed in
  • Loading branch information
powerful23 authored Jun 6, 2018
2 parents 299013d + 2e7bcc1 commit 788b12c
Show file tree
Hide file tree
Showing 28 changed files with 708 additions and 24 deletions.
6 changes: 3 additions & 3 deletions packages/aws-amplify-react/__tests__/Auth/AuthPiece-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ describe('AuthPiece test', () => {
name: 'name',
value: 'value',
type: 'radio',
checked: 'checked'
checked: true
}
}
const wrapper = shallow(<TestPiece/>);
const testPiece = wrapper.instance();

testPiece.handleInputChange(event);

expect(testPiece.inputs).toEqual({ name: 'checked' });
expect(testPiece.inputs).toEqual( {"checkedValue": "value", "name": true});
});

test('happy case without checke_type', () => {
Expand All @@ -192,7 +192,7 @@ describe('AuthPiece test', () => {

testPiece.handleInputChange(event);

expect(testPiece.inputs).toEqual({ name: 'value' });
expect(testPiece.inputs).toEqual({"checkedValue": null, "name": "value"});
});
});
});
54 changes: 51 additions & 3 deletions packages/aws-amplify-react/__tests__/Auth/ConfirmSignIn-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -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();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -106,7 +106,7 @@ describe('RequireNewPassword test', () => {
'password',
'requiredAttributes');

expect(spyon2).toBeCalledWith('signedIn', 'user');
expect(spyon2).toBeCalledWith('user');
spyon.mockClear();
});

Expand Down Expand Up @@ -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();
});
});
});

52 changes: 50 additions & 2 deletions packages/aws-amplify-react/__tests__/Auth/TOTPSetup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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();
});
});
})
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe.only('VerifyContent test', () => {

wrapper.find(Link).simulate('click');

expect(spyon).toBeCalledWith('signedIn');
expect(spyon).toBeCalled();

spyon.mockClear();
});
Expand Down Expand Up @@ -157,11 +157,12 @@ describe.only('VerifyContent test', () => {
const wrapper = shallow(<VerifyContact/>);
const verifyContact = wrapper.instance();
verifyContact.inputs = {
contact: 'contact'
contact: true,
checkedValue: 'email'
}

await verifyContact.verify();
expect(spyon).toBeCalledWith('contact');
expect(spyon).toBeCalledWith('email');

spyon.mockClear();
});
Expand Down
Loading

0 comments on commit 788b12c

Please sign in to comment.