Skip to content

Commit

Permalink
test: update tests for new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSolati committed May 29, 2018
1 parent 7303a35 commit 37600fb
Show file tree
Hide file tree
Showing 5 changed files with 553 additions and 541 deletions.
72 changes: 37 additions & 35 deletions test/callbackRegistration.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as firebase from 'firebase';

import { GeoCallbackRegistration } from '../src/callbackRegistration';
import {
afterEachHelper, beforeEachHelper, Checklist,
Expand Down Expand Up @@ -33,20 +35,20 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
it('\'key_moved\' registrations can be cancelled', (done) => {
const cl = new Checklist(['p1', 'p2', 'p3', 'p4', 'p5', 'loc1 moved'], expect, done);

geoFirestoreQueries.push(geoFirestore.query({ center: [1, 2], radius: 1000 }));
geoFirestoreQueries.push(geoFirestore.query({ center: new firebase.firestore.GeoPoint(1, 2), radius: 1000 }));

const onKeyMovedRegistration = geoFirestoreQueries[0].on('key_moved', (key, location, distance) => {
cl.x(key + ' moved');
});

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

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

Expand All @@ -55,7 +57,7 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
onKeyMovedRegistration.cancel();
cl.x('p3');

return geoFirestore.set('loc3', [1, 2]);
return geoFirestore.set('loc3', { coordinates: new firebase.firestore.GeoPoint(1, 2) });
}).then(() => {
cl.x('p4');

Expand All @@ -68,16 +70,16 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
it('\'key_entered\' registrations can be cancelled', (done) => {
const cl = new Checklist(['p1', 'p2', 'p3', 'p4', 'loc1 entered'], expect, done);

geoFirestoreQueries.push(geoFirestore.query({ center: [1, 2], radius: 1000 }));
geoFirestoreQueries.push(geoFirestore.query({ center: new firebase.firestore.GeoPoint(1, 2), radius: 1000 }));

const onKeyEnteredRegistration = geoFirestoreQueries[0].on('key_entered', (key, location, distance) => {
cl.x(key + ' entered');
});

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

Expand All @@ -86,7 +88,7 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
onKeyEnteredRegistration.cancel();
cl.x('p2');

return geoFirestore.set('loc3', [1, 2]);
return geoFirestore.set('loc3', { coordinates: new firebase.firestore.GeoPoint(1, 2) });
}).then(() => {
cl.x('p3');

Expand All @@ -99,29 +101,29 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
it('\'key_exited\' registrations can be cancelled', (done) => {
const cl = new Checklist(['p1', 'p2', 'p3', 'p4', 'p5', 'loc1 exited'], expect, done);

geoFirestoreQueries.push(geoFirestore.query({ center: [1, 2], radius: 1000 }));
geoFirestoreQueries.push(geoFirestore.query({ center: new firebase.firestore.GeoPoint(1, 2), radius: 1000 }));

const onKeyExitedRegistration = geoFirestoreQueries[0].on('key_exited', (key, location, distance) => {
cl.x(key + ' exited');
onKeyExitedRegistration.cancel();
});

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

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

return wait(100);
}).then(() => {
cl.x('p3');

return geoFirestore.set('loc3', [-80, -80]);
return geoFirestore.set('loc3', { coordinates: new firebase.firestore.GeoPoint(-80, -80) });
}).then(() => {
cl.x('p4');

Expand All @@ -134,7 +136,7 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
it('Cancelling a \'key_moved\' registration does not cancel all \'key_moved\' callbacks', (done) => {
const cl = new Checklist(['p1', 'p2', 'p3', 'p4', 'p5', 'loc1 moved1', 'loc1 moved2', 'loc3 moved2'], expect, done);

geoFirestoreQueries.push(geoFirestore.query({ center: [1, 2], radius: 1000 }));
geoFirestoreQueries.push(geoFirestore.query({ center: new firebase.firestore.GeoPoint(1, 2), radius: 1000 }));

const onKeyMovedRegistration1 = geoFirestoreQueries[0].on('key_moved', (key, location, distance) => {
cl.x(key + ' moved1');
Expand All @@ -144,13 +146,13 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
});

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

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

Expand All @@ -159,7 +161,7 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
onKeyMovedRegistration1.cancel();
cl.x('p3');

return geoFirestore.set('loc3', [1, 2]);
return geoFirestore.set('loc3', { coordinates: new firebase.firestore.GeoPoint(1, 2) });
}).then(() => {
cl.x('p4');

Expand All @@ -172,7 +174,7 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
it('Cancelling a \'key_entered\' registration does not cancel all \'key_entered\' callbacks', (done) => {
const cl = new Checklist(['p1', 'p2', 'p3', 'p4', 'loc1 entered1', 'loc1 entered2', 'loc3 entered2'], expect, done);

geoFirestoreQueries.push(geoFirestore.query({ center: [1, 2], radius: 1000 }));
geoFirestoreQueries.push(geoFirestore.query({ center: new firebase.firestore.GeoPoint(1, 2), radius: 1000 }));

const onKeyEnteredRegistration1 = geoFirestoreQueries[0].on('key_entered', (key, location, distance) => {
cl.x(key + ' entered1');
Expand All @@ -182,9 +184,9 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
});

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

Expand All @@ -193,7 +195,7 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
onKeyEnteredRegistration1.cancel();
cl.x('p2');

return geoFirestore.set('loc3', [1, 2]);
return geoFirestore.set('loc3', { coordinates: new firebase.firestore.GeoPoint(1, 2) });
}).then(() => {
cl.x('p3');

Expand All @@ -206,7 +208,7 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
it('Cancelling a \'key_exited\' registration does not cancel all \'key_exited\' callbacks', (done) => {
const cl = new Checklist(['p1', 'p2', 'p3', 'p4', 'p5', 'loc1 exited1', 'loc1 exited2', 'loc3 exited2'], expect, done);

geoFirestoreQueries.push(geoFirestore.query({ center: [1, 2], radius: 1000 }));
geoFirestoreQueries.push(geoFirestore.query({ center: new firebase.firestore.GeoPoint(1, 2), radius: 1000 }));

const onKeyExitedRegistration1 = geoFirestoreQueries[0].on('key_exited', (key, location, distance) => {
cl.x(key + ' exited1');
Expand All @@ -216,13 +218,13 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
});

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

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

Expand All @@ -231,7 +233,7 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
onKeyExitedRegistration1.cancel();
cl.x('p3');

return geoFirestore.set('loc3', [-80, -80]);
return geoFirestore.set('loc3', { coordinates: new firebase.firestore.GeoPoint(-80, -80) });
}).then(() => {
cl.x('p4');

Expand All @@ -242,7 +244,7 @@ describe('GeoFirestore GeoCallbackRegistration Tests:', () => {
});

it('Calling cancel on a GeoCallbackRegistration twice does not throw', () => {
geoFirestoreQueries.push(geoFirestore.query({ center: [1, 2], radius: 1000 }));
geoFirestoreQueries.push(geoFirestore.query({ center: new firebase.firestore.GeoPoint(1, 2), radius: 1000 }));

const onKeyExitedRegistration = geoFirestoreQueries[0].on('key_exited', () => { });

Expand Down
13 changes: 7 additions & 6 deletions test/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as chai from 'chai';
import * as firebase from 'firebase';
import 'firebase/firestore';

import { GeoFirestore } from '../src';
import { GeoFirestoreQuery } from '../src/query';
Expand All @@ -13,12 +12,14 @@ const expect = chai.expect;
export const invalidFirebaseRefs = [null, undefined, NaN, true, false, [], 0, 5, '', 'a', ['hi', 1]];
export const validKeys = ['a', 'loc1', '(e@Xi:4t>*E2)hc<5oa:1s6{B0d?u', Array(700).join('a')];
export const invalidKeys = ['', true, false, null, undefined, { a: 1 }, 'loc.1', 'loc$1', '[loc1', 'loc1]', 'loc#1', 'loc/1', 'a#i]$da[s', 'te/nst', 'te/rst', 'te/u0000st', 'te/u0015st', 'te/007Fst', Array(800).join('a')];
export const validLocations = [[0, 0], [-90, 180], [90, -180], [23, 74], [47.235124363, 127.2379654226]];
export const invalidLocations = [[-91, 0], [91, 0], [0, 181], [0, -181], [[0, 0], 0], ['a', 0], [0, 'a'], ['a', 'a'], [NaN, 0], [0, NaN], [undefined, NaN], [null, 0], [null, null], [0, undefined], [undefined, undefined], '', 'a', true, false, [], [1], {}, { a: 1 }, null, undefined, NaN];
export const validLocations = [new firebase.firestore.GeoPoint(0, 0), new firebase.firestore.GeoPoint(-90, 180), new firebase.firestore.GeoPoint(90, -180), new firebase.firestore.GeoPoint(23, 74), new firebase.firestore.GeoPoint(47.235124363, 127.2379654226)];
// @ts-ignore
export const invalidLocations = [{ latitude: -91, longitude: 0 }, { latitude: 91, longitude: 0 }, { latitude: 0, longitude: 181 }, { latitude: 0, longitude: -181 }, { latitude: [0, 0], longitude: 0 }, { latitude: 'a', longitude: 0 }, { latitude: 0, longitude: 'a' }, { latitude: 'a', longitude: 'a' }, { latitude: NaN, longitude: 0 }, { latitude: 0, longitude: NaN }, { latitude: undefined, longitude: NaN }, { latitude: null, longitude: 0 }, { latitude: null, longitude: null }, { latitude: 0, longitude: undefined }, { latitude: undefined, longitude: undefined }, '', 'a', true, false, [], [1], {}, { a: 1 }, null, undefined, NaN];
export const validGeohashes = ['4', 'd62dtu', '000000000000'];
export const invalidGeohashes = ['', 'aaa', 1, true, false, [], [1], {}, { a: 1 }, null, undefined, NaN];
export const validQueryCriterias = [{ center: [0, 0], radius: 1000 }, { center: [1, -180], radius: 1.78 }, { center: [22.22, -107.77], radius: 0 }, { center: [0, 0] }, { center: [1, -180] }, { center: [22.22, -107.77] }, { radius: 1000 }, { radius: 1.78 }, { radius: 0 }];
export const invalidQueryCriterias = [{}, { random: 100 }, { center: [91, 2], radius: 1000, random: 'a' }, { center: [91, 2], radius: 1000 }, { center: [1, -181], radius: 1000 }, { center: ['a', 2], radius: 1000 }, { center: [1, [1, 2]], radius: 1000 }, { center: [0, 0], radius: -1 }, { center: [null, 2], radius: 1000 }, { center: [1, undefined], radius: 1000 }, { center: [NaN, 0], radius: 1000 }, { center: [1, 2], radius: -10 }, { center: [1, 2], radius: 'text' }, { center: [1, 2], radius: [1, 2] }, { center: [1, 2], radius: null }, true, false, undefined, NaN, [], 'a', 1];
export const validQueryCriterias = [{ center: new firebase.firestore.GeoPoint(0, 0), radius: 1000 }, { center: new firebase.firestore.GeoPoint(1, -180), radius: 1.78 }, { center: new firebase.firestore.GeoPoint(22.22, -107.77), radius: 0 }, { center: new firebase.firestore.GeoPoint(0, 0) }, { center: new firebase.firestore.GeoPoint(1, -180) }, { center: new firebase.firestore.GeoPoint(22.22, -107.77) }, { radius: 1000 }, { radius: 1.78 }, { radius: 0 }];
// @ts-ignore
export const invalidQueryCriterias = [{}, { random: 100 }, { center: { latitude: 91, longitude: 2 }, radius: 1000, random: 'a' }, { center: { latitude: 91, longitude: 2 }, radius: 1000 }, { center: { latitude: 1, longitude: -181 }, radius: 1000 }, { center: { latitude: 'a', longitude: 2 }, radius: 1000 }, { center: { latitude: 1, longitude: [1, 2] }, radius: 1000 }, { center: new firebase.firestore.GeoPoint(0, 0), radius: -1 }, { center: { latitude: null, longitude: 2 }, radius: 1000 }, { center: { latitude: 1, longitude: undefined }, radius: 1000 }, { center: { latitude: NaN, longitude: 0 }, radius: 1000 }, { center: new firebase.firestore.GeoPoint(1, 2), radius: -10 }, { center: new firebase.firestore.GeoPoint(1, 2), radius: 'text' }, { center: new firebase.firestore.GeoPoint(1, 2), radius: [1, 2] }, { center: new firebase.firestore.GeoPoint(1, 2), radius: null }, true, false, undefined, NaN, [], 'a', 1];

// Create global constiables to hold the Firebase and GeoFire constiables
export let geoFirestoreRef: firebase.firestore.CollectionReference,
Expand Down Expand Up @@ -105,7 +106,7 @@ export function Checklist(items, expect, done) {
this.x = function (item) {
const index = eventsToComplete.indexOf(item);
if (index === -1) {
expect('Attempting to delete unexpected item \'' + item + '\' from Checklist').toBeFalsy();
expect('Attempting to delete unexpected item \'' + item + '\' from Checklist').to.be.false;
}
else {
eventsToComplete.splice(index, 1);
Expand Down
Loading

0 comments on commit 37600fb

Please sign in to comment.