@bluedot-innovation/models 2.0.16-alpha.1 → 2.0.17-alpha.1

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.
package/.eslintrc.js CHANGED
@@ -1,6 +1,42 @@
1
1
  module.exports = {
2
- "extends": "standard",
2
+ "extends" : [
3
+ "prettier"
4
+ ],
5
+ "plugins": [
6
+ "prettier"
7
+ ],
8
+ "parser": "babel-eslint",
9
+ "parserOptions": {
10
+ "ecmaVersion": 2015,
11
+ "sourceType": "module",
12
+ "ecmaFeatures": {
13
+ "jsx": true
14
+ }
15
+ },
3
16
  "rules": {
4
- "indent": ["error", 4]
17
+ "indent": [
18
+ 2,
19
+ 4,
20
+ {"SwitchCase": 1}
21
+ ],
22
+ "no-underscore-dangle": 0,
23
+ "import/prefer-default-export": false,
24
+ "arrow-body-style": 0
25
+ },
26
+ "env": {
27
+ "es6": true,
28
+ "browser": true,
29
+ "node": true,
30
+ "jest": true
31
+ },
32
+ "settings": {
33
+ "import/resolver": {
34
+ "webpack": {
35
+ "config": "./webpack.config.js"
36
+ }
37
+ }
38
+ },
39
+ "globals": {
40
+ "google": true
5
41
  }
6
- };
42
+ }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.0.17
2
+ - Tag model added
3
+
1
4
  ## 2.0.16
2
5
  - Don't enforce in `CalendarDateRangeFilter` that `endDate` is later than current date.
3
6
 
@@ -92,7 +92,7 @@ describe('BearingFilter', () => {
92
92
  })
93
93
  })
94
94
 
95
- describe.only('isMinimumNinetyApart(fromAngle, toAngle)', () => {
95
+ describe('isMinimumNinetyApart(fromAngle, toAngle)', () => {
96
96
  describe('should return true if the angles are at least 90 degrees apart in both directions', () => {
97
97
  const angles = [
98
98
  [360, 90],
@@ -0,0 +1,7 @@
1
+ const mocha = require('mocha')
2
+ global.mongoose = require('mongoose')
3
+ global.mongoose.Promise = global.Promise
4
+ global.describe = mocha.describe
5
+ global.it = mocha.it
6
+ global.assert = require('chai').assert
7
+ global.beforeEach = mocha.beforeEach
@@ -1,15 +1,5 @@
1
- let mongoose = require('mongoose')
2
-
3
- mongoose.Promise = global.Promise
4
-
5
1
  let ZoneModel = require('../../Models').Zone(mongoose)
6
2
  let ZoneModelBuiltInMongoose = require('../../Models').Zone()
7
- let testCase = require('mocha').describe
8
- let assertions = require('mocha').it
9
- let chai = require('chai')
10
- let assert = chai.assert
11
- let mocha = require('mocha')
12
- let beforeEach = mocha.beforeEach
13
3
 
14
4
  let zone
15
5
 
@@ -17,9 +7,9 @@ beforeEach(() => {
17
7
  zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
18
8
  })
19
9
 
20
- testCase('Zone', () => {
21
- testCase('Valid Zone ', () => {
22
- assertions('should validate a valid zone ', (done) => {
10
+ describe('Zone', () => {
11
+ describe('Valid Zone ', () => {
12
+ it('should validate a valid zone ', (done) => {
23
13
  let Zone = new ZoneModel(zone)
24
14
  Zone.validate((err, res) => {
25
15
  assert.notExists(res)
@@ -27,7 +17,8 @@ testCase('Zone', () => {
27
17
  done()
28
18
  })
29
19
  })
30
- assertions('should validate a valid zone ', (done) => {
20
+
21
+ it('should validate a valid zone ', (done) => {
31
22
  let Zone = new ZoneModelBuiltInMongoose(zone)
32
23
  Zone.validate((err, res) => {
33
24
  assert.notExists(res)
@@ -35,7 +26,8 @@ testCase('Zone', () => {
35
26
  done()
36
27
  })
37
28
  })
38
- assertions('should instantiate a circle', (done) => {
29
+
30
+ it('should instantiate a circle', (done) => {
39
31
  zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^circle$/))
40
32
  let Zone = new ZoneModel(zone)
41
33
  Zone.validate((err, res) => {
@@ -44,7 +36,8 @@ testCase('Zone', () => {
44
36
  done()
45
37
  })
46
38
  })
47
- assertions('should instantiate a bounding box', (done) => {
39
+
40
+ it('should instantiate a bounding box', (done) => {
48
41
  zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^boundingBox$/))
49
42
  let Zone = new ZoneModel(zone)
50
43
  Zone.validate((err, res) => {
@@ -53,7 +46,8 @@ testCase('Zone', () => {
53
46
  done()
54
47
  })
55
48
  })
56
- assertions('should instantiate a polygon', (done) => {
49
+
50
+ it('should instantiate a polygon', (done) => {
57
51
  zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polygon$/))
58
52
  let Zone = new ZoneModel(zone)
59
53
  Zone.validate((err, res) => {
@@ -62,7 +56,8 @@ testCase('Zone', () => {
62
56
  done()
63
57
  })
64
58
  })
65
- assertions('should instantiate a polyline', (done) => {
59
+
60
+ it('should instantiate a polyline', (done) => {
66
61
  zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polyline$/))
67
62
  let Zone = new ZoneModel(zone)
68
63
  Zone.validate((err, res) => {
@@ -73,8 +68,8 @@ testCase('Zone', () => {
73
68
  })
74
69
  })
75
70
 
76
- testCase('Invalid Zone ', () => {
77
- assertions('should throw an error when validating an invalid zone ', (done) => {
71
+ describe('Invalid Zone ', () => {
72
+ it('should throw an error when validating an invalid zone ', (done) => {
78
73
  delete zone.name
79
74
  let Zone = new ZoneModel(zone)
80
75
  Zone.validate((err, res) => {
@@ -83,7 +78,8 @@ testCase('Zone', () => {
83
78
  done()
84
79
  })
85
80
  })
86
- assertions('should throw an error when action is invalid', (done) => {
81
+
82
+ it('should throw an error when action is invalid', (done) => {
87
83
  delete zone.actions[1].url
88
84
  let Zone = new ZoneModel(zone)
89
85
  Zone.validate((err, res) => {
@@ -93,7 +89,8 @@ testCase('Zone', () => {
93
89
  done()
94
90
  })
95
91
  })
96
- assertions('should throw an error when a filter is invalid', (done) => {
92
+
93
+ it('should throw an error when a filter is invalid', (done) => {
97
94
  zone.filters[0].startDate = 'abc'
98
95
  let Zone = new ZoneModel(zone)
99
96
  Zone.validate((err, res) => {
package/models/Zone.js CHANGED
@@ -36,7 +36,7 @@ let filterSchema = new Schema({},
36
36
  let geofeatureSchema = new Schema({},
37
37
  { discriminatorKey: 'type', _id: false })
38
38
 
39
- let ZoneSchema = new Schema({
39
+ let zoneSchema = new Schema({
40
40
  _id: {type: String, default: uuidv4},
41
41
  name: {type: String, required: [true, 'name is required']},
42
42
  minimumRetriggerTime: {
@@ -49,6 +49,7 @@ let ZoneSchema = new Schema({
49
49
  message: '{VALUE} is not a number'
50
50
  }
51
51
  },
52
+ tags: {type: [String]},
52
53
  filters: {
53
54
  type: [filterSchema]
54
55
  },
@@ -69,33 +70,33 @@ let ZoneSchema = new Schema({
69
70
  }, {collection: 'zone'})
70
71
 
71
72
  // TODO: Test patcher and include for other schemas if required
72
- ZoneSchema.plugin(patcher)
73
+ zoneSchema.plugin(patcher)
73
74
 
74
- ZoneSchema.path('actions').discriminator('url', new Schema(urlActionSchema))
75
- ZoneSchema.path('actions').discriminator('message', new Schema(messageActionSchema))
75
+ zoneSchema.path('actions').discriminator('url', new Schema(urlActionSchema))
76
+ zoneSchema.path('actions').discriminator('message', new Schema(messageActionSchema))
76
77
 
77
- ZoneSchema.path('filters').discriminator('bearing', new Schema(bearingFilterSchema))
78
- ZoneSchema.path('filters').discriminator('calendarDateRange', new Schema(calendarDateRangeFilterSchema))
79
- ZoneSchema.path('filters').discriminator('percentageCrossed', new Schema(percentageCrossedFilterSchema))
80
- ZoneSchema.path('filters').discriminator('speed', new Schema(speedFilterSchema))
81
- ZoneSchema.path('filters').discriminator('timeOfDayRange', new Schema(timeOfDayRangeFilterSchema))
78
+ zoneSchema.path('filters').discriminator('bearing', new Schema(bearingFilterSchema))
79
+ zoneSchema.path('filters').discriminator('calendarDateRange', new Schema(calendarDateRangeFilterSchema))
80
+ zoneSchema.path('filters').discriminator('percentageCrossed', new Schema(percentageCrossedFilterSchema))
81
+ zoneSchema.path('filters').discriminator('speed', new Schema(speedFilterSchema))
82
+ zoneSchema.path('filters').discriminator('timeOfDayRange', new Schema(timeOfDayRangeFilterSchema))
82
83
 
83
- ZoneSchema.path('geofeatures').discriminator('beacon', new Schema(beaconSchema))
84
- ZoneSchema.path('geofeatures').discriminator('circle', new Schema(circleSchema))
85
- ZoneSchema.path('geofeatures').discriminator('polygon', new Schema(polygonSchema))
86
- ZoneSchema.path('geofeatures').discriminator('polyline', new Schema(polylineSchema))
87
- ZoneSchema.path('geofeatures').discriminator('boundingBox', new Schema(boundingBoxSchema))
84
+ zoneSchema.path('geofeatures').discriminator('beacon', new Schema(beaconSchema))
85
+ zoneSchema.path('geofeatures').discriminator('circle', new Schema(circleSchema))
86
+ zoneSchema.path('geofeatures').discriminator('polygon', new Schema(polygonSchema))
87
+ zoneSchema.path('geofeatures').discriminator('polyline', new Schema(polylineSchema))
88
+ zoneSchema.path('geofeatures').discriminator('boundingBox', new Schema(boundingBoxSchema))
88
89
 
89
90
  // optional mongoose
90
91
  const model = (mongooseInstance) => {
91
92
  let Zone
92
93
  if (mongooseInstance) {
93
- Zone = mongooseInstance.model('Zone', ZoneSchema)
94
+ Zone = mongooseInstance.model('Zone', zoneSchema)
94
95
  } else {
95
- Zone = mongoose.model('Zone', ZoneSchema)
96
+ Zone = mongoose.model('Zone', zoneSchema)
96
97
  }
97
98
 
98
99
  return Zone
99
100
  }
100
101
 
101
- module.exports = { Model: model, Schema: ZoneSchema }
102
+ module.exports = { Model: model, Schema: zoneSchema }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "2.0.16-alpha.1",
3
+ "version": "2.0.17-alpha.1",
4
4
  "description": "",
5
5
  "main": "Models.js",
6
6
  "scripts": {
7
7
  "lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",
8
- "test": "mocha __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
8
+ "test": "mocha --require __tests__/setup __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
9
9
  "test:coverage": "nyc mocha __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
10
10
  "test:coverage-check": "nyc check-coverage --lines 90 --functions 90 --branches 70",
11
11
  "test:ci": "npm run lint && npm run test:coverage-check && npm test"
@@ -13,24 +13,30 @@
13
13
  "author": "",
14
14
  "license": "UNLICENSED",
15
15
  "devDependencies": {
16
+ "babel-eslint": "^8.2.3",
16
17
  "chai": "^4.1.2",
17
18
  "describe": "*",
18
19
  "eslint": "^4.12.0",
20
+ "eslint-config-prettier": "^2.9.0",
19
21
  "eslint-config-standard": "^10.2.1",
20
22
  "eslint-plugin-import": "^2.8.0",
21
23
  "eslint-plugin-node": "^5.2.1",
24
+ "eslint-plugin-prettier": "^2.6.0",
22
25
  "eslint-plugin-promise": "^3.6.0",
23
26
  "eslint-plugin-standard": "^3.0.1",
24
27
  "mocha": "^4.0.1",
25
28
  "nyc": "^11.3.0",
29
+ "prettier": "^1.13.5",
26
30
  "sinon": "^4.1.2"
27
31
  },
28
32
  "dependencies": {
29
33
  "@bluedot-innovation/enums": "2.0.2",
34
+ "i": "^0.3.6",
30
35
  "lodash.clonedeep": "4.5.0",
31
36
  "mongoose": "^4.13.9",
32
37
  "mongoose-error-helper": "0.0.2",
33
38
  "mongoose-json-patch": "^1.1.1",
39
+ "npm": "^6.1.0",
34
40
  "uuid": "^3.1.0"
35
41
  }
36
42
  }