@bluedot-innovation/models 7.18.1 → 8.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 8.0.0
2
+ - BREAKING CHANGE - remove Zone actions
3
+
4
+ ## 7.18.2
5
+ - make clientId in Incentivio integration mandatory
6
+
1
7
  ## 7.18.1
2
8
  - Add Incentivio integration to Project
3
9
 
package/Models.js CHANGED
@@ -7,9 +7,7 @@ let Models = {}
7
7
 
8
8
  Models.Account = require('./models/Account').Model
9
9
  Models.Destination = require('./models/Destination').Model
10
- Models.MessageAction = require('./models/MessageAction').Model
11
10
  Models.Project = require('./models/Project').Model
12
- Models.UrlAction = require('./models/UrlAction').Model
13
11
  Models.User = require('./models/User').Model
14
12
  Models.Zone = require('./models/Zone').Model
15
13
 
@@ -48,10 +46,8 @@ let Schemas = {}
48
46
 
49
47
  Schemas.Account = require('./models/Account').Schema
50
48
  Schemas.Destination = require('./models/Destination').Schema
51
- Schemas.MessageAction = require('./models/MessageAction').Schema
52
49
  Schemas.Application = require('./models/Application').Schema
53
50
  Schemas.Project = require('./models/Project').Schema
54
- Schemas.UrlAction = require('./models/UrlAction').Schema
55
51
  Schemas.User = require('./models/User').Schema
56
52
  Schemas.Zone = require('./models/Zone').Schema
57
53
 
@@ -620,6 +620,28 @@ describe('Project', () => {
620
620
  })
621
621
  })
622
622
  })
623
+
624
+ describe("Incentivio integration validation", () => {
625
+ it('should throw an error when clientId is missing', (done) => {
626
+ delete project.integrations.incentivio.clientId
627
+ let Project = new ProjectModel(project)
628
+ Project.validate((err, res) => {
629
+ assert.exists(err)
630
+ assert.match(err.message, /`clientId` is required/)
631
+ done()
632
+ })
633
+ })
634
+
635
+ it('should throw an error when nowReadyEnabled is non boolean', (done) => {
636
+ project.integrations.incentivio.nowReadyEnabled = "invalid"
637
+ let Project = new ProjectModel(project)
638
+ Project.validate((err, res) => {
639
+ assert.exists(err)
640
+ assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "nowReadyEnabled"/)
641
+ done()
642
+ })
643
+ })
644
+ })
623
645
  })
624
646
 
625
647
  describe('should throw an error when any of the values of the array contains a falsy value', () => {
@@ -1,4 +1,3 @@
1
1
  {
2
- "arrayTypeFields": ["geofeatures", "conditions", "actions"]
2
+ "arrayTypeFields": ["geofeatures", "conditions"]
3
3
  }
4
-
@@ -131,51 +131,6 @@ describe('Zone', () => {
131
131
  })
132
132
  })
133
133
 
134
- it('should throw an error when action is invalid', (done) => {
135
- delete zone.actions[1].url
136
- let Zone = new ZoneModel(zone)
137
- Zone.validate((err, res) => {
138
- assert.exists(err, 'err object should exist')
139
- assert.isObject(err.errors)
140
- assert('actions.1.url' in err.errors, `errors should have a 'actions.1.url' property`)
141
- done()
142
- })
143
- })
144
-
145
- it('should throw an error when action type is missing', (done) => {
146
- delete zone.actions[0].type
147
- delete zone.actions[1].type
148
- let Zone = new ZoneModel(zone)
149
- Zone.validate((err, res) => {
150
- assert.exists(err, 'err object should exist')
151
- assert.isObject(err.errors)
152
- assert.match(err.message, /(Action requires a type of `url` or `message`.)/i)
153
- done()
154
- })
155
- })
156
-
157
- it('should throw an error when action object is empty', (done) => {
158
- zone.actions = [{}]
159
- let Zone = new ZoneModel(zone)
160
- Zone.validate((err, res) => {
161
- assert.exists(err, 'err object should exist')
162
- assert.isObject(err.errors)
163
- assert.match(err.message, /(Action requires a type of `url` or `message`.)/i)
164
- done()
165
- })
166
- })
167
-
168
- it('should throw an error when actions is null', (done) => {
169
- zone.actions = null
170
- let Zone = new ZoneModel(zone)
171
- Zone.validate((err, res) => {
172
- assert.exists(err, 'err object should exist')
173
- assert.isObject(err.errors)
174
- assert.match(err.message, /(actions must have a value)/i)
175
- done()
176
- })
177
- })
178
-
179
134
  it('should throw an error when a condition is invalid', (done) => {
180
135
  zone.conditions[0].startDate = 'abc'
181
136
  let Zone = new ZoneModel(zone)
package/models/Zone.js CHANGED
@@ -7,8 +7,6 @@
7
7
  let mongoose = require('mongoose')
8
8
  let Schema = mongoose.Schema
9
9
  let StateEnum = require('@bluedot-innovation/enums').StateEnum
10
- let messageActionSchema = require('./MessageAction').messageActionSchema
11
- let urlActionSchema = require('./UrlAction').urlActionSchema
12
10
  let circleSchema = require('./geofeatures/Circle').circleSchema
13
11
  let boundingBoxSchema = require('./geofeatures/BoundingBox').boundingBoxSchema
14
12
  let geolineSchema = require('./geofeatures/Geoline').geolineSchema
@@ -42,16 +40,6 @@ const tagsFormation = (zone) => {
42
40
  }
43
41
  }
44
42
 
45
- let actionSchema = new Schema({},
46
- { discriminatorKey: 'type', _id: false })
47
-
48
- actionSchema.pre('validate', function(next){
49
- if(this.type === undefined){
50
- return next(new Error('Action requires a type of `url` or `message`.'))
51
- }
52
- next()
53
- })
54
-
55
43
  let conditionSchema = new Schema({},
56
44
  { discriminatorKey: 'type', _id: false })
57
45
 
@@ -96,13 +84,6 @@ let zoneSchema = new Schema({
96
84
  message: 'conditions must have a value'
97
85
  }
98
86
  },
99
- actions: {
100
- type: [actionSchema],
101
- validate: {
102
- validator: helpers.validateNotNull,
103
- message: 'actions must have a value'
104
- }
105
- },
106
87
  geofeatures: {
107
88
  type: [geofeatureSchema],
108
89
  required: true,
@@ -125,9 +106,6 @@ let zoneSchema = new Schema({
125
106
  // plugin for PATCH operations
126
107
  zoneSchema.plugin(patcher)
127
108
 
128
- zoneSchema.path('actions').discriminator('url', new Schema(urlActionSchema, {_id: false}))
129
- zoneSchema.path('actions').discriminator('message', new Schema(messageActionSchema, {_id: false}))
130
-
131
109
  zoneSchema.path('conditions').discriminator('dayRange', new Schema(dayRangeRawSchema, {_id: false}))
132
110
  zoneSchema.path('conditions').discriminator('speed', new Schema(speedRawSchema, {_id: false}))
133
111
  zoneSchema.path('conditions').discriminator('timeActive', new Schema(timeActiveRawSchema, {_id: false}))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "7.18.1",
3
+ "version": "8.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",
@@ -2,7 +2,7 @@ const mongoose = require('mongoose');
2
2
 
3
3
  let IncentivioIntegrationSchema = new mongoose.Schema({
4
4
  nowReadyEnabled: {type: Boolean, default: true},
5
- clientId: {type: String},
5
+ clientId: {type: String, required: true},
6
6
  lastSyncedTime: {type: Date}
7
7
  }, {
8
8
  _id: false
@@ -1,5 +0,0 @@
1
- {
2
- "type": "message",
3
- "message": "hello",
4
- "title": "hello"
5
- }
@@ -1,3 +0,0 @@
1
- {
2
- "requiredFields":["message", "title"]
3
- }
@@ -1,73 +0,0 @@
1
- let mongoose = require('mongoose')
2
-
3
- mongoose.Promise = global.Promise
4
-
5
- let MessageActionModel = require('../../../Models').MessageAction(mongoose)
6
- let MessageActionModelBuiltInMongoose = require('../../../Models').MessageAction()
7
-
8
- let testCase = require('mocha').describe
9
- let assertions = require('mocha').it
10
- let chai = require('chai')
11
-
12
- let assert = chai.assert
13
- let mocha = require('mocha')
14
- let beforeEach = mocha.beforeEach
15
- let rules = require('./messageAction.rules.json')
16
-
17
- let messageAction
18
-
19
- beforeEach(() => {
20
- messageAction = JSON.parse(JSON.stringify(require('./messageAction.data.json')))
21
- })
22
-
23
- testCase('MessageAction', () => {
24
- testCase('Valid MessageAction', () => {
25
- assertions('should validate a valid messageAction ', (done) => {
26
- let MessageAction = new MessageActionModel(messageAction)
27
- MessageAction.validate((err, res) => {
28
- assert.notExists(res)
29
- assert(err === null, 'err should equals null')
30
- done()
31
- })
32
- })
33
- })
34
- testCase('Valid MessageAction', () => {
35
- assertions('should validate a valid messageAction ', (done) => {
36
- let MessageAction = new MessageActionModelBuiltInMongoose(messageAction)
37
- MessageAction.validate((err, res) => {
38
- assert.notExists(res)
39
- assert(err === null, 'err should equals null')
40
- done()
41
- })
42
- })
43
- })
44
-
45
- testCase('Invalid MessageAction', () => {
46
- assertions('should not validate a messageAction with invalid MessageAction', (done) => {
47
- delete messageAction[rules.requiredFields[0]]
48
- let MessageAction = new MessageActionModel(messageAction)
49
- MessageAction.validate((err, res) => {
50
- assert.exists(err, 'err object should exist')
51
- assert.isObject(err.errors)
52
- done()
53
- })
54
- })
55
- testCase('check each required property of the model and validate that it is present', () => {
56
- let requiredFields = rules.requiredFields
57
- requiredFields.map((i) => {
58
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
59
- // delete i from geofeatures' messageAction child
60
- delete messageAction[i]
61
- let MessageAction = new MessageActionModel(messageAction)
62
- MessageAction.validate((err, res) => {
63
- assert.notExists(res)
64
- assert.exists(err, 'err object should exist')
65
- assert.isObject(err.errors)
66
- assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
67
- done()
68
- })
69
- })
70
- })
71
- })
72
- })
73
- })
@@ -1,4 +0,0 @@
1
- {
2
- "type": "url",
3
- "url": "https://www.google.com"
4
- }
@@ -1,3 +0,0 @@
1
- {
2
- "requiredFields":["url"]
3
- }
@@ -1,74 +0,0 @@
1
- let mongoose = require('mongoose')
2
-
3
- mongoose.Promise = global.Promise
4
-
5
- let UrlactionModel = require('../../../Models').UrlAction(mongoose)
6
- let UrlactionModelBuiltInMongoose = require('../../../Models').UrlAction()
7
- let testCase = require('mocha').describe
8
- let assertions = require('mocha').it
9
- let chai = require('chai')
10
-
11
- let assert = chai.assert
12
- let mocha = require('mocha')
13
- let beforeEach = mocha.beforeEach
14
-
15
- let rules = require('./urlAction.rules.json')
16
-
17
- let urlaction
18
-
19
- beforeEach(() => {
20
- urlaction = JSON.parse(JSON.stringify(require('./urlAction.data.json')))
21
- })
22
-
23
- testCase('Urlaction', () => {
24
- testCase('Valid Urlaction', () => {
25
- assertions('should validate a valid urlaction ', (done) => {
26
- let Urlaction = new UrlactionModel(urlaction)
27
- Urlaction.validate((err, res) => {
28
- assert.notExists(res)
29
- assert(err === null, 'err should equals null')
30
- done()
31
- })
32
- })
33
- })
34
-
35
- testCase('Valid Urlaction (Built in mongoose)', () => {
36
- assertions('should validate a valid urlaction ', (done) => {
37
- let Urlaction = new UrlactionModelBuiltInMongoose(urlaction)
38
- Urlaction.validate((err, res) => {
39
- assert.notExists(res)
40
- assert(err === null, 'err should equals null')
41
- done()
42
- })
43
- })
44
- })
45
-
46
- testCase('Invalid Urlaction', () => {
47
- assertions('should not validate a urlaction with invalid Urlaction', (done) => {
48
- delete urlaction[rules.requiredFields[0]]
49
- let Urlaction = new UrlactionModel(urlaction)
50
- Urlaction.validate((err, res) => {
51
- assert.exists(err, 'err object should exist')
52
- assert.isObject(err.errors)
53
- done()
54
- })
55
- })
56
- testCase('check each required property of the model and validate that it is present', () => {
57
- let requiredFields = rules.requiredFields
58
- requiredFields.map((i) => {
59
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
60
- // delete i from geofeatures' urlaction child
61
- delete urlaction[i]
62
- let Urlaction = new UrlactionModel(urlaction)
63
- Urlaction.validate((err, res) => {
64
- assert.notExists(res)
65
- assert.exists(err, 'err object should exist')
66
- assert.isObject(err.errors)
67
- assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
68
- done()
69
- })
70
- })
71
- })
72
- })
73
- })
74
- })
@@ -1,50 +0,0 @@
1
- let mongoose = require('mongoose')
2
-
3
- mongoose.Promise = global.Promise
4
-
5
- let ZoneModel = require('../../Models').Zone(mongoose)
6
- let testCase = require('mocha').describe
7
- let assertions = require('mocha').it
8
- let chai = require('chai')
9
- let assert = chai.assert
10
- let mocha = require('mocha')
11
- let beforeEach = mocha.beforeEach
12
-
13
- let zone
14
-
15
- beforeEach(() => {
16
- zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
17
- // remove conditions as it's not tested
18
- delete zone.conditions
19
- // remove all but 1 geofeatures as geofeatures are required
20
- zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/circle/i))
21
- // remove customData
22
- delete zone.customData
23
- })
24
-
25
- testCase('Zone - Action', () => {
26
- testCase('Valid Zone - Action', () => {
27
- assertions('should not throw an error when a valid action is instantiated within a zone', (done) => {
28
- let Zone = new ZoneModel(zone)
29
- Zone.validate((err, res) => {
30
- assert.notExists(res)
31
- assert(err === null, 'err equals null')
32
- done()
33
- })
34
- })
35
- })
36
-
37
- testCase('Invalid Zone - Action', () => {
38
- assertions('should throw an error when an invalid action is instantiated within a zone', (done) => {
39
- delete zone.actions[1].url
40
- let Zone = new ZoneModel(zone)
41
- Zone.validate((err, res) => {
42
- assert.exists(err, 'err object should exist')
43
- assert.isObject(err.errors)
44
- assert('actions.1.url' in err.errors)
45
- assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
46
- done()
47
- })
48
- })
49
- })
50
- })
@@ -1,29 +0,0 @@
1
- let mongoose = require('mongoose')
2
-
3
- let schema = {
4
- title: {type: String, required: [true, 'title is required. ']},
5
- message: {type: String, required: [true, 'message is required. ']}
6
- }
7
-
8
- let MessageActionSchema = new mongoose.Schema(schema, {
9
- _id: false,
10
- versionKey: false
11
- })
12
-
13
- MessageActionSchema.add({
14
- type: {type: String, required: true}
15
- })
16
-
17
- // optional mongoose
18
- let model = (mongooseInstance) => {
19
- let MessageAction
20
- if (mongooseInstance) {
21
- MessageAction = mongooseInstance.model('MessageAction', MessageActionSchema)
22
- } else {
23
- MessageAction = mongoose.model('MessageAction', MessageActionSchema)
24
- }
25
-
26
- return MessageAction
27
- }
28
- // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
29
- module.exports = { Model: model, Schema: MessageActionSchema, messageActionSchema: schema }
@@ -1,36 +0,0 @@
1
- let mongoose = require('mongoose')
2
- let validators = require('../utils/validators')
3
-
4
- let schema = {
5
- url: {
6
- type: String,
7
- required: [true, 'url is required. '],
8
- validate: {
9
- validator: validators.validateUrl
10
- }
11
- }
12
- }
13
-
14
- let URLActionSchema = new mongoose.Schema(schema, {
15
- _id: false,
16
- __v: false
17
- })
18
-
19
- URLActionSchema.add({
20
- type: {type: String, required: true}
21
- })
22
-
23
- // optional mongoose
24
- const model = (mongooseInstance) => {
25
- let Urlaction
26
- if (mongooseInstance) {
27
- Urlaction = mongooseInstance.model('Urlaction', URLActionSchema)
28
- } else {
29
- Urlaction = mongoose.model('Urlaction', URLActionSchema)
30
- }
31
-
32
- return Urlaction
33
- }
34
-
35
- // Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
36
- module.exports = { Model: model, Schema: URLActionSchema, urlActionSchema: schema }