@bluedot-innovation/models 5.1.27-alpha.6 → 5.1.27

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.
@@ -23,10 +23,4 @@ helpers.testNullValue = (docObject, model, callback) => {
23
23
  })
24
24
  }
25
25
 
26
- helpers.removeDuplicatedTags = zone => {
27
- if (zone.tags && zone.tags.length) {
28
- zone.tags = [...new Set(zone.tags.map(tag => typeof tag === 'string' ? tag.toLowerCase() : tag))]
29
- }
30
- }
31
-
32
26
  module.exports = helpers
@@ -86,12 +86,16 @@ describe('Zone', () => {
86
86
  })
87
87
  })
88
88
 
89
- it('should set tags to lowercase and remove the duplicated tag', () => {
89
+ it('should set tags to lowercase and remove the duplicated tag', (done) => {
90
90
  zone.tags = ["TAG", 1, "TaG", 1]
91
- helpers.removeDuplicatedTags(zone)
92
- assert.strictEqual(zone.tags.length, 2)
93
- assert.strictEqual(zone.tags[0], "tag")
94
- assert.strictEqual(zone.tags[1], 1)
91
+
92
+ let Zone = new ZoneModel(zone)
93
+ assert.exists(Zone._doc)
94
+ assert.exists(Zone._doc.tags)
95
+ assert.strictEqual(Zone._doc.tags.length, 2)
96
+ assert.strictEqual(Zone._doc.tags[0], "tag")
97
+ assert.strictEqual(Zone._doc.tags[1], "1")
98
+ done()
95
99
  })
96
100
  })
97
101
 
package/models/Zone.js CHANGED
@@ -37,10 +37,8 @@ let customDataValidators = [
37
37
  {validator: helpers.isValidCustomDataCount, msg: 'Only 5 custom data fields are allowed to be added per zone'}
38
38
  ];
39
39
 
40
- const tagsFormation = (zone) => {
41
- if (zone.tags && zone.tags.length) {
42
- zone.tags = [...new Set(zone.tags.map(tag => typeof tag === 'string' ? tag.toLowerCase() : String(tag)))]
43
- }
40
+ const tagsFormation = (tags) => {
41
+ return [...new Set(tags.map(tag => typeof tag === 'string' ? tag.toLowerCase(): tag))]
44
42
  }
45
43
 
46
44
  let actionSchema = new Schema({},
@@ -86,7 +84,7 @@ let zoneSchema = new Schema({
86
84
  message: '{VALUE} is not a number'
87
85
  }
88
86
  },
89
- tags: {type: [String], validate: helpers.validateNotNull},
87
+ tags: {type: [String], set : tagsFormation, validate: helpers.validateNotNull},
90
88
  conditions: {
91
89
  type: [conditionSchema],
92
90
  validate: {
@@ -147,7 +145,6 @@ zoneSchema.pre('validate', function(next) {
147
145
  if( result )
148
146
  return next(result)
149
147
  }
150
- tagsFormation(this)
151
148
  next()
152
149
  }).catch((error) => console.log('Validation error ', error));
153
150
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "5.1.27-alpha.6",
3
+ "version": "5.1.27",
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",