@bluedot-innovation/models 6.0.0 → 6.0.1-zeta.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/__tests__/project/project.spec.js +54 -3
- package/__tests__/zone/zone.spec.js +1 -1
- package/package.json +23 -23
- package/schemas/Integration.js +29 -8
- package/utils/validators.js +10 -4
- package/yarn.lock +0 -2796
package/CHANGELOG.md
CHANGED
|
@@ -61,6 +61,24 @@ testCase('Project', () => {
|
|
|
61
61
|
done()
|
|
62
62
|
})
|
|
63
63
|
})
|
|
64
|
+
assertions(`should not validate if webhook protocol is not valid `, (done) => {
|
|
65
|
+
project.webhooks.url = 'htt://test.com'
|
|
66
|
+
let Project = new ProjectModel(project)
|
|
67
|
+
Project.validate((err, res) => {
|
|
68
|
+
assert.exists(err)
|
|
69
|
+
assert.match(err.message, /Please enter a valid URL/)
|
|
70
|
+
done()
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
assertions(`should not validate if webhook domain is not valid `, (done) => {
|
|
74
|
+
project.webhooks.url = 'https://@'
|
|
75
|
+
let Project = new ProjectModel(project)
|
|
76
|
+
Project.validate((err, res) => {
|
|
77
|
+
assert.exists(err)
|
|
78
|
+
assert.match(err.message, /Please enter a valid URL/)
|
|
79
|
+
done()
|
|
80
|
+
})
|
|
81
|
+
})
|
|
64
82
|
testCase('mparticle integration check', () => {
|
|
65
83
|
assertions('should throw an error if the mparticle integration has empty key ', (done) => {
|
|
66
84
|
|
|
@@ -93,6 +111,17 @@ testCase('Project', () => {
|
|
|
93
111
|
done()
|
|
94
112
|
})
|
|
95
113
|
})
|
|
114
|
+
assertions('should throw an error if the mparticle integration misses all keys ', (done) => {
|
|
115
|
+
|
|
116
|
+
project.integrations.mParticle = {}
|
|
117
|
+
|
|
118
|
+
let Project = new ProjectModel(project)
|
|
119
|
+
Project.validate((err, res) => {
|
|
120
|
+
assert.exists(err)
|
|
121
|
+
assert.match(err.message, /either of the two field combinations is mandatory/)
|
|
122
|
+
done()
|
|
123
|
+
})
|
|
124
|
+
})
|
|
96
125
|
assertions('should throw an error if the mparticle integration misses both keys ', (done) => {
|
|
97
126
|
|
|
98
127
|
delete project.integrations.mParticle.iOSApiKey
|
|
@@ -117,6 +146,28 @@ testCase('Project', () => {
|
|
|
117
146
|
done()
|
|
118
147
|
})
|
|
119
148
|
})
|
|
149
|
+
assertions('should throw an error if the mparticle integration has valid android key pair, but no Ios secret ', (done) => {
|
|
150
|
+
|
|
151
|
+
delete project.integrations.mParticle.iOSSecret
|
|
152
|
+
|
|
153
|
+
let Project = new ProjectModel(project)
|
|
154
|
+
Project.validate((err, res) => {
|
|
155
|
+
assert.exists(err)
|
|
156
|
+
assert.match(err.message, /both iOSSecret and iOSApiKey are required/)
|
|
157
|
+
done()
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
assertions('should throw an error if the mparticle integration has valid Ios key pair, but no android secret ', (done) => {
|
|
161
|
+
|
|
162
|
+
delete project.integrations.mParticle.androidSecret
|
|
163
|
+
|
|
164
|
+
let Project = new ProjectModel(project)
|
|
165
|
+
Project.validate((err, res) => {
|
|
166
|
+
assert.exists(err)
|
|
167
|
+
assert.match(err.message, /both androidSecret and androidApiKey are required/)
|
|
168
|
+
done()
|
|
169
|
+
})
|
|
170
|
+
})
|
|
120
171
|
assertions('should validate if the mparticle integration has only Android key ', (done) => {
|
|
121
172
|
|
|
122
173
|
delete project.integrations.mParticle.androidApiKey
|
|
@@ -167,13 +218,13 @@ testCase('Project', () => {
|
|
|
167
218
|
})
|
|
168
219
|
})
|
|
169
220
|
|
|
170
|
-
it(`should
|
|
221
|
+
it(`should throw an error when webhooks is null`, (done) => {
|
|
171
222
|
project = JSON.parse(JSON.stringify(project))
|
|
172
223
|
project.webhooks = null
|
|
173
224
|
helpers.testNullValue(project, ProjectModel, done)
|
|
174
225
|
})
|
|
175
226
|
|
|
176
|
-
it(`should
|
|
227
|
+
it(`should throw an error when firebaseApiKey is null`, (done) => {
|
|
177
228
|
project = JSON.parse(JSON.stringify(project))
|
|
178
229
|
project.firebaseApiKey = null
|
|
179
230
|
helpers.testNullValue(project, ProjectModel, done)
|
|
@@ -184,7 +235,7 @@ testCase('Project', () => {
|
|
|
184
235
|
|
|
185
236
|
arrayTypeFields.map(arrayField => {
|
|
186
237
|
FALSY_VALUES.map(falsyValue => {
|
|
187
|
-
it(`should
|
|
238
|
+
it(`should throw an error when it contains ${falsyValue} on a ${arrayField}`, (done) => {
|
|
188
239
|
helpers.testFalsyValue(falsyValue, arrayField, project, ProjectModel, done)
|
|
189
240
|
})
|
|
190
241
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1-zeta.1",
|
|
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",
|
|
@@ -11,32 +11,32 @@
|
|
|
11
11
|
},
|
|
12
12
|
"license": "UNLICENSED",
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"babel-eslint": "
|
|
15
|
-
"chai": "
|
|
14
|
+
"babel-eslint": "8.2.3",
|
|
15
|
+
"chai": "4.1.2",
|
|
16
16
|
"describe": "*",
|
|
17
|
-
"eslint": "
|
|
18
|
-
"eslint-config-prettier": "
|
|
19
|
-
"eslint-config-standard": "
|
|
20
|
-
"eslint-plugin-import": "
|
|
21
|
-
"eslint-plugin-node": "
|
|
22
|
-
"eslint-plugin-prettier": "
|
|
23
|
-
"eslint-plugin-promise": "
|
|
24
|
-
"eslint-plugin-standard": "
|
|
25
|
-
"mocha": "
|
|
26
|
-
"nyc": "
|
|
27
|
-
"prettier": "
|
|
28
|
-
"sinon": "
|
|
17
|
+
"eslint": "4.12.0",
|
|
18
|
+
"eslint-config-prettier": "2.9.0",
|
|
19
|
+
"eslint-config-standard": "10.2.1",
|
|
20
|
+
"eslint-plugin-import": "2.8.0",
|
|
21
|
+
"eslint-plugin-node": "5.2.1",
|
|
22
|
+
"eslint-plugin-prettier": "2.6.0",
|
|
23
|
+
"eslint-plugin-promise": "3.6.0",
|
|
24
|
+
"eslint-plugin-standard": "3.0.1",
|
|
25
|
+
"mocha": "4.0.1",
|
|
26
|
+
"nyc": "11.3.0",
|
|
27
|
+
"prettier": "1.13.5",
|
|
28
|
+
"sinon": "4.1.2"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@bluedot-innovation/enums": "
|
|
31
|
+
"@bluedot-innovation/enums": "2.1.5",
|
|
32
32
|
"@bluedot-innovation/mongoose-json-patch": "0.0.8",
|
|
33
|
-
"@mongoosejs/double": "
|
|
34
|
-
"@turf/area": "
|
|
35
|
-
"@turf/helpers": "
|
|
36
|
-
"deep-equal": "
|
|
37
|
-
"fast-deep-equal": "
|
|
33
|
+
"@mongoosejs/double": "0.2.0",
|
|
34
|
+
"@turf/area": "6.0.1",
|
|
35
|
+
"@turf/helpers": "6.1.4",
|
|
36
|
+
"deep-equal": "1.0.1",
|
|
37
|
+
"fast-deep-equal": "2.0.1",
|
|
38
38
|
"lodash.clonedeep": "4.5.0",
|
|
39
|
-
"mongoose": "
|
|
40
|
-
"uuid": "
|
|
39
|
+
"mongoose": "5.7.13",
|
|
40
|
+
"uuid": "3.1.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/schemas/Integration.js
CHANGED
|
@@ -31,30 +31,51 @@ const MParticleSchema = new mongoose.Schema({
|
|
|
31
31
|
msg:'iOSSecret should be a non-empty string, found ${VALUE}'
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
})
|
|
34
|
+
},{ _id : false })
|
|
35
35
|
|
|
36
36
|
const IntegrationSchema = new mongoose.Schema({
|
|
37
37
|
mParticle: {
|
|
38
38
|
type: MParticleSchema,
|
|
39
|
-
validate: {
|
|
39
|
+
validate: [{
|
|
40
40
|
validator: mParticleValidator,
|
|
41
41
|
msg: 'either of the two field combinations is mandatory: androidApiKey & androidSecret OR iOSApiKey & iOSSecret'
|
|
42
|
-
},
|
|
42
|
+
},{
|
|
43
|
+
validator:iOSPairValidator,
|
|
44
|
+
msg: 'both iOSSecret and iOSApiKey are required'
|
|
45
|
+
},{
|
|
46
|
+
validator:androidPairValidator,
|
|
47
|
+
msg: 'both androidSecret and androidApiKey are required'
|
|
48
|
+
}
|
|
49
|
+
],
|
|
43
50
|
required: true
|
|
44
51
|
}
|
|
45
|
-
});
|
|
52
|
+
},{ _id : false });
|
|
46
53
|
function apiKeyValidator(value){
|
|
47
54
|
// check if the value is a non-empty string
|
|
48
55
|
return !(typeof value !=='string' || value.trim() === '')
|
|
56
|
+
}
|
|
57
|
+
function iOSPairValidator(value){
|
|
58
|
+
const {iOSApiKey,iOSSecret} = value
|
|
59
|
+
const isIOSApiKeyProvided = (iOSApiKey !== undefined)
|
|
60
|
+
const isIOSSecretProvided = (iOSSecret !== undefined)
|
|
49
61
|
|
|
62
|
+
return isIOSApiKeyProvided === isIOSSecretProvided
|
|
50
63
|
}
|
|
64
|
+
|
|
65
|
+
function androidPairValidator(value){
|
|
66
|
+
const {androidApiKey,androidSecret} = value
|
|
67
|
+
const isAndroidApiKeyProvided = (androidApiKey !== undefined)
|
|
68
|
+
const isAndroidSecretProvided = (androidSecret !== undefined)
|
|
69
|
+
|
|
70
|
+
return isAndroidApiKeyProvided === isAndroidSecretProvided
|
|
71
|
+
}
|
|
72
|
+
|
|
51
73
|
function mParticleValidator(value) {
|
|
52
74
|
const { androidApiKey,androidSecret, iOSApiKey,iOSSecret } = value;
|
|
75
|
+
const isAndroidPairProvided = ((androidApiKey !== undefined)&&(androidSecret !==undefined))
|
|
76
|
+
const isIosPairProvided = ((iOSApiKey !== undefined)&&(iOSSecret !==undefined))
|
|
53
77
|
|
|
54
|
-
|
|
55
|
-
const isIOSKeyProvided = (typeof iOSApiKey !== "undefined" && typeof iOSSecret !== "undefined")
|
|
56
|
-
|
|
57
|
-
return isAndroidKeyProvided || isIOSKeyProvided;
|
|
78
|
+
return isIosPairProvided || isAndroidPairProvided;
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
module.exports = IntegrationSchema
|
package/utils/validators.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
const { URL } = require('url');
|
|
2
2
|
exports.validateUrl = function(url) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
try {
|
|
4
|
+
const myUrl = new URL(url); // Check is valid.
|
|
5
|
+
const protocol = myUrl.protocol.toLowerCase();
|
|
6
|
+
if( protocol != 'http:' && protocol != 'https:' )
|
|
7
|
+
return false;
|
|
8
|
+
return true;
|
|
9
|
+
} catch (err) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
6
12
|
}
|