@bluedot-innovation/models 7.17.0 → 7.18.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 7.18.0
2
+ - Add wait time goals to destination
3
+
1
4
  ## 7.17.0
2
5
  - Upgrade mongoose version to support MongoDB 5.0
3
6
 
@@ -10,5 +10,9 @@
10
10
  "latitude": -37.8159544565362,
11
11
  "longitude": 144.9723565578461
12
12
  },
13
- "address": "48 Pirrama Rd, Pyrmont NSW 2009, Australia"
13
+ "address": "48 Pirrama Rd, Pyrmont NSW 2009, Australia",
14
+ "waitTime": {
15
+ "goal": 300,
16
+ "alert": 240
17
+ }
14
18
  }
@@ -48,6 +48,16 @@ describe('Valid Destination ', () => {
48
48
  done()
49
49
  })
50
50
  })
51
+
52
+ it('should validate a valid destination without wait time goals', (done) => {
53
+ delete destination.waitTime
54
+ let Destination = new DestinationModel(destination)
55
+ Destination.validate((err, res) => {
56
+ assert.notExists(res)
57
+ assert(err === null, 'err equals null')
58
+ done()
59
+ })
60
+ })
51
61
  })
52
62
 
53
63
  describe('Invalid Destination ', () => {
@@ -154,4 +164,28 @@ describe('Invalid Destination ', () => {
154
164
  done()
155
165
  })
156
166
  })
167
+
168
+ it("should throw an error if wait time alert is greater than goal", (done) => {
169
+ destination.waitTime.alert = 600
170
+ let Destination = new DestinationModel(destination)
171
+ Destination.validate((err, res) => {
172
+ assert.notExists(res)
173
+ assert.exists(err)
174
+ console.log(err.message)
175
+ assert.match(err.message, /alert must be less than the goal value/)
176
+ done()
177
+ })
178
+ })
179
+
180
+ it("should throw an error if alert is not a number", (done) => {
181
+ destination.waitTime.alert = "Twelve"
182
+ let Destination = new DestinationModel(destination)
183
+ Destination.validate((err, res) => {
184
+ assert.notExists(res)
185
+ assert.exists(err)
186
+ console.log(err.message)
187
+ assert.match(err.message, /Cast to Number failed for value "Twelve" \(type string\) at path "alert"/)
188
+ done()
189
+ })
190
+ })
157
191
  })
@@ -2,6 +2,7 @@ const mongoose = require('mongoose')
2
2
  const uuidv4 = require('uuid/v4')
3
3
  const patcher = require('@bluedot-innovation/mongoose-json-patch')
4
4
  const Point = require('../schemas/Point')
5
+ const WaitTime = require('../schemas/WaitTime')
5
6
  const helpers = require('../helpers')
6
7
 
7
8
  const DestinationSchema = new mongoose.Schema({
@@ -16,6 +17,7 @@ const DestinationSchema = new mongoose.Schema({
16
17
  projectId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, msg: 'Invalid projectId'}},
17
18
  creationTime: {type: Date, default: Date.now},
18
19
  lastUpdateTime: {type: Date, default: Date.now},
20
+ waitTime: { type: WaitTime }
19
21
  }, {collection: 'destination'})
20
22
 
21
23
  DestinationSchema.plugin(patcher)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "7.17.0",
3
+ "version": "7.18.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",
@@ -0,0 +1,13 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ function validateAlertLessThanGoal(alert){
4
+ return alert < this.goal
5
+ }
6
+ const WaitTimeSchema = new mongoose.Schema({
7
+ alert: { type: Number, required: true, validate: { validator: validateAlertLessThanGoal, msg: "alert must be less than the goal value" } },
8
+ goal: { type: Number, required: true }
9
+ }, {
10
+ _id: false
11
+ })
12
+
13
+ module.exports = WaitTimeSchema