@bluedot-innovation/models 2.0.7-alpha.7 → 2.0.9-alpha.1

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,10 @@
1
+ ## 2.0.9
2
+ - Validation on `projectPermissions` in user model
3
+
4
+ ## 2.0.8
5
+ - Removed `description` from `zone` model.
6
+ - Added `triggerOnExit` to `zone` model.
7
+
1
8
  ## 2.0.7
2
9
  - All `guid`'s changed to `_id`'s
3
10
 
@@ -9,5 +9,11 @@ module.exports = {
9
9
  lastUpdateTime: '2018-02-14T04:12:02.103Z',
10
10
  creationTime: '2018-02-14T04:12:02.103Z',
11
11
  isAdmin: true,
12
- accountId: '37ac5be3-60ec-4fb7-9f88-a4f6e8895f81'
12
+ accountId: '37ac5be3-60ec-4fb7-9f88-a4f6e8895f81',
13
+ projectPermissions: [
14
+ {
15
+ permissionLevel: 'READ_WRITE',
16
+ projectId: '1dc621a1-7980-410b-839b-4bed63600139'
17
+ }
18
+ ]
13
19
  }
@@ -2,8 +2,8 @@ let mongoose = require('mongoose')
2
2
 
3
3
  let UserModel = require('../../Models').User(mongoose)
4
4
  let UserModelBuiltInMongoose = require('../../Models').User()
5
- let testCase = require('mocha').describe
6
- let assertions = require('mocha').it
5
+ let describe = require('mocha').describe
6
+ let it = require('mocha').it
7
7
  let rules = require('./user.rules.js')
8
8
  let chai = require('chai')
9
9
  let assert = chai.assert
@@ -16,19 +16,20 @@ beforeEach(() => {
16
16
  user = require('./user.data.js')
17
17
  })
18
18
 
19
- testCase('User', () => {
20
- testCase('Valid User ', () => {
21
- assertions('should validate a valid user when initializing the model with an external mongoose instance', (done) => {
19
+ describe('User', () => {
20
+ describe('Valid User ', () => {
21
+ it('should validate a valid user when initializing the model with an external mongoose instance', (done) => {
22
22
  let User = new UserModel(user)
23
23
 
24
24
  User.validate((err, res) => {
25
25
  assert.notExists(res)
26
26
  assert(err === null, 'err equals null')
27
+
27
28
  done()
28
29
  })
29
30
  })
30
31
 
31
- assertions('should validate a valid user', (done) => {
32
+ it('should validate a valid user', (done) => {
32
33
  let User = new UserModelBuiltInMongoose(user)
33
34
 
34
35
  User.validate((err, res) => {
@@ -39,11 +40,11 @@ testCase('User', () => {
39
40
  })
40
41
  })
41
42
 
42
- testCase('Invalid User', () => {
43
- testCase('recursive property check', () => {
43
+ describe('Invalid User', () => {
44
+ describe('recursive property check', () => {
44
45
  let requiredFields = rules.requiredFields
45
46
  requiredFields.forEach((requiredField) => {
46
- assertions(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, (done) => {
47
+ it(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, (done) => {
47
48
  user = JSON.parse(JSON.stringify(user))
48
49
  delete user[requiredField]
49
50
  let User = new UserModel(user)
@@ -59,12 +60,12 @@ testCase('User', () => {
59
60
  })
60
61
  })
61
62
 
62
- testCase('recursive invalid entry check', () => {
63
+ describe('recursive invalid entry check', () => {
63
64
  const { customValidators } = rules
64
65
 
65
66
  customValidators.forEach((customValidator) => {
66
67
  customValidator.invalidInputs.forEach((invalidInput) => {
67
- assertions(`should throw an error with property '${customValidator.name}' if '${customValidator.name}' is invalid => ${customValidator.name} = ${invalidInput}`, (done) => {
68
+ it(`should throw an error with property '${customValidator.name}' if '${customValidator.name}' is invalid => ${customValidator.name} = ${invalidInput}`, (done) => {
68
69
  user = JSON.parse(JSON.stringify(user))
69
70
  user[customValidator.name] = invalidInput
70
71
  let User = new UserModel(user)
@@ -80,4 +81,28 @@ testCase('User', () => {
80
81
  })
81
82
  })
82
83
  })
84
+
85
+ describe('projectPermissions:', () => {
86
+ it('should fail if projectId is invalid', (done) => {
87
+ user = JSON.parse(JSON.stringify(user))
88
+ user.projectPermissions[0].projectId = '8b1b5cb5-3c7b-452a-b9a7-'
89
+ const User = new UserModel(user)
90
+
91
+ User.validate((err, res) => {
92
+ assert.match(err, /(projectId not in UUID v4 format)/i)
93
+ done()
94
+ })
95
+ })
96
+
97
+ it('should fail if permissionLevel is invalid', (done) => {
98
+ user = JSON.parse(JSON.stringify(user))
99
+ user.projectPermissions[0].permissionLevel = 'INVALID'
100
+ const User = new UserModel(user)
101
+
102
+ User.validate((err, res) => {
103
+ assert.match(err, /(not a valid enum value)/i)
104
+ done()
105
+ })
106
+ })
107
+ })
83
108
  })
package/models/User.js CHANGED
@@ -3,10 +3,11 @@
3
3
  * Copyright : Bluedot Innovation.
4
4
  */
5
5
 
6
- let StateEnum = require('@bluedot-innovation/enums').StateEnum
7
- let mongoose = require('mongoose')
8
- let patcher = require('mongoose-json-patch')
6
+ const StateEnum = require('@bluedot-innovation/enums').StateEnum
7
+ const mongoose = require('mongoose')
8
+ const patcher = require('mongoose-json-patch')
9
9
  const helpers = require('../helpers')
10
+ const ProjectPermission = require('../schemas/ProjectPermission')
10
11
 
11
12
  let UserSchema = new mongoose.Schema({
12
13
  username: {
@@ -32,7 +33,7 @@ let UserSchema = new mongoose.Schema({
32
33
  lastUpdateTime: {type: Date, default: Date.now},
33
34
  isAdmin: {type: Boolean, required: true},
34
35
  secret: String,
35
- projectPermissions: Array,
36
+ projectPermissions: [ProjectPermission],
36
37
  accountId: {
37
38
  type: String,
38
39
  required: true,
package/models/Zone.js CHANGED
@@ -59,8 +59,8 @@ let ZoneSchema = new Schema({
59
59
  type: [geofeatureSchema],
60
60
  required: true
61
61
  },
62
+ triggerOnExit: {type: Boolean, default: false},
62
63
  customData: {type: Schema.Types.Mixed},
63
- description: {type: String, default: ''},
64
64
  creationTime: {type: Date, default: Date.now},
65
65
  lastUpdateTime: {type: Date, default: Date.now},
66
66
  projectId: {type: String, required: [true, 'projectId is required']},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "2.0.7-alpha.7",
3
+ "version": "2.0.9-alpha.1",
4
4
  "description": "",
5
5
  "main": "Models.js",
6
6
  "scripts": {
@@ -0,0 +1,20 @@
1
+ const mongoose = require('mongoose')
2
+ const helpers = require('../helpers')
3
+ const PermissionsEnum = require('@bluedot-innovation/enums').PermissionsEnum
4
+
5
+ const ProjectPermissionSchema = new mongoose.Schema({
6
+ permissionLevel: {
7
+ type: String,
8
+ required: true,
9
+ enum: [PermissionsEnum.READ_WRITE, PermissionsEnum.READ]
10
+ },
11
+ projectId: {
12
+ type: String,
13
+ validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'projectId not in UUID v4 format'}
14
+ }
15
+ }, {
16
+ _id: false,
17
+ __v: false
18
+ })
19
+
20
+ module.exports = ProjectPermissionSchema