[tests] added global.TestHelpers + firestore helpers `TestHelpers.firestore.X`

This commit is contained in:
Salakar 2018-04-12 08:14:17 +01:00
parent 85efdecb1a
commit 1838089684
1 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,42 @@
module.exports = {
DOC_1: { name: 'doc1' },
DOC_2: { name: 'doc2', title: 'Document 2' },
// needs to be a fn as firebase may not yet be available
COL_DOC_1() {
return {
baz: true,
daz: 123,
foo: 'bar',
gaz: 12.1234567,
geopoint: new firebase.firestore.GeoPoint(0, 0),
naz: null,
object: {
daz: 123,
},
timestamp: new Date(2017, 2, 10, 10, 0, 0),
};
},
/**
*
* @param collectionName
* @return {Promise<*>}
*/
async cleanCollection(collectionName = 'collection-tests') {
const firestore = firebaseAdmin.firestore();
const batch = firestore.batch();
const collection = firestore.collection(collectionName);
const docsToDelete = await collection.get();
for (let i = 0, len = docsToDelete.length; i < len; i++) {
const { ref, path } = docsToDelete[i];
if (path.includes(testRunId)) {
batch.delete(ref);
}
}
return writeBatch.commit();
},
};