[tests] refactor/cleanup misc firestore tests
This commit is contained in:
parent
372abe57b7
commit
e479f0c0f6
|
@ -7,7 +7,6 @@ const {
|
||||||
resetTestCollectionDoc,
|
resetTestCollectionDoc,
|
||||||
} = TestHelpers.firestore;
|
} = TestHelpers.firestore;
|
||||||
|
|
||||||
// TODO cleanup promises and replace with async/await
|
|
||||||
describe('firestore()', () => {
|
describe('firestore()', () => {
|
||||||
describe('DocumentReference', () => {
|
describe('DocumentReference', () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
@ -487,59 +486,52 @@ describe('firestore()', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO async/await these tests
|
|
||||||
describe('update()', () => {
|
describe('update()', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await resetTestCollectionDoc(COL2_DOC_1_PATH, { name: 'doc1' });
|
await resetTestCollectionDoc(COL2_DOC_1_PATH, { name: 'doc1' });
|
||||||
});
|
});
|
||||||
it('should update Document using object', () =>
|
|
||||||
test2DocRef(COL2_DOC_1_ID)
|
|
||||||
.update({ name: 'updated' })
|
|
||||||
.then(async () => {
|
|
||||||
const doc = await test2DocRef(COL2_DOC_1_ID).get();
|
|
||||||
doc.data().name.should.equal('updated');
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should update Document using key/value pairs', () =>
|
it('should update Document using object', async () => {
|
||||||
test2DocRef(COL2_DOC_1_ID)
|
await test2DocRef(COL2_DOC_1_ID).update({ name: 'updated' });
|
||||||
.update('name', 'updated')
|
const doc = await test2DocRef(COL2_DOC_1_ID).get();
|
||||||
.then(async () => {
|
doc.data().name.should.equal('updated');
|
||||||
const doc = await test2DocRef(COL2_DOC_1_ID).get();
|
});
|
||||||
doc.data().name.should.equal('updated');
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should update Document using FieldPath/value pair', () =>
|
it('should update Document using key/value pairs', async () => {
|
||||||
test2DocRef(COL2_DOC_1_ID)
|
await test2DocRef(COL2_DOC_1_ID).update('name', 'updated');
|
||||||
.update(new firebase.firestore.FieldPath('name'), 'Name')
|
const doc = await test2DocRef(COL2_DOC_1_ID).get();
|
||||||
.then(async () => {
|
doc.data().name.should.equal('updated');
|
||||||
const doc = await test2DocRef(COL2_DOC_1_ID).get();
|
});
|
||||||
doc.data().name.should.equal('Name');
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should update Document using nested FieldPath and value pair', () =>
|
it('should update Document using FieldPath/value pair', async () => {
|
||||||
test2DocRef(COL2_DOC_1_ID)
|
await test2DocRef(COL2_DOC_1_ID).update(
|
||||||
.update(
|
new firebase.firestore.FieldPath('name'),
|
||||||
new firebase.firestore.FieldPath('nested', 'name'),
|
'Name'
|
||||||
'Nested Name'
|
);
|
||||||
)
|
const doc = await test2DocRef(COL2_DOC_1_ID).get();
|
||||||
.then(async () => {
|
doc.data().name.should.equal('Name');
|
||||||
const doc = await test2DocRef(COL2_DOC_1_ID).get();
|
});
|
||||||
doc.data().nested.name.should.equal('Nested Name');
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should update Document using multiple FieldPath/value pairs', () =>
|
it('should update Document using nested FieldPath and value pair', async () => {
|
||||||
test2DocRef(COL2_DOC_1_ID)
|
await test2DocRef(COL2_DOC_1_ID).update(
|
||||||
.update(
|
new firebase.firestore.FieldPath('nested', 'name'),
|
||||||
new firebase.firestore.FieldPath('nested', 'firstname'),
|
'Nested Name'
|
||||||
'First Name',
|
);
|
||||||
new firebase.firestore.FieldPath('nested', 'lastname'),
|
const doc = await test2DocRef(COL2_DOC_1_ID).get();
|
||||||
'Last Name'
|
doc.data().nested.name.should.equal('Nested Name');
|
||||||
)
|
});
|
||||||
.then(async () => {
|
|
||||||
const doc = await test2DocRef(COL2_DOC_1_ID).get();
|
it('should update Document using multiple FieldPath/value pairs', async () => {
|
||||||
doc.data().nested.firstname.should.equal('First Name');
|
await test2DocRef(COL2_DOC_1_ID).update(
|
||||||
doc.data().nested.lastname.should.equal('Last Name');
|
new firebase.firestore.FieldPath('nested', 'firstname'),
|
||||||
}));
|
'First Name',
|
||||||
|
new firebase.firestore.FieldPath('nested', 'lastname'),
|
||||||
|
'Last Name'
|
||||||
|
);
|
||||||
|
const doc = await test2DocRef(COL2_DOC_1_ID).get();
|
||||||
|
doc.data().nested.firstname.should.equal('First Name');
|
||||||
|
doc.data().nested.lastname.should.equal('Last Name');
|
||||||
|
});
|
||||||
|
|
||||||
it('errors when invalid parameters supplied', async () => {
|
it('errors when invalid parameters supplied', async () => {
|
||||||
const docRef = test2DocRef(COL2_DOC_1_ID);
|
const docRef = test2DocRef(COL2_DOC_1_ID);
|
||||||
|
|
|
@ -137,7 +137,7 @@ describe('firestore()', () => {
|
||||||
should.equal(didReject, true);
|
should.equal(didReject, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('handle native exceptions', async () => {
|
it('handle native exceptions', async () => {
|
||||||
const firestore = firebase.firestore();
|
const firestore = firebase.firestore();
|
||||||
const docRef = testDocRef('tSet');
|
const docRef = testDocRef('tSet');
|
||||||
const blockedRef = firestore.doc('denied/foo');
|
const blockedRef = firestore.doc('denied/foo');
|
||||||
|
|
Loading…
Reference in New Issue