Add geo point tests
This commit is contained in:
parent
d51cf6e23d
commit
9dab0896f0
12
README.md
12
README.md
|
@ -689,7 +689,11 @@ Include the connector in your package.json dependencies and run `npm install`.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
### GeoPoint TODO
|
### GeoPoint
|
||||||
|
|
||||||
|
Use the `GeoPoint` class.
|
||||||
|
|
||||||
|
var GeoPoint = require('asteroid').GeoPoint;
|
||||||
|
|
||||||
Embed a latitude / longitude point in a [Model](#model).
|
Embed a latitude / longitude point in a [Model](#model).
|
||||||
|
|
||||||
|
@ -723,9 +727,15 @@ Get the distance between two points.
|
||||||
|
|
||||||
#### Distance Types
|
#### Distance Types
|
||||||
|
|
||||||
|
**Note:** all distance methods use `miles` by default.
|
||||||
|
|
||||||
- `miles`
|
- `miles`
|
||||||
- `radians`
|
- `radians`
|
||||||
- `kilometers`
|
- `kilometers`
|
||||||
|
- `meters`
|
||||||
|
- `miles`
|
||||||
|
- `feet`
|
||||||
|
- `degrees`
|
||||||
|
|
||||||
#### geoPoint.lat
|
#### geoPoint.lat
|
||||||
|
|
||||||
|
|
2
index.js
2
index.js
|
@ -15,4 +15,4 @@ asteroid.Memory = require('./lib/connectors/memory');
|
||||||
* Types
|
* Types
|
||||||
*/
|
*/
|
||||||
|
|
||||||
asteroid.GeoPoint = require('./lib/geo-point');
|
asteroid.GeoPoint = require('jugglingdb/lib/geo').GeoPoint;
|
|
@ -1,18 +0,0 @@
|
||||||
/**
|
|
||||||
* Export the `GeoPoint` class.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = GeoPoint;
|
|
||||||
|
|
||||||
function GeoPoint(data) {
|
|
||||||
if(!(this instanceof GeoPoint)) {
|
|
||||||
return new GeoPoint(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.lat = data.lat;
|
|
||||||
this.lng = data.lng;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO remove this
|
|
||||||
// register the type
|
|
||||||
require('jugglingdb/lib/model-builder').ModelBuilder.registerType(GeoPoint);
|
|
|
@ -1,41 +1,19 @@
|
||||||
// describe('GeoPoint', function() {
|
describe('GeoPoint', function() {
|
||||||
//
|
describe('geoPoint.distanceTo(geoPoint, options)', function() {
|
||||||
// describe('geoPoint.distanceTo(geoPoint, options)', function() {
|
it("Get the distance to another `GeoPoint`.", function() {
|
||||||
// it("Get the distance to another `GeoPoint`.", function(done) {
|
var here = new GeoPoint({lat: 10, lng: 10});
|
||||||
// /* example -
|
var there = new GeoPoint({lat: 5, lng: 5});
|
||||||
// var here = new GeoPoint({lat: 10, long: 10});
|
|
||||||
// var there = new GeoPoint({lat: 5, long: 5});
|
assert.equal(here.distanceTo(there, {type: 'meters'}), 782777.923052584);
|
||||||
// console.log(here.distanceTo(there, {type: 'miles'})); // 438
|
});
|
||||||
// */
|
});
|
||||||
// done(new Error('test not implemented'));
|
|
||||||
// });
|
describe('GeoPoint.distanceBetween(a, b, options)', function() {
|
||||||
// });
|
it("Get the distance between two points.", function() {
|
||||||
//
|
var here = new GeoPoint({lat: 10, lng: 10});
|
||||||
// describe('GeoPoint.distanceBetween(a, b, options)', function() {
|
var there = new GeoPoint({lat: 5, lng: 5});
|
||||||
// it("Get the distance between two points.", function(done) {
|
|
||||||
// /* example -
|
assert.equal(GeoPoint.distanceBetween(here, there, {type: 'feet'}), 2568169.038886431);
|
||||||
// GeoPoint.distanceBetween(here, there, {type: 'miles'}) // 438
|
});
|
||||||
// */
|
});
|
||||||
// done(new Error('test not implemented'));
|
});
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// describe('geoPoint.lat', function() {
|
|
||||||
// it("The latitude point in degrees", function(done) {
|
|
||||||
// done(new Error('test not implemented'));
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// describe('geoPoint.long', function() {
|
|
||||||
// it("The longitude point in degrees", function(done) {
|
|
||||||
// /* example -
|
|
||||||
// app.use(asteroid.rest());
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// app.use(asteroid.sio);
|
|
||||||
//
|
|
||||||
// */
|
|
||||||
// done(new Error('test not implemented'));
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// });
|
|
|
@ -5,6 +5,7 @@
|
||||||
assert = require('assert');
|
assert = require('assert');
|
||||||
asteroid = require('../');
|
asteroid = require('../');
|
||||||
memoryConnector = asteroid.Memory;
|
memoryConnector = asteroid.Memory;
|
||||||
|
GeoPoint = asteroid.GeoPoint;
|
||||||
app = null;
|
app = null;
|
||||||
TaskEmitter = require('sl-task-emitter');
|
TaskEmitter = require('sl-task-emitter');
|
||||||
request = require('supertest');
|
request = require('supertest');
|
||||||
|
|
Loading…
Reference in New Issue