Files
react-native-firebase/packages/auth/e2e/phone.e2e.js
gwenoleR 71a1120337 fix!(auth): confirm code returns User instead of UserCredential (#3684)
[publish]

BREAKING CHANGE: `confirm(verificationCode)` now correctly returns an instance of `UserCredentials` instead of `User`. You can access `User` from the `.user` property on the `UserCredentials` instance.
2020-05-28 22:52:07 +01:00

43 lines
1.7 KiB
JavaScript

const TEST_PHONE_A = '+447445255123';
const TEST_CODE_A = '123456';
// const TEST_PHONE_B = '+447445123457';
// const TEST_CODE_B = '654321';
describe('auth() => Phone', () => {
before(async () => {
firebase.auth().settings.appVerificationDisabledForTesting = true;
await firebase.auth().settings.setAutoRetrievedSmsCodeForPhoneNumber(TEST_PHONE_A, TEST_CODE_A);
await Utils.sleep(50);
});
beforeEach(async () => {
if (firebase.auth().currentUser) {
await firebase.auth().signOut();
await Utils.sleep(50);
}
});
// TODO these are flakey on CI and sometimes fail - needs investigation
describe('signInWithPhoneNumber', () => {
it('signs in with a valid code', async () => {
const confirmResult = await firebase.auth().signInWithPhoneNumber(TEST_PHONE_A);
confirmResult.verificationId.should.be.a.String();
should.ok(confirmResult.verificationId.length, 'verificationId string should not be empty');
confirmResult.confirm.should.be.a.Function();
const userCredential = await confirmResult.confirm(TEST_CODE_A);
userCredential.user.should.be.instanceOf(jet.require('packages/auth/lib/User'));
userCredential.user.phoneNumber.should.equal(TEST_PHONE_A);
});
it('errors on invalid code', async () => {
const confirmResult = await firebase.auth().signInWithPhoneNumber(TEST_PHONE_A);
confirmResult.verificationId.should.be.a.String();
should.ok(confirmResult.verificationId.length, 'verificationId string should not be empty');
confirmResult.confirm.should.be.a.Function();
await confirmResult.confirm('666999').should.be.rejected();
// TODO test error code and message
});
});
});