Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should retrieve belongsTo and hasMany relationships in hasMany embedded record', async () => {
/**
* A record embedded with a hasMany relationship can contain belongsTo and hasMany relationships to other records, confirm they are retrieved successfully
*
* This retrieves the data created in the previous test
*/
const store: Store = new Store(admin.database(), { basePath });
const post: Post = await store.findRecord(Post, testData.post[1].id);
const firstPhoto = post.photos.filter((photo: Photo) => photo.id === testData.photo[1].id)[0];
expect(firstPhoto, 'Photo with id of photo1 is in post photos').to.not.be.an('undefined');
const takenBy = await firstPhoto.takenBy;
expect(takenBy.name, 'taken by is user3').to.equal(testData.user[3].name);
const taggedUsers = firstPhoto.taggedUsers;
// Firebase does not preserve array ordering so the two tagged users
await Promise.all(taggedUsers.map(async (taggedUserPromise: ModelOrPromise) => {
const user = await taggedUserPromise;
if (user.id === testData.user[1].id) {
expect(user.name, 'tagged user 1 is user 1').to.equal(testData.user[1].name);
parentPastebinId: 0,
children: 0
},
users: 0
};
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: dataBaseUrl,
// storageBucket: "firebase-seecoderun.appspot.com",
databaseAuthVariableOverride: {
uid: uid
}
});
const databaseRef = admin.database();
// Provide custom logger which prefixes log statements with "[FIREBASE]"
// Disable logging across page refreshes
// databaseRef.enableLogging(function (message) {
// console.log("[FIREBASE]", message);
// },
// false);
let databaseRootRef = databaseRef.ref(dataBaseRoot);
// Data functions
const makeNewPastebin = onComplete => {
return databaseRootRef
.push(defaultPastebinScheme, onComplete);
};
const makeNewPastebinId = () => {
return databaseRootRef.push(0).key;
console.log('Post lab write: updating indices');
delta[`/idx/user_labs/${data.user_id}/${data.id}`] = true;
delta[`/idx/user_visible_labs/${data.user_id}/${data.id}`] = data.hidden ? null : true;
if (data.hidden || data.is_private) {
delta[`/idx/recent_labs/${data.id}`] = null;
}
// We need to find all executions that are attached to this lab
// and hide them as well.
//
// Notice we don't update `lab_visible_executions` because we only
// need to hide them for the users not for the labs.
return admin
.database()
.ref(`/idx/lab_executions/${data.id}`)
.once('value')
.then(snapshot => snapshot.val())
.then(val => (val ? Object.keys(val) : []))
.then(executionIds => {
executionIds.forEach(id => {
delta[`/idx/user_visible_executions/${data.user_id}/${id}`] = data.hidden ? null : true;
});
})
.then(_ =>
admin
.database()
.ref()
.update(delta)
);
email,
emailVerified,
accessToken,
twitchUserData
) {
// The UID we'll assign to the user.
const uid = `twitch:${userId}`;
// Save the access token to the Firebase Realtime Database.
const databaseAccesTokenTask = admin
.database()
.ref(`/twitchAccessToken/${uid}`)
.set(accessToken);
// Save the twitch user-data to the Firebase Realtime Database.
const databaseUserDataTask = admin
.database()
.ref(`/twitchUserData/${uid}`)
.set(twitchUserData);
// Create or update the user account.
const userCreationTask = admin
.auth()
.updateUser(uid, {
displayName: username,
photoURL: logoUrl,
email: email,
emailVerified: emailVerified
})
.catch(error => {
// If user does not exists we create it.
if (error.code === 'auth/user-not-found') {
Object.keys(roles).forEach((key, index) => {
if (key === roleUid) {
let grantRef = false
console.log('User role changed:', eventSnapshot.val())
if (eventSnapshot.val()) {
grantRef = admin.database().ref(`user_grants/${userUid}/${grantUid}`).set(true)
} else {
grantRef = admin.database().ref(`user_grants/${userUid}/${grantUid}`).remove()
}
promises.push(grantRef)
console.log('Role changed', userUid, roleUid, grantUid)
}
})
})
export async function getVerifier(id: string): Promise {
console.info('Getting verifier from db')
if (!id) {
console.error('Invalid verifier id', id)
return null
}
return (await database()
.ref(`/${CELO_ENV}/mobileVerifiers/${id}`)
.once('value')).val()
}
const admin = require('firebase-admin');
const db = admin.database();
const gamesRef = db.ref('games');
const usersRef = db.ref('users');
const roomsRef = db.ref('rooms');
const Promise = require('bluebird');
const Game = require('../../game/logic.js');
const router = module.exports = require('express').Router();
/** Game Logging */
const util = require('../util');
const log = util.log;
/**
* Game routes for initializing game
const admin = require('firebase-admin');
const env = require('./services/environment');
var credential = admin.credential.cert(env.firebaseConfig.serviceAccount);
admin.initializeApp({
databaseURL: env.firebaseConfig.databaseURL,
credential
});
const ref = admin.database().ref('firebase-search/test/algolia');
const FirebaseSearch = require('./firebase-search');
describe('Firebase Search', () => {
let search;
beforeEach(() => {
search = new FirebaseSearch(ref, env);
});
beforeEach(done =>
clean().then(() => {
search.algolia.search('test').then(res => {
expect(res.nbHits).toEqual(0);
done();
});
}));
exports.clean = functions.https.onRequest((request, response) => {
admin
.database()
.ref('/')
.set({
todos: {
'-KtqzKEE4kQHdckAXEmh': {
done: true,
label: 'Hello',
},
'-KtqzL-Rgzmox9liHblv': {
done: false,
label: 'World',
},
},
})
const documentReferences = []