@bluedot-innovation/models 6.0.2 → 6.0.4
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.data.json +4 -4
- package/__tests__/project/project.spec.js +28 -17
- package/package.json +1 -1
- package/schemas/Integration.js +18 -18
- package/schemas/Webhook.js +12 -1
package/CHANGELOG.md
CHANGED
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"firebaseApiKey": "88888888-4444-4444-4444-121212121212",
|
|
17
17
|
"apiKey": "88888888-4444-4444-4444-123412341234",
|
|
18
18
|
"integrations":{
|
|
19
|
-
"
|
|
19
|
+
"mparticle": {
|
|
20
20
|
"androidApiKey": "us1-c5e6eefe90fe704aba0a7d2daa00baaa",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
21
|
+
"androidSecretKey": "eZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN",
|
|
22
|
+
"iosApiKey": "us1-a5e6eefe90fe704aba0a7d2daa00baaa",
|
|
23
|
+
"iosSecretKey": "fZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN"
|
|
24
24
|
}
|
|
25
25
|
}}
|
|
@@ -22,7 +22,7 @@ beforeEach(() => {
|
|
|
22
22
|
|
|
23
23
|
testCase('Project', () => {
|
|
24
24
|
testCase('Valid Project ', () => {
|
|
25
|
-
assertions('should validate a valid project ', (done) => {
|
|
25
|
+
assertions('should validate a valid project ', (done) => {
|
|
26
26
|
let Project = new ProjectModel(project)
|
|
27
27
|
Project.validate((err, res) => {
|
|
28
28
|
assert.notExists(res)
|
|
@@ -82,7 +82,7 @@ testCase('Project', () => {
|
|
|
82
82
|
testCase('mparticle integration check', () => {
|
|
83
83
|
assertions('should throw an error if the mparticle integration has empty key ', (done) => {
|
|
84
84
|
|
|
85
|
-
project.integrations.
|
|
85
|
+
project.integrations.mparticle.androidApiKey = null
|
|
86
86
|
|
|
87
87
|
let Project = new ProjectModel(project)
|
|
88
88
|
Project.validate((err, res) => {
|
|
@@ -93,27 +93,27 @@ testCase('Project', () => {
|
|
|
93
93
|
})
|
|
94
94
|
assertions('should throw an error if the mparticle integration has a key with empty string ', (done) => {
|
|
95
95
|
|
|
96
|
-
project.integrations.
|
|
96
|
+
project.integrations.mparticle.iosApiKey = ''
|
|
97
97
|
let Project = new ProjectModel(project)
|
|
98
98
|
Project.validate((err, res) => {
|
|
99
99
|
assert.exists(err)
|
|
100
|
-
assert.match(err.message, /
|
|
100
|
+
assert.match(err.message, /iosApiKey should be a non-empty string/)
|
|
101
101
|
done()
|
|
102
102
|
})
|
|
103
103
|
})
|
|
104
104
|
assertions('should throw an error if the mparticle integration has a secret key with empty string ', (done) => {
|
|
105
105
|
|
|
106
|
-
project.integrations.
|
|
106
|
+
project.integrations.mparticle.iosSecretKey = ''
|
|
107
107
|
let Project = new ProjectModel(project)
|
|
108
108
|
Project.validate((err, res) => {
|
|
109
109
|
assert.exists(err)
|
|
110
|
-
assert.match(err.message, /
|
|
110
|
+
assert.match(err.message, /iosSecretKey should be a non-empty string/)
|
|
111
111
|
done()
|
|
112
112
|
})
|
|
113
113
|
})
|
|
114
114
|
assertions('should throw an error if the mparticle integration misses all keys ', (done) => {
|
|
115
115
|
|
|
116
|
-
project.integrations.
|
|
116
|
+
project.integrations.mparticle = {}
|
|
117
117
|
|
|
118
118
|
let Project = new ProjectModel(project)
|
|
119
119
|
Project.validate((err, res) => {
|
|
@@ -124,8 +124,8 @@ testCase('Project', () => {
|
|
|
124
124
|
})
|
|
125
125
|
assertions('should throw an error if the mparticle integration misses both keys ', (done) => {
|
|
126
126
|
|
|
127
|
-
delete project.integrations.
|
|
128
|
-
delete project.integrations.
|
|
127
|
+
delete project.integrations.mparticle.iosApiKey
|
|
128
|
+
delete project.integrations.mparticle.androidApiKey
|
|
129
129
|
|
|
130
130
|
let Project = new ProjectModel(project)
|
|
131
131
|
Project.validate((err, res) => {
|
|
@@ -136,8 +136,8 @@ testCase('Project', () => {
|
|
|
136
136
|
})
|
|
137
137
|
assertions('should throw an error if the mparticle integration misses both secret keys ', (done) => {
|
|
138
138
|
|
|
139
|
-
delete project.integrations.
|
|
140
|
-
delete project.integrations.
|
|
139
|
+
delete project.integrations.mparticle.iosSecretKey
|
|
140
|
+
delete project.integrations.mparticle.androidSecretKey
|
|
141
141
|
|
|
142
142
|
let Project = new ProjectModel(project)
|
|
143
143
|
Project.validate((err, res) => {
|
|
@@ -148,30 +148,30 @@ testCase('Project', () => {
|
|
|
148
148
|
})
|
|
149
149
|
assertions('should throw an error if the mparticle integration has valid android key pair, but no Ios secret ', (done) => {
|
|
150
150
|
|
|
151
|
-
delete project.integrations.
|
|
151
|
+
delete project.integrations.mparticle.iosSecretKey
|
|
152
152
|
|
|
153
153
|
let Project = new ProjectModel(project)
|
|
154
154
|
Project.validate((err, res) => {
|
|
155
155
|
assert.exists(err)
|
|
156
|
-
assert.match(err.message, /both
|
|
156
|
+
assert.match(err.message, /both iosSecretKey and iosApiKey are required/)
|
|
157
157
|
done()
|
|
158
158
|
})
|
|
159
159
|
})
|
|
160
160
|
assertions('should throw an error if the mparticle integration has valid Ios key pair, but no android secret ', (done) => {
|
|
161
161
|
|
|
162
|
-
delete project.integrations.
|
|
162
|
+
delete project.integrations.mparticle.androidSecretKey
|
|
163
163
|
|
|
164
164
|
let Project = new ProjectModel(project)
|
|
165
165
|
Project.validate((err, res) => {
|
|
166
166
|
assert.exists(err)
|
|
167
|
-
assert.match(err.message, /both
|
|
167
|
+
assert.match(err.message, /both androidSecretKey and androidApiKey are required/)
|
|
168
168
|
done()
|
|
169
169
|
})
|
|
170
170
|
})
|
|
171
171
|
assertions('should validate if the mparticle integration has only Android key ', (done) => {
|
|
172
172
|
|
|
173
|
-
delete project.integrations.
|
|
174
|
-
delete project.integrations.
|
|
173
|
+
delete project.integrations.mparticle.androidApiKey
|
|
174
|
+
delete project.integrations.mparticle.androidSecretKey
|
|
175
175
|
|
|
176
176
|
let Project = new ProjectModel(project)
|
|
177
177
|
Project.validate((err, res) => {
|
|
@@ -224,6 +224,17 @@ testCase('Project', () => {
|
|
|
224
224
|
helpers.testNullValue(project, ProjectModel, done)
|
|
225
225
|
})
|
|
226
226
|
|
|
227
|
+
it(`should throw an error when webhooks has primitive value in headers`, (done) => {
|
|
228
|
+
project = JSON.parse(JSON.stringify(project))
|
|
229
|
+
project.webhooks.headers = 'primitive'
|
|
230
|
+
helpers.testNullValue(project, ProjectModel, done)
|
|
231
|
+
})
|
|
232
|
+
it(`should throw an error when webhooks has array in headers`, (done) => {
|
|
233
|
+
project = JSON.parse(JSON.stringify(project))
|
|
234
|
+
project.webhooks.headers = ['array']
|
|
235
|
+
helpers.testNullValue(project, ProjectModel, done)
|
|
236
|
+
})
|
|
237
|
+
|
|
227
238
|
it(`should throw an error when firebaseApiKey is null`, (done) => {
|
|
228
239
|
project = JSON.parse(JSON.stringify(project))
|
|
229
240
|
project.firebaseApiKey = null
|
package/package.json
CHANGED
package/schemas/Integration.js
CHANGED
|
@@ -10,41 +10,41 @@ const MParticleSchema = new mongoose.Schema({
|
|
|
10
10
|
msg:'androidApiKey should be a non-empty string, found ${VALUE}'
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
|
-
|
|
13
|
+
androidSecretKey: {
|
|
14
14
|
type: String,
|
|
15
15
|
validate:{
|
|
16
16
|
validator:apiKeyValidator,
|
|
17
|
-
msg:'
|
|
17
|
+
msg:'androidSecretKey should be a non-empty string, found ${VALUE}'
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
-
|
|
20
|
+
iosApiKey:{
|
|
21
21
|
type:String,
|
|
22
22
|
validate:{
|
|
23
23
|
validator:apiKeyValidator,
|
|
24
|
-
msg:'
|
|
24
|
+
msg:'iosApiKey should be a non-empty string, found ${VALUE}'
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
|
-
|
|
27
|
+
iosSecretKey:{
|
|
28
28
|
type:String,
|
|
29
29
|
validate:{
|
|
30
30
|
validator:apiKeyValidator,
|
|
31
|
-
msg:'
|
|
31
|
+
msg:'iosSecretKey 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
39
|
validate: [{
|
|
40
40
|
validator: mParticleValidator,
|
|
41
|
-
msg: 'either of the two field combinations is mandatory: androidApiKey &
|
|
41
|
+
msg: 'either of the two field combinations is mandatory: androidApiKey & androidSecretKey OR iosApiKey & iosSecretKey'
|
|
42
42
|
},{
|
|
43
43
|
validator:iOSPairValidator,
|
|
44
|
-
msg: 'both
|
|
44
|
+
msg: 'both iosSecretKey and iosApiKey are required'
|
|
45
45
|
},{
|
|
46
46
|
validator:androidPairValidator,
|
|
47
|
-
msg: 'both
|
|
47
|
+
msg: 'both androidSecretKey and androidApiKey are required'
|
|
48
48
|
}
|
|
49
49
|
],
|
|
50
50
|
required: true
|
|
@@ -55,25 +55,25 @@ function apiKeyValidator(value){
|
|
|
55
55
|
return !(typeof value !=='string' || value.trim() === '')
|
|
56
56
|
}
|
|
57
57
|
function iOSPairValidator(value){
|
|
58
|
-
const {
|
|
59
|
-
const isIOSApiKeyProvided = (
|
|
60
|
-
const isIOSSecretProvided = (
|
|
58
|
+
const {iosApiKey,iosSecretKey} = value
|
|
59
|
+
const isIOSApiKeyProvided = (iosApiKey !== undefined)
|
|
60
|
+
const isIOSSecretProvided = (iosSecretKey !== undefined)
|
|
61
61
|
|
|
62
62
|
return isIOSApiKeyProvided === isIOSSecretProvided
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
function androidPairValidator(value){
|
|
66
|
-
const {androidApiKey,
|
|
66
|
+
const {androidApiKey,androidSecretKey} = value
|
|
67
67
|
const isAndroidApiKeyProvided = (androidApiKey !== undefined)
|
|
68
|
-
const isAndroidSecretProvided = (
|
|
68
|
+
const isAndroidSecretProvided = (androidSecretKey !== undefined)
|
|
69
69
|
|
|
70
70
|
return isAndroidApiKeyProvided === isAndroidSecretProvided
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
function mParticleValidator(value) {
|
|
74
|
-
const { androidApiKey,
|
|
75
|
-
const isAndroidPairProvided = ((androidApiKey !== undefined)&&(
|
|
76
|
-
const isIosPairProvided = ((
|
|
74
|
+
const { androidApiKey,androidSecretKey, iosApiKey,iosSecretKey } = value;
|
|
75
|
+
const isAndroidPairProvided = ((androidApiKey !== undefined)&&(androidSecretKey !==undefined))
|
|
76
|
+
const isIosPairProvided = ((iosApiKey !== undefined)&&(iosSecretKey !==undefined))
|
|
77
77
|
|
|
78
78
|
return isIosPairProvided || isAndroidPairProvided;
|
|
79
79
|
}
|
package/schemas/Webhook.js
CHANGED
|
@@ -16,7 +16,18 @@ let WebhookSchema = new mongoose.Schema({
|
|
|
16
16
|
|
|
17
17
|
// https://bluedotinnovation.atlassian.net/browse/BP-1500 -- Limiting headers to 1
|
|
18
18
|
function validateHeaderlength (headers) {
|
|
19
|
-
|
|
19
|
+
// handles the case of headers being a primitive value
|
|
20
|
+
if(typeof headers !== 'object' || Array.isArray(headers)){
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
const headerKeys = Object.keys(headers)
|
|
24
|
+
// only one key-value pair is allowed
|
|
25
|
+
if(headerKeys.length > 1){
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
const key = headerKeys[0]
|
|
29
|
+
// the value should be present
|
|
30
|
+
return headers[key]
|
|
20
31
|
}
|
|
21
32
|
|
|
22
33
|
module.exports = WebhookSchema
|