[tests] misc
This commit is contained in:
parent
710f2ef44f
commit
f57962b018
|
@ -2,42 +2,43 @@ const { testDocRef } = TestHelpers.firestore;
|
|||
|
||||
describe('firestore()', () => {
|
||||
describe('batch()', () => {
|
||||
it('should create / update / delete', () => {
|
||||
it('should create / update / delete', async () => {
|
||||
const ayRef = testDocRef('AY');
|
||||
const lRef = testDocRef('LON');
|
||||
const nycRef = testDocRef('NYC');
|
||||
const sfRef = testDocRef('SF');
|
||||
const batch = firebase.firestore().batch();
|
||||
|
||||
return firebase
|
||||
.firestore()
|
||||
.batch()
|
||||
.set(ayRef, { name: 'Aylesbury' })
|
||||
.set(lRef, { name: 'London' })
|
||||
.set(nycRef, { name: 'New York City' })
|
||||
.set(sfRef, { name: 'San Francisco' })
|
||||
.update(nycRef, { population: 1000000 })
|
||||
.update(sfRef, 'name', 'San Fran')
|
||||
.update(
|
||||
batch.set(ayRef, { name: 'Aylesbury' });
|
||||
batch.set(lRef, { name: 'London' });
|
||||
batch.set(nycRef, { name: 'New York City' });
|
||||
batch.set(sfRef, { name: 'San Francisco' });
|
||||
|
||||
batch.update(nycRef, { population: 1000000 });
|
||||
batch.update(sfRef, 'name', 'San Fran');
|
||||
batch.update(
|
||||
sfRef,
|
||||
new firebase.firestore.FieldPath('name'),
|
||||
'San Fran FieldPath'
|
||||
)
|
||||
.update(
|
||||
);
|
||||
batch.update(
|
||||
sfRef,
|
||||
new firebase.firestore.FieldPath('nested', 'name'),
|
||||
'Nested Nme'
|
||||
)
|
||||
.update(
|
||||
);
|
||||
batch.update(
|
||||
sfRef,
|
||||
new firebase.firestore.FieldPath('nested', 'firstname'),
|
||||
'First Name',
|
||||
new firebase.firestore.FieldPath('nested', 'lastname'),
|
||||
'Last Name'
|
||||
)
|
||||
.set(lRef, { population: 3000000 }, { merge: true })
|
||||
.delete(ayRef)
|
||||
.commit()
|
||||
.then(async () => {
|
||||
);
|
||||
|
||||
batch.set(lRef, { population: 3000000 }, { merge: true });
|
||||
batch.delete(ayRef);
|
||||
|
||||
await batch.commit();
|
||||
|
||||
const ayDoc = await ayRef.get();
|
||||
should.equal(ayDoc.exists, false);
|
||||
|
||||
|
@ -54,7 +55,6 @@ describe('firestore()', () => {
|
|||
sfDoc.data().nested.firstname.should.equal('First Name');
|
||||
sfDoc.data().nested.lastname.should.equal('Last Name');
|
||||
});
|
||||
});
|
||||
|
||||
it('errors when invalid parameters supplied', async () => {
|
||||
const ref = firebase.firestore().doc('collection/doc');
|
||||
|
|
|
@ -139,7 +139,7 @@ describe('firestore()', () => {
|
|||
it('handle native exceptions', async () => {
|
||||
const firestore = firebase.firestore();
|
||||
const docRef = testDocRef('tSet');
|
||||
const blockedRef = firestore.doc('blocked-collection/foo');
|
||||
const blockedRef = firestore.doc('denied/foo');
|
||||
|
||||
const updateFunction = async transaction => {
|
||||
await transaction.get(docRef);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const TEST_COLLECTION_NAME = 'collection-tests';
|
||||
const TEST_COLLECTION_NAME = 'tests';
|
||||
|
||||
let shouldCleanup = false;
|
||||
const ONE_HOUR = 60 * 60 * 1000;
|
||||
|
@ -6,18 +6,22 @@ const ONE_HOUR = 60 * 60 * 1000;
|
|||
module.exports = {
|
||||
async cleanup() {
|
||||
if (!shouldCleanup) return Promise.resolve();
|
||||
await module.exports.cleanCollection(TEST_COLLECTION_NAME);
|
||||
// TODO add any others?
|
||||
await Promise.all([
|
||||
module.exports.cleanCollection(TEST_COLLECTION_NAME),
|
||||
module.exports.cleanCollection(`${TEST_COLLECTION_NAME}2`),
|
||||
]);
|
||||
// await module.exports.cleanCollection(`${TEST_COLLECTION_NAME}3`);
|
||||
// await module.exports.cleanCollection(`${TEST_COLLECTION_NAME}4`);
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
TEST_COLLECTION_NAME,
|
||||
|
||||
DOC_1: { name: 'doc1' },
|
||||
DOC_1_PATH: `collection-tests/doc1${testRunId}`,
|
||||
DOC_1_PATH: `tests/doc1${testRunId}`,
|
||||
|
||||
DOC_2: { name: 'doc2', title: 'Document 2' },
|
||||
DOC_2_PATH: `collection-tests/doc2${testRunId}`,
|
||||
DOC_2_PATH: `tests/doc2${testRunId}`,
|
||||
|
||||
// needs to be a fn as firebase may not yet be available
|
||||
COL_DOC_1() {
|
||||
|
@ -36,7 +40,7 @@ module.exports = {
|
|||
};
|
||||
},
|
||||
|
||||
COL_DOC_1_PATH: `collection-tests/col1${testRunId}`,
|
||||
COL_DOC_1_PATH: `tests/col1${testRunId}`,
|
||||
COL_DOC_1_ID: `col1${testRunId}`,
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue