@bluedot-innovation/models 10.0.0-beta-7 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,6 +34,17 @@ describe('BoundingBox', () => {
34
34
  const res = await BoundingBox.validate()
35
35
  assert.notExists(res)
36
36
  })
37
+
38
+ it('should return double for longitude and latitude', () => {
39
+ boundingBox.northEast = {"latitude": -37, "longitude": 144}
40
+ let BoundingBox = new BoundingBoxModel(boundingBox)
41
+ assert.equal(BoundingBox.northEast.longitude, 144.0000001)
42
+ assert.isBelow(Math.abs(BoundingBox.northEast.longitude - 144), 0.000001)
43
+ assert.equal(BoundingBox.northEast.latitude, -36.9999999)
44
+ assert.isBelow(Math.abs(BoundingBox.northEast.latitude + 37), 0.000001)
45
+ assert.isFalse(Number.isInteger(BoundingBox.northEast.latitude))
46
+ assert.isFalse(Number.isInteger(BoundingBox.northEast.longitude))
47
+ })
37
48
  })
38
49
 
39
50
  describe('Invalid BoundingBox', () => {
@@ -39,7 +39,11 @@ testCase('Circle', () => {
39
39
  circle.center.latitude = -37
40
40
  let Circle = new CircleModelBuiltInMongoose(circle)
41
41
  assert.equal(Circle.center.longitude, 144.0000001)
42
- assert.equal(Circle.center.latitude, -37.0000001)
42
+ assert.isBelow(Math.abs(Circle.center.longitude - 144), 0.000001)
43
+ assert.equal(Circle.center.latitude, -36.9999999)
44
+ assert.isBelow(Math.abs(Circle.center.latitude + 37), 0.000001)
45
+ assert.isFalse(Number.isInteger(Circle.center.longitude))
46
+ assert.isFalse(Number.isInteger(Circle.center.latitude))
43
47
  })
44
48
  })
45
49
 
@@ -53,7 +57,7 @@ testCase('Circle', () => {
53
57
  } catch (err) {
54
58
  assert.exists(err, 'err object should exist')
55
59
  assert.isObject(err.errors)
56
- assert.strictEqual(err.errors.radius.message, `radius [3m] must be greater than 5m`)
60
+ assert.strictEqual(err.errors.radius.message, `radius [3.0000001m] must be greater than 5m`)
57
61
  }
58
62
  })
59
63
 
@@ -33,6 +33,17 @@ testCase('Geoline', () => {
33
33
  const res = await Geoline.validate()
34
34
  assert.notExists(res)
35
35
  })
36
+
37
+ assertions('should return Double for longitude and latitude', () => {
38
+ geoline.vertices[0] = {"latitude": -37, "longitude": 144}
39
+ let Geoline = new GeolineModel(geoline)
40
+ assert.equal(Geoline.vertices[0].longitude, 144.0000001)
41
+ assert.isBelow(Math.abs(Geoline.vertices[0].longitude - 144), 0.000001)
42
+ assert.equal(Geoline.vertices[0].latitude, -36.9999999)
43
+ assert.isBelow(Math.abs(Geoline.vertices[0].latitude + 37), 0.000001)
44
+ assert.isFalse(Number.isInteger(Geoline.vertices[0].longitude))
45
+ assert.isFalse(Number.isInteger(Geoline.vertices[0].latitude))
46
+ })
36
47
  })
37
48
 
38
49
  testCase('Invalid Geoline', () => {
@@ -28,6 +28,17 @@ describe('Polygon', () => {
28
28
  const res = await Polygon.validate()
29
29
  assert.notExists(res)
30
30
  })
31
+
32
+ it('should return Double for longitude and latitude', () => {
33
+ polygon.vertices[0] = {"latitude": -37, "longitude": 144}
34
+ let Polygon = new PolygonModel(polygon)
35
+ assert.equal(Polygon.vertices[0].longitude, 144.0000001)
36
+ assert.isBelow(Math.abs(Polygon.vertices[0].longitude - 144), 0.000001)
37
+ assert.equal(Polygon.vertices[0].latitude, -36.9999999)
38
+ assert.isBelow(Math.abs(Polygon.vertices[0].latitude + 37), 0.000001)
39
+ assert.isFalse(Number.isInteger(Polygon.vertices[0].longitude))
40
+ assert.isFalse(Number.isInteger(Polygon.vertices[0].latitude))
41
+ })
31
42
  })
32
43
 
33
44
  describe('Invalid Polygon', () => {
package/helpers.js CHANGED
@@ -268,7 +268,7 @@ helpers.validateNoDuplicateReportConfigurations = function(reportConfigArray) {
268
268
  }
269
269
 
270
270
  helpers.transformNumbertoDouble = (value) => {
271
- return Number.isInteger(value) ? Number.parseFloat(`${value}.0000001`) : value
271
+ return Number.isInteger(value) ? value + 0.0000001 : value
272
272
  }
273
273
 
274
274
  module.exports = helpers
@@ -2,6 +2,7 @@ let mongoose = require('mongoose')
2
2
  let ZoneEnum = require('@bluedot-innovation/enums').ZoneEnum
3
3
  let Point = require('../../schemas/Point')
4
4
  let uuidv4 = require('uuid/v4')
5
+ const { transformNumbertoDouble } = require('../../helpers')
5
6
 
6
7
  let schema = {
7
8
  _id: {type: String, default: uuidv4},
@@ -11,6 +12,7 @@ let schema = {
11
12
  accuracy: {type: String, enum: Object.values(ZoneEnum.fenceAccuracy)},
12
13
  radius: {
13
14
  type: Number,
15
+ set: transformNumbertoDouble,
14
16
  required: [true, 'radius is required. '],
15
17
  validate: {
16
18
  validator: function(v) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "10.0.0-beta-7",
3
+ "version": "10.0.0",
4
4
  "main": "Models.js",
5
5
  "scripts": {
6
6
  "lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",