Skip to content

Commit

Permalink
test: update tests and remove settings from GeoFirestore
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSolati committed Nov 26, 2020
1 parent 95858bd commit 4b1bd27
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 112 deletions.
15 changes: 0 additions & 15 deletions src/GeoFirestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,4 @@ export class GeoFirestore {
updateFunction
);
}

/**
* Specifies custom settings to be used to configure the `Firestore`
* instance. Can only be invoked once and before any other Firestore
* method.
*
* If settings are provided via both `settings()` and the `Firestore`
* constructor, both settings objects are merged and any settings provided
* via `settings()` take precedence.
*/
settings(
settings: GeoFirestoreTypes.cloud.Settings | GeoFirestoreTypes.web.Settings
): void {
this._firestore.settings(settings);
}
}
18 changes: 9 additions & 9 deletions test/GeoCollectionReference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ describe('GeoCollectionReference Tests:', () => {
});

it('id will be a sting', () => {
expect(typeof geocollection.id).to.equal('string');
expect(geocollection.id).to.be.string;
});
});

describe('parent:', () => {
it('parent will return null if not a subcollection in a document', () => {
expect(geocollection.parent).to.equal(null);
expect(geocollection.parent).to.be.null;
});

it('parent will return a GeoDocumentReference if a subcollection in a document', () => {
Expand All @@ -86,7 +86,7 @@ describe('GeoCollectionReference Tests:', () => {
.then(doc => {
const subCollection = doc.collection('subcollection');
expect(subCollection.parent).to.be.instanceOf(GeoDocumentReference);
expect(subCollection.parent.isEqual(doc)).to.deep.equal(true);
expect(subCollection.parent.isEqual(doc)).to.be.true;
});
});
});
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('GeoCollectionReference Tests:', () => {
.doc(d1.id)
.get()
.then(d2 => {
expect(d2.exists).to.equal(true);
expect(d2.exists).to.be.true;
});
});
});
Expand All @@ -144,7 +144,7 @@ describe('GeoCollectionReference Tests:', () => {
.doc(d1.id)
.get()
.then(d2 => {
expect(d2.exists).to.equal(true);
expect(d2.exists).to.be.true;
});
});
});
Expand All @@ -163,7 +163,7 @@ describe('GeoCollectionReference Tests:', () => {
.doc(d1.id)
.get()
.then(d2 => {
expect(d2.exists).to.equal(true);
expect(d2.exists).to.be.true;
});
});
});
Expand All @@ -178,7 +178,7 @@ describe('GeoCollectionReference Tests:', () => {
.doc(d1.id)
.get()
.then(d2 => {
expect(d2.exists).to.equal(true);
expect(d2.exists).to.be.true;
});
});
});
Expand All @@ -196,7 +196,7 @@ describe('GeoCollectionReference Tests:', () => {
.doc(d1.id)
.get()
.then(d2 => {
expect(d2.exists).to.equal(true);
expect(d2.exists).to.be.true;
});
});
});
Expand All @@ -217,7 +217,7 @@ describe('GeoCollectionReference Tests:', () => {
expect(geocollection.doc(doc.id)).to.be.instanceOf(
GeoDocumentReference
);
expect(geocollection.doc(doc.id).isEqual(doc)).to.deep.equal(true);
expect(geocollection.doc(doc.id).isEqual(doc)).to.be.true;
});
});
});
Expand Down
43 changes: 19 additions & 24 deletions test/GeoDocumentReference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ describe('GeoDocumentReference Tests:', () => {
.then(() => collection.get())
.then(snapshot => {
snapshot.forEach(doc => {
expect(
typeof new GeoDocumentReference(collection.doc(doc.id)).id
).to.equal('string');
expect(new GeoDocumentReference(collection.doc(doc.id)).id)
.to.be.string;
});
})
.then(done);
Expand Down Expand Up @@ -109,7 +108,7 @@ describe('GeoDocumentReference Tests:', () => {
.then(() => {
const sub = documentReference.onSnapshot(snapshot => {
sub();
expect(snapshot.exists).to.equal(true);
expect(snapshot.exists).to.be.true;
done();
});
});
Expand Down Expand Up @@ -184,12 +183,10 @@ describe('GeoDocumentReference Tests:', () => {
.doc('loc1')
.set({coordinates: new firebase.firestore.GeoPoint(0, 0)})
.then(() => {
expect(
geocollection.doc('loc1').isEqual(geocollection.doc('loc1'))
).to.be.equal(true);
expect(
geocollection.doc('loc1').isEqual(collection.doc('loc1'))
).to.be.equal(true);
expect(geocollection.doc('loc1').isEqual(geocollection.doc('loc1')))
.to.be.true;
expect(geocollection.doc('loc1').isEqual(collection.doc('loc1'))).to
.be.true;
})
.then(done);
});
Expand All @@ -199,12 +196,10 @@ describe('GeoDocumentReference Tests:', () => {
.doc('loc1')
.set({coordinates: new firebase.firestore.GeoPoint(0, 0)})
.then(() => {
expect(
geocollection.doc('loc1').isEqual(geocollection.doc('loc2'))
).to.be.equal(false);
expect(
geocollection.doc('loc1').isEqual(collection.doc('loc2'))
).to.be.equal(false);
expect(geocollection.doc('loc1').isEqual(geocollection.doc('loc2')))
.to.be.false;
expect(geocollection.doc('loc1').isEqual(collection.doc('loc2'))).to
.be.false;
})
.then(done);
});
Expand Down Expand Up @@ -236,7 +231,7 @@ describe('GeoDocumentReference Tests:', () => {
.set({coordinates: new firebase.firestore.GeoPoint(0, 0)})
.then(() => geocollection.doc('loc1').get())
.then(doc => {
expect(doc.exists).to.equal(true);
expect(doc.exists).to.be.true;
})
.then(done);
});
Expand All @@ -263,7 +258,7 @@ describe('GeoDocumentReference Tests:', () => {
.doc(d1.id)
.get()
.then(d2 => {
expect(d2.exists).to.equal(true);
expect(d2.exists).to.be.true;
});
});
});
Expand All @@ -282,7 +277,7 @@ describe('GeoDocumentReference Tests:', () => {
.doc(d1.id)
.get()
.then(d2 => {
expect(d2.exists).to.equal(true);
expect(d2.exists).to.be.true;
});
});
});
Expand Down Expand Up @@ -383,7 +378,7 @@ describe('GeoDocumentReference Tests:', () => {
.set({coordinates: new firebase.firestore.GeoPoint(0, 0)})
.then(() => documentReference.get())
.then(doc => {
expect(doc.exists).to.equal(true);
expect(doc.exists).to.be.true;
expect(doc.data()).to.eql({
g: {
geohash: '7zzzzzzzzz',
Expand All @@ -403,7 +398,7 @@ describe('GeoDocumentReference Tests:', () => {
.set({coordinates: new firebase.firestore.GeoPoint(0, 0)})
.then(() => documentReference.get())
.then(doc => {
expect(doc.exists).to.equal(true);
expect(doc.exists).to.be.true;
expect(doc.data()).to.eql({
g: {
geohash: '7zzzzzzzzz',
Expand All @@ -422,7 +417,7 @@ describe('GeoDocumentReference Tests:', () => {
.set({coordinates: new firebase.firestore.GeoPoint(0, 0)})
.then(() => documentReference.get({source: 'server'}))
.then(doc => {
expect(doc.exists).to.equal(true);
expect(doc.exists).to.be.true;
expect(doc.data()).to.eql({
g: {
geohash: '7zzzzzzzzz',
Expand All @@ -440,8 +435,8 @@ describe('GeoDocumentReference Tests:', () => {
documentReference
.get()
.then(doc => {
expect(doc.exists).to.equal(false);
expect(doc.data()).to.equal(undefined);
expect(doc.exists).to.be.false;
expect(doc.data()).to.be.undefined;
})
.then(done);
});
Expand Down
16 changes: 8 additions & 8 deletions test/GeoDocumentSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('GeoDocumentSnapshot Tests:', () => {
stubDatabase()
.then(() => geocollection.doc('loc0').get())
.then(snapshot => {
expect(snapshot.exists).to.equal(true);
expect(snapshot.exists).to.be.true;
})
.then(done);
});
Expand All @@ -68,7 +68,7 @@ describe('GeoDocumentSnapshot Tests:', () => {
.doc('loc0')
.get()
.then(snapshot => {
expect(snapshot.exists).to.equal(false);
expect(snapshot.exists).to.be.false;
})
.then(done);
});
Expand All @@ -79,7 +79,7 @@ describe('GeoDocumentSnapshot Tests:', () => {
stubDatabase()
.then(() => geocollection.doc('loc0').get())
.then(snapshot => {
expect(typeof snapshot.id === 'string').to.equal(true);
expect(snapshot.id).to.be.string;
})
.then(done);
});
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('GeoDocumentSnapshot Tests:', () => {
.then(snapshot => (geoQuerySnapshot = snapshot))
.then(() => collection.doc('loc0').get())
.then(snapshot => {
expect(geoQuerySnapshot.ref.isEqual(snapshot.ref)).to.equal(true);
expect(geoQuerySnapshot.ref.isEqual(snapshot.ref)).to.be.true;
})
.then(done);
});
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('GeoDocumentSnapshot Tests:', () => {
stubDatabase()
.then(() => geocollection.doc('loc0').get())
.then(snapshot => {
expect(snapshot.isEqual(snapshot['_snapshot'])).to.equal(true);
expect(snapshot.isEqual(snapshot['_snapshot'])).to.be.true;
})
.then(done);
});
Expand All @@ -211,7 +211,7 @@ describe('GeoDocumentSnapshot Tests:', () => {
stubDatabase()
.then(() => geocollection.doc('loc0').get())
.then(snapshot => {
expect(snapshot.isEqual(snapshot)).to.equal(true);
expect(snapshot.isEqual(snapshot)).to.be.true;
})
.then(done);
});
Expand All @@ -223,7 +223,7 @@ describe('GeoDocumentSnapshot Tests:', () => {
.then(snapshot => (snapshotDoc0 = snapshot))
.then(() => collection.doc('loc1').get())
.then(snapshot => {
expect(snapshotDoc0.isEqual(snapshot)).to.equal(false);
expect(snapshotDoc0.isEqual(snapshot)).to.be.false;
})
.then(done);
});
Expand All @@ -235,7 +235,7 @@ describe('GeoDocumentSnapshot Tests:', () => {
.then(snapshot => (snapshotDoc0 = snapshot))
.then(() => geocollection.doc('loc1').get())
.then(snapshot => {
expect(snapshotDoc0.isEqual(snapshot)).to.equal(false);
expect(snapshotDoc0.isEqual(snapshot)).to.be.false;
})
.then(done);
});
Expand Down
14 changes: 5 additions & 9 deletions test/GeoFirestore.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as chai from 'chai';
import firebase from 'firebase/app';

import {GeoFirestore} from '../src';
import {
Expand Down Expand Up @@ -46,9 +47,10 @@ describe('GeoFirestore Tests:', () => {

describe('batch():', () => {
it('batch() returns a new GeoWriteBatch based on a Firestore WriteBatch', () => {
expect(new GeoFirestore(firestore).batch().native).to.deep.equal(
firestore.batch()
);
expect(
new GeoFirestore(firestore).batch().native instanceof
firebase.firestore.WriteBatch
).to.be.true;
});
});

Expand Down Expand Up @@ -87,10 +89,4 @@ describe('GeoFirestore Tests:', () => {
geofirestore.runTransaction(() => Math as any).catch(() => done());
});
});

describe('settings:', () => {
it("settings() does't throw errors given valid Firestore Settings", () => {
expect(() => new GeoFirestore(firestore).settings({})).not.to.throw();
});
});
});
8 changes: 4 additions & 4 deletions test/GeoQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('GeoQuery Tests:', () => {
.near({center, radius: 1})
.onSnapshot(snapshot => {
subscription();
expect(snapshot.empty).to.equal(true);
expect(snapshot.empty).to.be.true;
done();
});
});
Expand Down Expand Up @@ -199,15 +199,15 @@ describe('GeoQuery Tests:', () => {
.onSnapshot(snapshot => {
if (!runOnce) {
runOnce = true;
expect(snapshot.empty).to.equal(false);
expect(snapshot.empty).to.be.false;
expect(snapshot.docChanges().length).to.equal(1);
expect(snapshot.docChanges()[0].type).to.equal('added');
setTimeout(() => {
geocollection.doc('loc0').delete();
}, 100);
} else {
subscription();
expect(snapshot.empty).to.equal(true);
expect(snapshot.empty).to.be.true;
expect(snapshot.docChanges().length).to.equal(1);
expect(snapshot.docChanges()[0].type).to.equal('removed');
done();
Expand Down Expand Up @@ -565,7 +565,7 @@ describe('GeoQuery Tests:', () => {
const query = new GeoQuery(collection);
// eslint-disable-next-line
// @ts-ignore
expect(() => query.where('count', 'as', 12)).to.throw();
expect(() => query.where('count', 'as', 12).then(() => null)).to.throw();
});
});

Expand Down
Loading

0 comments on commit 4b1bd27

Please sign in to comment.