@bluedot-innovation/models 5.1.49 → 5.1.51

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,9 @@
1
+ ## 5.1.51
2
+ - Add secret keys to mParticle
3
+
4
+ ## 5.1.50
5
+ - Add mParticle to Integration
6
+
1
7
  ## 5.1.49
2
8
  - Add integrations to Project
3
9
 
@@ -14,5 +14,12 @@
14
14
  }
15
15
  },
16
16
  "firebaseApiKey": "88888888-4444-4444-4444-121212121212",
17
- "apiKey": "88888888-4444-4444-4444-123412341234"
18
- }
17
+ "apiKey": "88888888-4444-4444-4444-123412341234",
18
+ "integrations":{
19
+ "mParticle": {
20
+ "androidApiKey": "us1-c5e6eefe90fe704aba0a7d2daa00baaa",
21
+ "androidSecret": "eZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN",
22
+ "iOSApiKey": "us1-a5e6eefe90fe704aba0a7d2daa00baaa",
23
+ "iOSSecret": "fZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN"
24
+ }
25
+ }}
@@ -61,6 +61,74 @@ testCase('Project', () => {
61
61
  done()
62
62
  })
63
63
  })
64
+ testCase('mparticle integration check', () => {
65
+ assertions('should throw an error if the mparticle integration has empty key ', (done) => {
66
+
67
+ project.integrations.mParticle.androidApiKey = null
68
+
69
+ let Project = new ProjectModel(project)
70
+ Project.validate((err, res) => {
71
+ assert.exists(err)
72
+ assert.match(err.message, /androidApiKey should be a non-empty string/)
73
+ done()
74
+ })
75
+ })
76
+ assertions('should throw an error if the mparticle integration has a key with empty string ', (done) => {
77
+
78
+ project.integrations.mParticle.iOSApiKey = ''
79
+ let Project = new ProjectModel(project)
80
+ Project.validate((err, res) => {
81
+ assert.exists(err)
82
+ assert.match(err.message, /iOSApiKey should be a non-empty string/)
83
+ done()
84
+ })
85
+ })
86
+ assertions('should throw an error if the mparticle integration has a secret key with empty string ', (done) => {
87
+
88
+ project.integrations.mParticle.iOSSecret = ''
89
+ let Project = new ProjectModel(project)
90
+ Project.validate((err, res) => {
91
+ assert.exists(err)
92
+ assert.match(err.message, /iOSSecret should be a non-empty string/)
93
+ done()
94
+ })
95
+ })
96
+ assertions('should throw an error if the mparticle integration misses both keys ', (done) => {
97
+
98
+ delete project.integrations.mParticle.iOSApiKey
99
+ delete project.integrations.mParticle.androidApiKey
100
+
101
+ let Project = new ProjectModel(project)
102
+ Project.validate((err, res) => {
103
+ assert.exists(err)
104
+ assert.match(err.message, /either of the two field combinations is mandatory/)
105
+ done()
106
+ })
107
+ })
108
+ assertions('should throw an error if the mparticle integration misses both secret keys ', (done) => {
109
+
110
+ delete project.integrations.mParticle.iOSSecret
111
+ delete project.integrations.mParticle.androidSecret
112
+
113
+ let Project = new ProjectModel(project)
114
+ Project.validate((err, res) => {
115
+ assert.exists(err)
116
+ assert.match(err.message, /either of the two field combinations is mandatory/)
117
+ done()
118
+ })
119
+ })
120
+ assertions('should validate if the mparticle integration has only Android key ', (done) => {
121
+
122
+ delete project.integrations.mParticle.androidApiKey
123
+ delete project.integrations.mParticle.androidSecret
124
+
125
+ let Project = new ProjectModel(project)
126
+ Project.validate((err, res) => {
127
+ assert.notExists(res)
128
+ done()
129
+ })
130
+ })
131
+ })
64
132
  testCase('recursive property check', () => {
65
133
  let requiredFields = rules.requiredFields
66
134
  requiredFields.map((i) => {
package/models/Project.js CHANGED
@@ -11,6 +11,7 @@ let uuidv4 = require('uuid/v4')
11
11
  let patcher = require('@bluedot-innovation/mongoose-json-patch')
12
12
  let helpers = require('../helpers')
13
13
 
14
+ let IntegrationSchema = require('../schemas/Integration')
14
15
  let WebhookSchema = require('../schemas/Webhook')
15
16
  let iosConfig = require('../schemas/IosConfig')
16
17
  let androidConfig = require('../schemas/AndroidConfig')
@@ -39,7 +40,7 @@ let ProjectSchema = new mongoose.Schema({
39
40
  }, // http://collab.bluedot.io/display/PD/Remote+configuration => https://bluedotinnovation.atlassian.net/wiki/spaces/ENG/pages/223150126/Remote+Config+details
40
41
  firebaseApiKey: {type: String, validate: helpers.validateNotNull},
41
42
  apiKey: {type: String},
42
- integrations: Schema.Types.Mixed
43
+ integrations: IntegrationSchema
43
44
  },
44
45
  {collection: 'project'})
45
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "5.1.49",
3
+ "version": "5.1.51",
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",
@@ -0,0 +1,60 @@
1
+ let mongoose = require("mongoose");
2
+
3
+
4
+
5
+ const MParticleSchema = new mongoose.Schema({
6
+ androidApiKey: {
7
+ type: String,
8
+ validate:{
9
+ validator:apiKeyValidator,
10
+ msg:'androidApiKey should be a non-empty string, found ${VALUE}'
11
+ }
12
+ },
13
+ androidSecret: {
14
+ type: String,
15
+ validate:{
16
+ validator:apiKeyValidator,
17
+ msg:'androidSecret should be a non-empty string, found ${VALUE}'
18
+ }
19
+ },
20
+ iOSApiKey:{
21
+ type:String,
22
+ validate:{
23
+ validator:apiKeyValidator,
24
+ msg:'iOSApiKey should be a non-empty string, found ${VALUE}'
25
+ }
26
+ },
27
+ iOSSecret:{
28
+ type:String,
29
+ validate:{
30
+ validator:apiKeyValidator,
31
+ msg:'iOSSecret should be a non-empty string, found ${VALUE}'
32
+ }
33
+ }
34
+ })
35
+
36
+ const IntegrationSchema = new mongoose.Schema({
37
+ mParticle: {
38
+ type: MParticleSchema,
39
+ validate: {
40
+ validator: mParticleValidator,
41
+ msg: 'either of the two field combinations is mandatory: androidApiKey & androidSecret OR iOSApiKey & iOSSecret'
42
+ },
43
+ required: true
44
+ }
45
+ });
46
+ function apiKeyValidator(value){
47
+ // check if the value is a non-empty string
48
+ return !(typeof value !=='string' || value.trim() === '')
49
+
50
+ }
51
+ function mParticleValidator(value) {
52
+ const { androidApiKey,androidSecret, iOSApiKey,iOSSecret } = value;
53
+
54
+ const isAndroidKeyProvided = (typeof androidApiKey !== "undefined" && typeof androidSecret !=="undefined")
55
+ const isIOSKeyProvided = (typeof iOSApiKey !== "undefined" && typeof iOSSecret !== "undefined")
56
+
57
+ return isAndroidKeyProvided || isIOSKeyProvided;
58
+ }
59
+
60
+ module.exports = IntegrationSchema