[tests] misc

This commit is contained in:
Salakar 2018-04-16 19:20:00 +01:00
parent 710f2ef44f
commit f57962b018
3 changed files with 55 additions and 51 deletions

View File

@ -2,58 +2,58 @@ 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(
sfRef,
new firebase.firestore.FieldPath('name'),
'San Fran FieldPath'
)
.update(
sfRef,
new firebase.firestore.FieldPath('nested', 'name'),
'Nested Nme'
)
.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 () => {
const ayDoc = await ayRef.get();
should.equal(ayDoc.exists, false);
batch.set(ayRef, { name: 'Aylesbury' });
batch.set(lRef, { name: 'London' });
batch.set(nycRef, { name: 'New York City' });
batch.set(sfRef, { name: 'San Francisco' });
const lDoc = await lRef.get();
lDoc.data().name.should.equal('London');
lDoc.data().population.should.equal(3000000);
batch.update(nycRef, { population: 1000000 });
batch.update(sfRef, 'name', 'San Fran');
batch.update(
sfRef,
new firebase.firestore.FieldPath('name'),
'San Fran FieldPath'
);
batch.update(
sfRef,
new firebase.firestore.FieldPath('nested', 'name'),
'Nested Nme'
);
batch.update(
sfRef,
new firebase.firestore.FieldPath('nested', 'firstname'),
'First Name',
new firebase.firestore.FieldPath('nested', 'lastname'),
'Last Name'
);
const nycDoc = await nycRef.get();
nycDoc.data().name.should.equal('New York City');
nycDoc.data().population.should.equal(1000000);
batch.set(lRef, { population: 3000000 }, { merge: true });
batch.delete(ayRef);
const sfDoc = await sfRef.get();
sfDoc.data().name.should.equal('San Fran FieldPath');
sfDoc.data().nested.firstname.should.equal('First Name');
sfDoc.data().nested.lastname.should.equal('Last Name');
});
await batch.commit();
const ayDoc = await ayRef.get();
should.equal(ayDoc.exists, false);
const lDoc = await lRef.get();
lDoc.data().name.should.equal('London');
lDoc.data().population.should.equal(3000000);
const nycDoc = await nycRef.get();
nycDoc.data().name.should.equal('New York City');
nycDoc.data().population.should.equal(1000000);
const sfDoc = await sfRef.get();
sfDoc.data().name.should.equal('San Fran FieldPath');
sfDoc.data().nested.firstname.should.equal('First Name');
sfDoc.data().nested.lastname.should.equal('Last Name');
});
it('errors when invalid parameters supplied', async () => {

View File

@ -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);

View File

@ -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}`,
/**