@bluedot-innovation/models 5.1.52 → 5.1.53

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 CHANGED
@@ -1,3 +1,6 @@
1
+ ## 5.1.53
2
+ - change validation mesages of mParticle
3
+
1
4
  ## 5.1.52
2
5
  - fix secret keys validation of mParticle
3
6
 
@@ -135,7 +135,18 @@ testCase('Project', () => {
135
135
  let Project = new ProjectModel(project)
136
136
  Project.validate((err, res) => {
137
137
  assert.exists(err)
138
- assert.match(err.message, /either of the two field combinations is mandatory/)
138
+ assert.match(err.message, /both iOSSecret and iOSApiKey are required/)
139
+ done()
140
+ })
141
+ })
142
+ assertions('should throw an error if the mparticle integration has valid Ios key pair, but no android secret ', (done) => {
143
+
144
+ delete project.integrations.mParticle.androidSecret
145
+
146
+ let Project = new ProjectModel(project)
147
+ Project.validate((err, res) => {
148
+ assert.exists(err)
149
+ assert.match(err.message, /both androidSecret and androidApiKey are required/)
139
150
  done()
140
151
  })
141
152
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "5.1.52",
3
+ "version": "5.1.53",
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",
@@ -36,33 +36,44 @@ const MParticleSchema = new mongoose.Schema({
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)
61
+
62
+ return isIOSApiKeyProvided === isIOSSecretProvided
63
+ }
64
+
65
+ function androidPairValidator(value){
66
+ const {androidApiKey,androidSecret} = value
67
+ const isAndroidApiKeyProvided = (androidApiKey !== undefined)
68
+ const isAndroidSecretProvided = (androidSecret !== undefined)
49
69
 
70
+ return isAndroidApiKeyProvided === isAndroidSecretProvided
50
71
  }
72
+
51
73
  function mParticleValidator(value) {
52
74
  const { androidApiKey,androidSecret, iOSApiKey,iOSSecret } = value;
53
- let isAndroidPairProvided = false
54
- let isIosPairProvided = false
55
- if((androidApiKey === undefined) !== (androidSecret ===undefined)){
56
- return false
57
- } else if((androidApiKey !== undefined)){
58
- isAndroidPairProvided=true
59
- }
60
- if((iOSApiKey === undefined) !== (iOSSecret ===undefined)){
61
- return false
62
- } else if((iOSApiKey !== undefined)){
63
- isIosPairProvided=true
64
- }
65
-
75
+ const isAndroidPairProvided = ((androidApiKey !== undefined)&&(androidSecret !==undefined))
76
+ const isIosPairProvided = ((iOSApiKey !== undefined)&&(iOSSecret !==undefined))
66
77
 
67
78
  return isIosPairProvided || isAndroidPairProvided;
68
79
  }