[tests][auth] added signInWithCustomToken test
This commit is contained in:
parent
6500212e39
commit
ffcb34f949
@ -1,4 +1,26 @@
|
|||||||
describe('auth()', () => {
|
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()', () => {
|
describe('onAuthStateChanged()', () => {
|
||||||
it('calls callback with the current user and when auth state changes', async () => {
|
it('calls callback with the current user and when auth state changes', async () => {
|
||||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
const detox = require('detox');
|
const detox = require('detox');
|
||||||
const config = require('../package.json').detox;
|
const config = require('../package.json').detox;
|
||||||
|
require('./../helpers');
|
||||||
global.sinon = require('sinon');
|
|
||||||
require('should-sinon');
|
|
||||||
global.should = require('should');
|
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await detox.init(config);
|
await detox.init(config);
|
||||||
@ -12,27 +9,3 @@ before(async () => {
|
|||||||
after(async () => {
|
after(async () => {
|
||||||
await detox.cleanup();
|
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;
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user