@bluedot-innovation/models 7.18.2 → 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 +9 -0
- package/__tests__/project/project.data.json +0 -5
- package/__tests__/project/project.spec.js +0 -22
- package/__tests__/zone/zone.spec.js +62 -12
- package/helpers.js +4 -7
- package/models/Zone.js +1 -1
- package/package.json +1 -1
- package/schemas/Integration.js +2 -4
- package/schemas/IncentivioIntegration.js +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## 8.1.1
|
|
2
|
+
- Validate Zone customData values - must be a string and should not be empty
|
|
3
|
+
|
|
4
|
+
## 8.1.0
|
|
5
|
+
- Remove incentivio and put Zone actions back in (removes 7.18.1-8.0.0 changes)
|
|
6
|
+
|
|
7
|
+
## 8.0.0
|
|
8
|
+
- BREAKING CHANGE - remove Zone actions
|
|
9
|
+
|
|
1
10
|
## 7.18.2
|
|
2
11
|
- make clientId in Incentivio integration mandatory
|
|
3
12
|
|
|
@@ -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', () => {
|
|
@@ -252,7 +252,7 @@ describe('Zone', () => {
|
|
|
252
252
|
})
|
|
253
253
|
})
|
|
254
254
|
|
|
255
|
-
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) => {
|
|
256
256
|
zone.customData["name#3"] = "A Custom action"
|
|
257
257
|
let Zone = new ZoneModel(zone)
|
|
258
258
|
Zone.validate((err, res) => {
|
|
@@ -261,7 +261,7 @@ describe('Zone', () => {
|
|
|
261
261
|
})
|
|
262
262
|
})
|
|
263
263
|
|
|
264
|
-
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) => {
|
|
265
265
|
for (let i = 0; i <= 21; i++) {
|
|
266
266
|
zone.customData[`key${i}`] = `value ${i}`
|
|
267
267
|
}
|
|
@@ -273,52 +273,102 @@ describe('Zone', () => {
|
|
|
273
273
|
})
|
|
274
274
|
})
|
|
275
275
|
|
|
276
|
-
it('should throw an error if CustomData value is null
|
|
276
|
+
it('should throw an error if CustomData value is null', (done) => {
|
|
277
277
|
zone.customData["name3"] = null;
|
|
278
278
|
|
|
279
279
|
let Zone = new ZoneModel(zone)
|
|
280
280
|
Zone.validate((err, res) => {
|
|
281
|
-
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);
|
|
282
282
|
done()
|
|
283
283
|
})
|
|
284
284
|
})
|
|
285
285
|
|
|
286
|
-
it('should throw an error if CustomData value is undefined
|
|
286
|
+
it('should throw an error if CustomData value is undefined', (done) => {
|
|
287
287
|
zone.customData["name3"] = undefined;
|
|
288
288
|
|
|
289
289
|
let Zone = new ZoneModel(zone)
|
|
290
290
|
Zone.validate((err, res) => {
|
|
291
|
-
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);
|
|
292
292
|
done()
|
|
293
293
|
})
|
|
294
294
|
})
|
|
295
295
|
|
|
296
|
-
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) => {
|
|
297
297
|
zone.customData["name3"] = ' ';
|
|
298
298
|
|
|
299
299
|
let Zone = new ZoneModel(zone)
|
|
300
300
|
Zone.validate((err, res) => {
|
|
301
|
-
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);
|
|
302
302
|
done()
|
|
303
303
|
})
|
|
304
304
|
})
|
|
305
305
|
|
|
306
|
-
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) => {
|
|
307
307
|
zone.customData["name3"] = {};
|
|
308
308
|
|
|
309
309
|
let Zone = new ZoneModel(zone)
|
|
310
310
|
Zone.validate((err, res) => {
|
|
311
|
-
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);
|
|
312
312
|
done()
|
|
313
313
|
})
|
|
314
314
|
})
|
|
315
315
|
|
|
316
|
-
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) => {
|
|
317
327
|
zone.customData["name3"] = [];
|
|
318
328
|
|
|
319
329
|
let Zone = new ZoneModel(zone)
|
|
320
330
|
Zone.validate((err, res) => {
|
|
321
|
-
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);
|
|
322
372
|
done()
|
|
323
373
|
})
|
|
324
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
|
|
package/models/Zone.js
CHANGED
|
@@ -32,7 +32,7 @@ let helpers = require('../helpers')
|
|
|
32
32
|
let customDataValidators = [
|
|
33
33
|
{validator: helpers.validateCustomData, msg: 'CustomData key should have alpha numeric, - and _ characters only'},
|
|
34
34
|
{validator: helpers.checkDuplicateKeys, msg: 'CustomData key should be unique'},
|
|
35
|
-
{validator: helpers.
|
|
35
|
+
{validator: helpers.isCustomDataValuesNotEmptyString, msg: 'CustomData value should be a string and should not be empty'},
|
|
36
36
|
{validator: helpers.isValidCustomDataCount, msg: 'Only 20 custom data fields are allowed to be added per zone'}
|
|
37
37
|
];
|
|
38
38
|
|
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
|