@bluedot-innovation/models 5.1.17 → 5.1.20

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,12 @@
1
+ ## 5.1.20
2
+ - Validate projectId when posting a zone
3
+
4
+ ## 5.1.19
5
+ - Lowercase incoming tags and remove duplicates
6
+
7
+ ## 5.1.18
8
+ - Add status field to TestInstance
9
+
1
10
  ## 5.1.17
2
11
  - Add validation for `txPower` to Beacon collection
3
12
 
@@ -85,6 +85,18 @@ describe('Zone', () => {
85
85
  done()
86
86
  })
87
87
  })
88
+
89
+ it('should set tags to lowercase and remove the duplicated tag', (done) => {
90
+ zone.tags = ["TAG", 1, "TaG", 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()
99
+ })
88
100
  })
89
101
 
90
102
  describe('Invalid Zone ', () => {
@@ -254,6 +266,16 @@ describe('Zone', () => {
254
266
  helpers.testNullValue(zone, ZoneModel, done)
255
267
  })
256
268
 
269
+ it('should throw an error when projectId is invalid', (done) => {
270
+ zone.projectId = "invalid id"
271
+ let Zone = new ZoneModel(zone)
272
+ Zone.validate((err, res) => {
273
+ assert.exists(err, 'err object should exist')
274
+ assert.match(err.message, /(Invalid Project Id)/i)
275
+ done()
276
+ })
277
+ })
278
+
257
279
  describe('should throw an error when any of the values of the array contains a falsy value', () => {
258
280
  let arrayTypeFields = rules.arrayTypeFields
259
281
 
@@ -4,6 +4,7 @@
4
4
  */
5
5
  let mongoose = require('mongoose')
6
6
  let StateEnum = require('@bluedot-innovation/enums').StateEnum
7
+ let TestStatusEnum = require('@bluedot-innovation/enums').TestStatusEnum
7
8
 
8
9
  let TestInstanceSchema = new mongoose.Schema(
9
10
  {
@@ -19,6 +20,7 @@ let TestInstanceSchema = new mongoose.Schema(
19
20
  creationTime: {type: Date, default: Date.now},
20
21
  lastUpdateTime: {type: Date, default: Date.now},
21
22
  state: {type: String, default: StateEnum.ACTIVE},
23
+ status: {type: String, default: TestStatusEnum.PLANNED},
22
24
  isValid: {type: Boolean, default: true},
23
25
  comments: String,
24
26
  isProduction: Boolean,
package/models/Zone.js CHANGED
@@ -37,6 +37,10 @@ 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 = (tags) => {
41
+ return [...new Set(tags.map(tag => typeof tag === 'string' ? tag.toLowerCase(): tag))]
42
+ }
43
+
40
44
  let actionSchema = new Schema({},
41
45
  { discriminatorKey: 'type', _id: false })
42
46
 
@@ -59,7 +63,7 @@ let zoneSchema = new Schema({
59
63
  message: '{VALUE} is not a number'
60
64
  }
61
65
  },
62
- tags: {type: [String], validate: helpers.validateNotNull},
66
+ tags: {type: [String], set : tagsFormation, validate: helpers.validateNotNull},
63
67
  conditions: {
64
68
  type: [conditionSchema]
65
69
  },
@@ -76,7 +80,7 @@ let zoneSchema = new Schema({
76
80
  customData: {type: Schema.Types.Mixed, validate: customDataValidators},
77
81
  creationTime: {type: Date, default: Date.now},
78
82
  lastUpdateTime: {type: Date, default: Date.now},
79
- projectId: {type: String, required: true},
83
+ projectId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, message: 'Invalid Project Id.'}},
80
84
  state: {type: String, default: StateEnum.ACTIVE, select: false},
81
85
  accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}}
82
86
  }, {collection: 'zone'})
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "5.1.17",
3
+ "version": "5.1.20",
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",
@@ -28,7 +28,7 @@
28
28
  "sinon": "^4.1.2"
29
29
  },
30
30
  "dependencies": {
31
- "@bluedot-innovation/enums": "2.1.4",
31
+ "@bluedot-innovation/enums": "2.1.5",
32
32
  "@bluedot-innovation/mongoose-json-patch": "0.0.6",
33
33
  "deep-equal": "^1.0.1",
34
34
  "fast-deep-equal": "^2.0.1",