[tests][auth] added signInWithCustomToken test

This commit is contained in:
Salakar 2018-04-09 17:27:53 +01:00
parent 6500212e39
commit ffcb34f949
2 changed files with 23 additions and 28 deletions

View File

@ -1,4 +1,26 @@
describe('auth()', () => {
beforeEach(async () => {
if (firebase.auth().currentUser) await firebase.auth().signOut();
});
describe('signInWithCustomToken()', () => {
it('signs in with a admin sdk created custom auth token', async () => {
const customUID = `custom${randomString(12, '#aA')}`;
const token = await firebaseAdmin.auth().createCustomToken(customUID);
const user = await firebase.auth().signInWithCustomToken(token);
user.uid.should.equal(customUID);
firebase.auth().currentUser.uid.should.equal(customUID);
await firebase.auth().signOut();
const {
user: user2,
} = await firebase.auth().signInAndRetrieveDataWithCustomToken(token);
user2.uid.should.equal(customUID);
firebase.auth().currentUser.uid.should.equal(customUID);
});
});
describe('onAuthStateChanged()', () => {
it('calls callback with the current user and when auth state changes', async () => {
await firebase.auth().signInAnonymouslyAndRetrieveData();

View File

@ -1,9 +1,6 @@
const detox = require('detox');
const config = require('../package.json').detox;
global.sinon = require('sinon');
require('should-sinon');
global.should = require('should');
require('./../helpers');
before(async () => {
await detox.init(config);
@ -12,27 +9,3 @@ before(async () => {
after(async () => {
await detox.cleanup();
});
Object.defineProperty(global, 'firebase', {
get() {
return bridge.module;
},
});
global.sleep = duration =>
new Promise(resolve => {
setTimeout(resolve, duration);
});
global.randomString = (length, chars) => {
let mask = '';
if (chars.indexOf('a') > -1) mask += 'abcdefghijklmnopqrstuvwxyz';
if (chars.indexOf('A') > -1) mask += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if (chars.indexOf('#') > -1) mask += '0123456789';
if (chars.indexOf('!') > -1) mask += '~`!@#$%^&*()_+-={}[]:";\'<>?,./|\\';
let result = '';
for (let i = length; i > 0; --i) {
result += mask[Math.round(Math.random() * (mask.length - 1))];
}
return result;
};