@bluedot-innovation/models 7.16.0 → 7.17.0-alpha
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 +3 -0
- package/__tests__/project/project.data.json +4 -0
- package/__tests__/project/project.spec.js +24 -13
- package/package.json +3 -3
- package/schemas/Integration.js +3 -1
- package/schemas/ProjectAttentiveIntegration.js +10 -0
- package/schemas/Webhook.js +4 -4
- package/utils/DbInitialiser/DbInitialiser.js +17 -16
package/CHANGELOG.md
CHANGED
|
@@ -485,27 +485,17 @@ describe('Project', () => {
|
|
|
485
485
|
let Project = new ProjectModel(project)
|
|
486
486
|
Project.validate((err, res) => {
|
|
487
487
|
assert.exists(err)
|
|
488
|
-
assert.match(err.message, /type "register" can only have structure "mobivity"
|
|
488
|
+
assert.match(err.message, /type "register" can only have structure "mobivity"/)
|
|
489
489
|
done()
|
|
490
490
|
})
|
|
491
491
|
})
|
|
492
|
-
it(`should not validate if the type is register and the structure is not mobivity
|
|
492
|
+
it(`should not validate if the type is register and the structure is not mobivity`, (done) => {
|
|
493
493
|
project.webhooks[0].type = "register"
|
|
494
494
|
project.webhooks[0].structure = "standard"
|
|
495
495
|
let Project = new ProjectModel(project)
|
|
496
496
|
Project.validate((err, res) => {
|
|
497
497
|
assert.exists(err)
|
|
498
|
-
assert.match(err.message, /type "register" can only have structure "mobivity"
|
|
499
|
-
done()
|
|
500
|
-
})
|
|
501
|
-
})
|
|
502
|
-
it(`should not validate if structure is attentive and the type is not register`, (done) => {
|
|
503
|
-
project.webhooks[0].type = "trigger"
|
|
504
|
-
project.webhooks[0].structure = "attentive"
|
|
505
|
-
let Project = new ProjectModel(project)
|
|
506
|
-
Project.validate((err, res) => {
|
|
507
|
-
assert.exists(err)
|
|
508
|
-
assert.match(err.message, /type "register" can only have structure "mobivity" or "attentive"/)
|
|
498
|
+
assert.match(err.message, /type "register" can only have structure "mobivity"/)
|
|
509
499
|
done()
|
|
510
500
|
})
|
|
511
501
|
})
|
|
@@ -609,6 +599,27 @@ describe('Project', () => {
|
|
|
609
599
|
})
|
|
610
600
|
})
|
|
611
601
|
})
|
|
602
|
+
describe("Attentive integration validation", () => {
|
|
603
|
+
it('should throw an error when trigger is non boolean', (done) => {
|
|
604
|
+
project.integrations.attentive.trigger = "invalid"
|
|
605
|
+
let Project = new ProjectModel(project)
|
|
606
|
+
Project.validate((err, res) => {
|
|
607
|
+
assert.exists(err)
|
|
608
|
+
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "trigger"/)
|
|
609
|
+
done()
|
|
610
|
+
})
|
|
611
|
+
})
|
|
612
|
+
|
|
613
|
+
it('should throw an error when helloRegister is non boolean', (done) => {
|
|
614
|
+
project.integrations.attentive.helloRegister = "invalid"
|
|
615
|
+
let Project = new ProjectModel(project)
|
|
616
|
+
Project.validate((err, res) => {
|
|
617
|
+
assert.exists(err)
|
|
618
|
+
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "helloRegister"/)
|
|
619
|
+
done()
|
|
620
|
+
})
|
|
621
|
+
})
|
|
622
|
+
})
|
|
612
623
|
})
|
|
613
624
|
|
|
614
625
|
describe('should throw an error when any of the values of the array contains a falsy value', () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.17.0-alpha",
|
|
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",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"eslint-plugin-promise": "^3.6.0",
|
|
24
24
|
"eslint-plugin-standard": "^3.0.1",
|
|
25
25
|
"mocha": "^4.0.1",
|
|
26
|
-
"mongodb": "^
|
|
26
|
+
"mongodb": "^5.1.0",
|
|
27
27
|
"nyc": "^11.3.0",
|
|
28
28
|
"prettier": "^1.13.5",
|
|
29
29
|
"sinon": "^4.1.2"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"deep-equal": "^1.0.1",
|
|
38
38
|
"fast-deep-equal": "^2.0.1",
|
|
39
39
|
"lodash.clonedeep": "4.5.0",
|
|
40
|
-
"mongoose": "^
|
|
40
|
+
"mongoose": "^6.10.4",
|
|
41
41
|
"uuid": "^3.1.0"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/schemas/Integration.js
CHANGED
|
@@ -4,6 +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')
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
const MParticleSchema = new mongoose.Schema({
|
|
@@ -56,7 +57,8 @@ const IntegrationSchema = new mongoose.Schema({
|
|
|
56
57
|
segment: { type: segmentIntegrationSchema },
|
|
57
58
|
oneSignal: { type: oneSignalIntegrationSchema },
|
|
58
59
|
bbot: { type: bbotIntegrationSchema },
|
|
59
|
-
flipdish: { type: flipdishIntegrationSchema }
|
|
60
|
+
flipdish: { type: flipdishIntegrationSchema },
|
|
61
|
+
attentive: { type: projectAttentiveIntegrationSchema }
|
|
60
62
|
},{ _id : false });
|
|
61
63
|
function apiKeyValidator(value){
|
|
62
64
|
// check if the value is a non-empty string
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
let ProjectAttentiveIntegrationSchema = new mongoose.Schema({
|
|
4
|
+
helloRegister: {type: Boolean, required: true},
|
|
5
|
+
trigger: {type: Boolean, required: true}
|
|
6
|
+
}, {
|
|
7
|
+
_id: false
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
module.exports = ProjectAttentiveIntegrationSchema
|
package/schemas/Webhook.js
CHANGED
|
@@ -28,9 +28,9 @@ function validateMobivityRequiredFields(structure){
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function validateTypeAndStructure(type) {
|
|
31
|
-
if ((type === "register" && !['mobivity'
|
|
32
|
-
|| (type !== "register" && ['mobivity'
|
|
33
|
-
throw new Error('type "register" can only have structure "mobivity"
|
|
31
|
+
if ((type === "register" && !['mobivity'].includes(this.structure))
|
|
32
|
+
|| (type !== "register" && ['mobivity'].includes(this.structure))) {
|
|
33
|
+
throw new Error('type "register" can only have structure "mobivity"')
|
|
34
34
|
} else if ((type === "helloOrder" && this.structure !== 'default')
|
|
35
35
|
|| (type !== "helloOrder" && this.structure === 'default')) {
|
|
36
36
|
throw new Error('type "helloOrder" can only have structure "default"')
|
|
@@ -44,7 +44,7 @@ let WebhookSchema = new mongoose.Schema({
|
|
|
44
44
|
body: {type: mongoose.Schema.Types.Mixed, validate: [{ validator: validators.validateNonEmptyStringKeyValuePairsOnly, msg: 'webhook body keys and values must be strings' }, { validator: validators.validateNoSpacesInObjectKeys, msg: 'webhook body keys cannot contain spaces' }]},
|
|
45
45
|
structure: {
|
|
46
46
|
type: String,
|
|
47
|
-
enum: ['standard', 'tealium', 'mobivity', '
|
|
47
|
+
enum: ['standard', 'tealium', 'mobivity', 'default'],
|
|
48
48
|
default: 'standard',
|
|
49
49
|
validate: [
|
|
50
50
|
{validator: validateTealiumRequiredFields, msg: 'tealium webhooks require "tealium_account" and "tealium_profile" body fields to be present'},
|
|
@@ -4,26 +4,27 @@ const {createAllIndexesIfNotExists} = require("./indexInitialiser");
|
|
|
4
4
|
const MONGO_DB_URI = process.env.MONGO_DB_URI
|
|
5
5
|
const DB_NAME = process.env.DB_NAME
|
|
6
6
|
const ENVIRONMENT = process.env.ENVIRONMENT
|
|
7
|
-
const client = new MongoClient(MONGO_DB_URI
|
|
7
|
+
const client = new MongoClient(MONGO_DB_URI)
|
|
8
8
|
|
|
9
9
|
console.log(`Using DB_NAME:${DB_NAME} in ENVIRONMENT:${ENVIRONMENT}`)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
try {
|
|
12
|
+
await client.connect()
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.log("Failed to connect to Mongo DB", error)
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
console.log("Connected to Mongo DB")
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
await createAllIndexesIfNotExists(db)
|
|
22
|
-
}catch(error){
|
|
23
|
-
console.log(error)
|
|
24
|
-
await client.close()
|
|
25
|
-
process.exit(1)
|
|
26
|
-
}
|
|
20
|
+
const db = client.db(DB_NAME)
|
|
27
21
|
|
|
22
|
+
try{
|
|
23
|
+
await createAllIndexesIfNotExists(db)
|
|
24
|
+
} catch(error) {
|
|
25
|
+
console.log(error)
|
|
28
26
|
await client.close()
|
|
29
|
-
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
await client.close()
|