@bluedot-innovation/models 8.0.0 → 8.1.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/CHANGELOG.md +6 -0
- package/Models.js +4 -0
- package/__tests__/action/message/messageAction.data.json +5 -0
- package/__tests__/action/message/messageAction.rules.json +3 -0
- package/__tests__/action/message/messageAction.spec.js +73 -0
- package/__tests__/action/url/urlAction.data.json +4 -0
- package/__tests__/action/url/urlAction.rules.json +3 -0
- package/__tests__/action/url/urlAction.spec.js +74 -0
- package/__tests__/project/project.data.json +0 -5
- package/__tests__/project/project.spec.js +0 -22
- package/__tests__/zone/zone.action.spec.js +50 -0
- package/__tests__/zone/zone.rules.json +2 -1
- package/__tests__/zone/zone.spec.js +107 -12
- package/helpers.js +4 -7
- package/models/MessageAction.js +29 -0
- package/models/UrlAction.js +36 -0
- package/models/Zone.js +23 -1
- package/package.json +1 -1
- package/schemas/Integration.js +2 -4
- package/schemas/IncentivioIntegration.js +0 -11
package/CHANGELOG.md
CHANGED
package/Models.js
CHANGED
|
@@ -7,7 +7,9 @@ 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
|
|
10
11
|
Models.Project = require('./models/Project').Model
|
|
12
|
+
Models.UrlAction = require('./models/UrlAction').Model
|
|
11
13
|
Models.User = require('./models/User').Model
|
|
12
14
|
Models.Zone = require('./models/Zone').Model
|
|
13
15
|
|
|
@@ -46,8 +48,10 @@ let Schemas = {}
|
|
|
46
48
|
|
|
47
49
|
Schemas.Account = require('./models/Account').Schema
|
|
48
50
|
Schemas.Destination = require('./models/Destination').Schema
|
|
51
|
+
Schemas.MessageAction = require('./models/MessageAction').Schema
|
|
49
52
|
Schemas.Application = require('./models/Application').Schema
|
|
50
53
|
Schemas.Project = require('./models/Project').Schema
|
|
54
|
+
Schemas.UrlAction = require('./models/UrlAction').Schema
|
|
51
55
|
Schemas.User = require('./models/User').Schema
|
|
52
56
|
Schemas.Zone = require('./models/Zone').Schema
|
|
53
57
|
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
})
|
|
@@ -620,28 +620,6 @@ 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
|
-
})
|
|
645
623
|
})
|
|
646
624
|
|
|
647
625
|
describe('should throw an error when any of the values of the array contains a falsy value', () => {
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
})
|
|
@@ -131,6 +131,51 @@ 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
|
+
|
|
134
179
|
it('should throw an error when a condition is invalid', (done) => {
|
|
135
180
|
zone.conditions[0].startDate = 'abc'
|
|
136
181
|
let Zone = new ZoneModel(zone)
|
|
@@ -207,7 +252,7 @@ describe('Zone', () => {
|
|
|
207
252
|
})
|
|
208
253
|
})
|
|
209
254
|
|
|
210
|
-
it('should throw an error if CustomData key does not have alpha numeric and _ characters only
|
|
255
|
+
it('should throw an error if CustomData key does not have alpha numeric and _ characters only', (done) => {
|
|
211
256
|
zone.customData["name#3"] = "A Custom action"
|
|
212
257
|
let Zone = new ZoneModel(zone)
|
|
213
258
|
Zone.validate((err, res) => {
|
|
@@ -216,7 +261,7 @@ describe('Zone', () => {
|
|
|
216
261
|
})
|
|
217
262
|
})
|
|
218
263
|
|
|
219
|
-
it('should throw an error if custom data keys count is greater than 20
|
|
264
|
+
it('should throw an error if custom data keys count is greater than 20', (done) => {
|
|
220
265
|
for (let i = 0; i <= 21; i++) {
|
|
221
266
|
zone.customData[`key${i}`] = `value ${i}`
|
|
222
267
|
}
|
|
@@ -228,52 +273,102 @@ describe('Zone', () => {
|
|
|
228
273
|
})
|
|
229
274
|
})
|
|
230
275
|
|
|
231
|
-
it('should throw an error if CustomData value is null
|
|
276
|
+
it('should throw an error if CustomData value is null', (done) => {
|
|
232
277
|
zone.customData["name3"] = null;
|
|
233
278
|
|
|
234
279
|
let Zone = new ZoneModel(zone)
|
|
235
280
|
Zone.validate((err, res) => {
|
|
236
|
-
assert.match(err.message, /(CustomData value should not be empty)/i);
|
|
281
|
+
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
237
282
|
done()
|
|
238
283
|
})
|
|
239
284
|
})
|
|
240
285
|
|
|
241
|
-
it('should throw an error if CustomData value is undefined
|
|
286
|
+
it('should throw an error if CustomData value is undefined', (done) => {
|
|
242
287
|
zone.customData["name3"] = undefined;
|
|
243
288
|
|
|
244
289
|
let Zone = new ZoneModel(zone)
|
|
245
290
|
Zone.validate((err, res) => {
|
|
246
|
-
assert.match(err.message, /(CustomData value should not be empty)/i);
|
|
291
|
+
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
247
292
|
done()
|
|
248
293
|
})
|
|
249
294
|
})
|
|
250
295
|
|
|
251
|
-
it('should throw an error if CustomData value is an empty string
|
|
296
|
+
it('should throw an error if CustomData value is an empty string', (done) => {
|
|
252
297
|
zone.customData["name3"] = ' ';
|
|
253
298
|
|
|
254
299
|
let Zone = new ZoneModel(zone)
|
|
255
300
|
Zone.validate((err, res) => {
|
|
256
|
-
assert.match(err.message, /(CustomData value should not be empty)/i);
|
|
301
|
+
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
257
302
|
done()
|
|
258
303
|
})
|
|
259
304
|
})
|
|
260
305
|
|
|
261
|
-
it('should throw an error if CustomData value is an empty object
|
|
306
|
+
it('should throw an error if CustomData value is an empty object', (done) => {
|
|
262
307
|
zone.customData["name3"] = {};
|
|
263
308
|
|
|
264
309
|
let Zone = new ZoneModel(zone)
|
|
265
310
|
Zone.validate((err, res) => {
|
|
266
|
-
assert.match(err.message, /(CustomData value should not be empty)/i);
|
|
311
|
+
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
267
312
|
done()
|
|
268
313
|
})
|
|
269
314
|
})
|
|
270
315
|
|
|
271
|
-
it('should throw an error if CustomData value is an
|
|
316
|
+
it('should throw an error if CustomData value is an object', (done) => {
|
|
317
|
+
zone.customData["name3"] = { key: 'value' };
|
|
318
|
+
|
|
319
|
+
let Zone = new ZoneModel(zone)
|
|
320
|
+
Zone.validate((err, res) => {
|
|
321
|
+
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
322
|
+
done()
|
|
323
|
+
})
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
it('should throw an error if CustomData value is an empty array', (done) => {
|
|
272
327
|
zone.customData["name3"] = [];
|
|
273
328
|
|
|
274
329
|
let Zone = new ZoneModel(zone)
|
|
275
330
|
Zone.validate((err, res) => {
|
|
276
|
-
assert.match(err.message, /(CustomData value should not be empty)/i);
|
|
331
|
+
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
332
|
+
done()
|
|
333
|
+
})
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
it('should throw an error if CustomData value is an array', (done) => {
|
|
337
|
+
zone.customData["name3"] = ['value1', 'value2'];
|
|
338
|
+
|
|
339
|
+
let Zone = new ZoneModel(zone)
|
|
340
|
+
Zone.validate((err, res) => {
|
|
341
|
+
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
342
|
+
done()
|
|
343
|
+
})
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
it('should throw an error if CustomData value is a number', (done) => {
|
|
347
|
+
zone.customData["name3"] = 1;
|
|
348
|
+
|
|
349
|
+
let Zone = new ZoneModel(zone)
|
|
350
|
+
Zone.validate((err, res) => {
|
|
351
|
+
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
352
|
+
done()
|
|
353
|
+
})
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
it('should throw an error if CustomData value is a boolean', (done) => {
|
|
357
|
+
zone.customData["name3"] = true;
|
|
358
|
+
|
|
359
|
+
let Zone = new ZoneModel(zone)
|
|
360
|
+
Zone.validate((err, res) => {
|
|
361
|
+
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
362
|
+
done()
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
it('should throw an error if CustomData value is a NaN', (done) => {
|
|
367
|
+
zone.customData["name3"] = NaN;
|
|
368
|
+
|
|
369
|
+
let Zone = new ZoneModel(zone)
|
|
370
|
+
Zone.validate((err, res) => {
|
|
371
|
+
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
277
372
|
done()
|
|
278
373
|
})
|
|
279
374
|
})
|
package/helpers.js
CHANGED
|
@@ -50,12 +50,12 @@ helpers.checkDuplicateKeys = function (data) {
|
|
|
50
50
|
*
|
|
51
51
|
* @remarks
|
|
52
52
|
* ensures that data is an object
|
|
53
|
-
* ensures data.key is valid (`
|
|
53
|
+
* ensures data.key is valid (`must be a non-empty string`)
|
|
54
54
|
*
|
|
55
55
|
* @param data
|
|
56
56
|
* @returns boolean
|
|
57
57
|
*/
|
|
58
|
-
helpers.
|
|
58
|
+
helpers.isCustomDataValuesNotEmptyString = function (data) {
|
|
59
59
|
|
|
60
60
|
if(!isValidObject(data)){
|
|
61
61
|
return false
|
|
@@ -64,11 +64,8 @@ helpers.isCustomDataValuesNotEmpty = function (data) {
|
|
|
64
64
|
const customDataValues = Object.values(data)
|
|
65
65
|
|
|
66
66
|
return customDataValues.every(value => {
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// not null, not undefined, not {}, not []
|
|
71
|
-
return (value !== null && value !== undefined && JSON.stringify(value) !== '{}' && JSON.stringify(value) !== '[]')
|
|
67
|
+
// must be a non-empty string
|
|
68
|
+
return (typeof value === 'string' && value.trim().length > 0)
|
|
72
69
|
})
|
|
73
70
|
}
|
|
74
71
|
|
|
@@ -0,0 +1,29 @@
|
|
|
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 }
|
|
@@ -0,0 +1,36 @@
|
|
|
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 }
|
package/models/Zone.js
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
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
|
|
10
12
|
let circleSchema = require('./geofeatures/Circle').circleSchema
|
|
11
13
|
let boundingBoxSchema = require('./geofeatures/BoundingBox').boundingBoxSchema
|
|
12
14
|
let geolineSchema = require('./geofeatures/Geoline').geolineSchema
|
|
@@ -30,7 +32,7 @@ let helpers = require('../helpers')
|
|
|
30
32
|
let customDataValidators = [
|
|
31
33
|
{validator: helpers.validateCustomData, msg: 'CustomData key should have alpha numeric, - and _ characters only'},
|
|
32
34
|
{validator: helpers.checkDuplicateKeys, msg: 'CustomData key should be unique'},
|
|
33
|
-
{validator: helpers.
|
|
35
|
+
{validator: helpers.isCustomDataValuesNotEmptyString, msg: 'CustomData value should be a string and should not be empty'},
|
|
34
36
|
{validator: helpers.isValidCustomDataCount, msg: 'Only 20 custom data fields are allowed to be added per zone'}
|
|
35
37
|
];
|
|
36
38
|
|
|
@@ -40,6 +42,16 @@ const tagsFormation = (zone) => {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
|
|
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
|
+
|
|
43
55
|
let conditionSchema = new Schema({},
|
|
44
56
|
{ discriminatorKey: 'type', _id: false })
|
|
45
57
|
|
|
@@ -84,6 +96,13 @@ let zoneSchema = new Schema({
|
|
|
84
96
|
message: 'conditions must have a value'
|
|
85
97
|
}
|
|
86
98
|
},
|
|
99
|
+
actions: {
|
|
100
|
+
type: [actionSchema],
|
|
101
|
+
validate: {
|
|
102
|
+
validator: helpers.validateNotNull,
|
|
103
|
+
message: 'actions must have a value'
|
|
104
|
+
}
|
|
105
|
+
},
|
|
87
106
|
geofeatures: {
|
|
88
107
|
type: [geofeatureSchema],
|
|
89
108
|
required: true,
|
|
@@ -106,6 +125,9 @@ let zoneSchema = new Schema({
|
|
|
106
125
|
// plugin for PATCH operations
|
|
107
126
|
zoneSchema.plugin(patcher)
|
|
108
127
|
|
|
128
|
+
zoneSchema.path('actions').discriminator('url', new Schema(urlActionSchema, {_id: false}))
|
|
129
|
+
zoneSchema.path('actions').discriminator('message', new Schema(messageActionSchema, {_id: false}))
|
|
130
|
+
|
|
109
131
|
zoneSchema.path('conditions').discriminator('dayRange', new Schema(dayRangeRawSchema, {_id: false}))
|
|
110
132
|
zoneSchema.path('conditions').discriminator('speed', new Schema(speedRawSchema, {_id: false}))
|
|
111
133
|
zoneSchema.path('conditions').discriminator('timeActive', new Schema(timeActiveRawSchema, {_id: false}))
|
package/package.json
CHANGED
package/schemas/Integration.js
CHANGED
|
@@ -4,8 +4,7 @@ const segmentIntegrationSchema = require('./SegmentIntegration')
|
|
|
4
4
|
const oneSignalIntegrationSchema = require('./OneSignalIntegration')
|
|
5
5
|
const bbotIntegrationSchema = require('./BbotIntegration')
|
|
6
6
|
const flipdishIntegrationSchema = require('./FlipdishIntegration')
|
|
7
|
-
const projectAttentiveIntegrationSchema = require('./ProjectAttentiveIntegration')
|
|
8
|
-
const incentivioIntegrationSchema = require('./IncentivioIntegration')
|
|
7
|
+
const projectAttentiveIntegrationSchema = require('./ProjectAttentiveIntegration')
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
const MParticleSchema = new mongoose.Schema({
|
|
@@ -59,8 +58,7 @@ const IntegrationSchema = new mongoose.Schema({
|
|
|
59
58
|
oneSignal: { type: oneSignalIntegrationSchema },
|
|
60
59
|
bbot: { type: bbotIntegrationSchema },
|
|
61
60
|
flipdish: { type: flipdishIntegrationSchema },
|
|
62
|
-
attentive: { type: projectAttentiveIntegrationSchema }
|
|
63
|
-
incentivio: { type: incentivioIntegrationSchema }
|
|
61
|
+
attentive: { type: projectAttentiveIntegrationSchema }
|
|
64
62
|
},{ _id : false });
|
|
65
63
|
function apiKeyValidator(value){
|
|
66
64
|
// check if the value is a non-empty string
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const mongoose = require('mongoose');
|
|
2
|
-
|
|
3
|
-
let IncentivioIntegrationSchema = new mongoose.Schema({
|
|
4
|
-
nowReadyEnabled: {type: Boolean, default: true},
|
|
5
|
-
clientId: {type: String, required: true},
|
|
6
|
-
lastSyncedTime: {type: Date}
|
|
7
|
-
}, {
|
|
8
|
-
_id: false
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
module.exports = IncentivioIntegrationSchema
|