Skip to content

Commit

Permalink
test(GeoFirestore): write better remove function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSolati committed Aug 1, 2018
1 parent da11c3b commit e6b7789
Showing 1 changed file with 11 additions and 163 deletions.
174 changes: 11 additions & 163 deletions test/geofirestore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,108 +1037,8 @@ describe('GeoFirestore Tests:', () => {
}).catch(failTestOnCaughtError);
});

it('set() handles decimal latitudes and longitudes', (done) => {
const cl = new Checklist(['p1', 'p2'], expect, done);

geoFirestore.set({
'loc1': { coordinates: new firebase.firestore.GeoPoint(0.254, 0) },
'loc2': { coordinates: new firebase.firestore.GeoPoint(50, 50.293403) },
'loc3': { coordinates: new firebase.firestore.GeoPoint(-82.614, -90.938) }
}).then(() => {
cl.x('p1');

return getFirestoreData();
}).then((firebaseData) => {
expect(firebaseData).to.deep.equal({
'loc1': { 'l': new firebase.firestore.GeoPoint(0.254, 0), 'g': 'ebpcrypzxv', 'd': { coordinates: new firebase.firestore.GeoPoint(0.254, 0) } },
'loc2': { 'l': new firebase.firestore.GeoPoint(50, 50.293403), 'g': 'v0gu2qnx15', 'd': { coordinates: new firebase.firestore.GeoPoint(50, 50.293403) } },
'loc3': { 'l': new firebase.firestore.GeoPoint(-82.614, -90.938), 'g': '1cr648sfx4', 'd': { coordinates: new firebase.firestore.GeoPoint(-82.614, -90.938) } }
});

cl.x('p2');
}).catch(failTestOnCaughtError);
});

it('set() updates Firebase when changing a pre-existing key', (done) => {
const cl = new Checklist(['p1', 'p2', 'p3'], expect, done);

geoFirestore.set({
'loc1': { coordinates: new firebase.firestore.GeoPoint(0, 0) },
'loc2': { coordinates: new firebase.firestore.GeoPoint(50, 50) },
'loc3': { coordinates: new firebase.firestore.GeoPoint(-90, -90) }
}).then(() => {
cl.x('p1');

return geoFirestore.set({
'loc1': { coordinates: new firebase.firestore.GeoPoint(2, 3) }
});
}).then(() => {
cl.x('p2');

return getFirestoreData();
}).then((firebaseData) => {
expect(firebaseData).to.deep.equal({
'loc1': { 'l': new firebase.firestore.GeoPoint(2, 3), 'g': 's065kk0dc5', 'd': { coordinates: new firebase.firestore.GeoPoint(2, 3) } },
'loc2': { 'l': new firebase.firestore.GeoPoint(50, 50), 'g': 'v0gs3y0zh7', 'd': { coordinates: new firebase.firestore.GeoPoint(50, 50) } },
'loc3': { 'l': new firebase.firestore.GeoPoint(-90, -90), 'g': '1bpbpbpbpb', 'd': { coordinates: new firebase.firestore.GeoPoint(-90, -90) } }
});

cl.x('p3');
}).catch(failTestOnCaughtError);
});

it('set() updates Firebase when changing a pre-existing key to the same location', (done) => {
const cl = new Checklist(['p1', 'p2', 'p3'], expect, done);

geoFirestore.set({
'loc1': { coordinates: new firebase.firestore.GeoPoint(0, 0) },
'loc2': { coordinates: new firebase.firestore.GeoPoint(50, 50) },
'loc3': { coordinates: new firebase.firestore.GeoPoint(-90, -90) }
}).then(() => {
cl.x('p1');

return geoFirestore.set({
'loc1': { coordinates: new firebase.firestore.GeoPoint(0, 0) }
});
}).then(() => {
cl.x('p2');

return getFirestoreData();
}).then((firebaseData) => {
expect(firebaseData).to.deep.equal({
'loc1': { 'l': new firebase.firestore.GeoPoint(0, 0), 'g': '7zzzzzzzzz', 'd': { coordinates: new firebase.firestore.GeoPoint(0, 0) } },
'loc2': { 'l': new firebase.firestore.GeoPoint(50, 50), 'g': 'v0gs3y0zh7', 'd': { coordinates: new firebase.firestore.GeoPoint(50, 50) } },
'loc3': { 'l': new firebase.firestore.GeoPoint(-90, -90), 'g': '1bpbpbpbpb', 'd': { coordinates: new firebase.firestore.GeoPoint(-90, -90) } }
});

cl.x('p3');
}).catch(failTestOnCaughtError);
});

it('set() handles multiple keys at the same location', (done) => {
const cl = new Checklist(['p1', 'p2'], expect, done);

geoFirestore.set({
'loc1': { coordinates: new firebase.firestore.GeoPoint(0, 0) },
'loc2': { coordinates: new firebase.firestore.GeoPoint(0, 0) },
'loc3': { coordinates: new firebase.firestore.GeoPoint(0, 0) }
}).then(() => {
cl.x('p1');

return getFirestoreData();
}).then((firebaseData) => {
expect(firebaseData).to.deep.equal({
'loc1': { 'l': new firebase.firestore.GeoPoint(0, 0), 'g': '7zzzzzzzzz', 'd': { coordinates: new firebase.firestore.GeoPoint(0, 0) } },
'loc2': { 'l': new firebase.firestore.GeoPoint(0, 0), 'g': '7zzzzzzzzz', 'd': { coordinates: new firebase.firestore.GeoPoint(0, 0) } },
'loc3': { 'l': new firebase.firestore.GeoPoint(0, 0), 'g': '7zzzzzzzzz', 'd': { coordinates: new firebase.firestore.GeoPoint(0, 0) } }
});

cl.x('p2');
}).catch(failTestOnCaughtError);
});

it('set() updates Firebase after complex operations', (done) => {
const cl = new Checklist(['p1', 'p2', 'p3', 'p4', 'p5', 'p6'], expect, done);
it('remove() updates Firebase after complex operations', (done) => {
const cl = new Checklist(['p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7'], expect, done);

geoFirestore.set({
'loc:1': { coordinates: new firebase.firestore.GeoPoint(0, 0) },
Expand All @@ -1152,93 +1052,41 @@ describe('GeoFirestore Tests:', () => {
cl.x('p2');

return geoFirestore.set({
'loc2': { coordinates: new firebase.firestore.GeoPoint(0.2358, -72.621) },
'loc3': { coordinates: new firebase.firestore.GeoPoint(0.2358, -72.621) },
'loc4': { coordinates: new firebase.firestore.GeoPoint(87.6, -130) },
'loc5': { coordinates: new firebase.firestore.GeoPoint(5, 55.555) }
});
}).then(() => {
cl.x('p3');

return geoFirestore.set({
'loc5': null
});
return geoFirestore.remove('loc5');
}).then(() => {
cl.x('p4');

return geoFirestore.set({
'loc:1': { coordinates: new firebase.firestore.GeoPoint(87.6, -130) },
'loc2': { coordinates: new firebase.firestore.GeoPoint(0.2358, -72.621) },
'loc%!A72f()3': { coordinates: new firebase.firestore.GeoPoint(-90, -90) },
'loc6': { coordinates: new firebase.firestore.GeoPoint(-72.258, 0.953215) }
});
}).then(() => {
cl.x('p5');

return geoFirestore.set(['loc:1', 'loc3', 'loc6']);
}).then(() => {
cl.x('p6');

return getFirestoreData();
}).then((firebaseData) => {
expect(firebaseData).to.deep.equal({
'loc:1': { 'l': new firebase.firestore.GeoPoint(87.6, -130), 'g': 'cped3g0fur', 'd': { coordinates: new firebase.firestore.GeoPoint(87.6, -130) } },
'loc2': { 'l': new firebase.firestore.GeoPoint(0.2358, -72.621), 'g': 'd2h376zj8h', 'd': { coordinates: new firebase.firestore.GeoPoint(0.2358, -72.621) } },
'loc%!A72f()3': { 'l': new firebase.firestore.GeoPoint(-90, -90), 'g': '1bpbpbpbpb', 'd': { coordinates: new firebase.firestore.GeoPoint(-90, -90) } },
'loc4': { 'l': new firebase.firestore.GeoPoint(87.6, -130), 'g': 'cped3g0fur', 'd': { coordinates: new firebase.firestore.GeoPoint(87.6, -130) } },
'loc6': { 'l': new firebase.firestore.GeoPoint(-72.258, 0.953215), 'g': 'h50svty4es', 'd': { coordinates: new firebase.firestore.GeoPoint(-72.258, 0.953215) } }
'loc4': { 'l': new firebase.firestore.GeoPoint(87.6, -130), 'g': 'cped3g0fur', 'd': { coordinates: new firebase.firestore.GeoPoint(87.6, -130) } }
});

cl.x('p6');
}).catch(failTestOnCaughtError);
});

it('set() does not throw errors given valid keys', () => {
validKeys.forEach((validKey) => {
expect(() => {
const locations = {};
locations[validKey] = { coordinates: new firebase.firestore.GeoPoint(0, 0) };
geoFirestore.set(locations);
}).not.to.throw();
});
});

it('set() throws errors given invalid keys', () => {
invalidKeys.forEach((invalidKey) => {
if (invalidKey !== null && invalidKey !== undefined && typeof invalidKey !== 'boolean') {
expect(() => {
const locations = {};
// @ts-ignore
locations[invalidKey] = { coordinates: new firebase.firestore.GeoPoint(0, 0) };
geoFirestore.set(locations);
}).to.throw();
}
});
});

it('set() throws errors given a location argument in combination with an object', () => {
expect(() => {
geoFirestore.set({
'loc': { coordinates: new firebase.firestore.GeoPoint(0, 0) }
}, { coordinates: new firebase.firestore.GeoPoint(0, 0) });
}).to.throw();
});

it('set() does not throw errors given valid locations', () => {
validLocations.forEach((validLocation) => {
expect(() => {
geoFirestore.set({
'loc': { coordinates: validLocation }
});
}).not.to.throw();
});
});

it('set() throws errors given invalid locations', () => {
invalidLocations.forEach((invalidLocation) => {
// Setting location to null is valid since it will remove the key
if (invalidLocation !== null) {
expect(() => {
geoFirestore.set({
'loc': { coordinates: invalidLocation }
});
}).to.throw(Error, /Invalid GeoFirestore document/);
}
});
});
});

describe('query():', () => {
Expand Down

0 comments on commit e6b7789

Please sign in to comment.