@bluedot-innovation/models 2.0.8-alpha.1 → 2.0.9
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 +3 -0
- package/__tests__/user/user.data.js +7 -1
- package/__tests__/user/user.spec.js +36 -11
- package/models/User.js +5 -4
- package/package.json +2 -3
- package/schemas/ProjectPermission.js +20 -0
- package/models/Fence.js +0 -20
- package/models/GeoFence.js +0 -21
- package/models/Geofeature.js +0 -24
package/CHANGELOG.md
CHANGED
|
@@ -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
|
|
6
|
-
let
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
43
|
-
|
|
43
|
+
describe('Invalid User', () => {
|
|
44
|
+
describe('recursive property check', () => {
|
|
44
45
|
let requiredFields = rules.requiredFields
|
|
45
46
|
requiredFields.forEach((requiredField) => {
|
|
46
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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:
|
|
36
|
+
projectPermissions: [ProjectPermission],
|
|
36
37
|
accountId: {
|
|
37
38
|
type: String,
|
|
38
39
|
required: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "Models.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,13 +22,12 @@
|
|
|
22
22
|
"eslint-plugin-promise": "^3.6.0",
|
|
23
23
|
"eslint-plugin-standard": "^3.0.1",
|
|
24
24
|
"mocha": "^4.0.1",
|
|
25
|
-
"mockgoose": "^7.3.3",
|
|
26
25
|
"nyc": "^11.3.0",
|
|
27
26
|
"sinon": "^4.1.2"
|
|
28
27
|
},
|
|
29
28
|
"dependencies": {
|
|
30
29
|
"@bluedot-innovation/enums": "2.0.2",
|
|
31
|
-
"lodash.clonedeep": "
|
|
30
|
+
"lodash.clonedeep": "4.5.0",
|
|
32
31
|
"mongoose": "^4.13.9",
|
|
33
32
|
"mongoose-error-helper": "0.0.2",
|
|
34
33
|
"mongoose-json-patch": "^1.1.1",
|
|
@@ -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
|
package/models/Fence.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Arun on 10/09/2014.
|
|
3
|
-
* Copyright : Bluedot Innovations.
|
|
4
|
-
* Owner :
|
|
5
|
-
*/
|
|
6
|
-
let mongoose = require('mongoose')
|
|
7
|
-
const Schema = mongoose.Schema
|
|
8
|
-
|
|
9
|
-
let FenceSchema = new mongoose.Schema({
|
|
10
|
-
'_id': {type: String},
|
|
11
|
-
'creationTime': {type: Date, default: Date.now},
|
|
12
|
-
'lastUpdateTime': {type: Date, default: Date.now},
|
|
13
|
-
'type': {type: String, default: 'Feature'},
|
|
14
|
-
'dataSource': {type: String, select: false, default: 'openApi'},
|
|
15
|
-
'geometry': {type: Schema.Types.Mixed, default: {}}
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
let Fence = mongoose.model('Fence', FenceSchema)
|
|
19
|
-
|
|
20
|
-
module.exports = Fence
|
package/models/GeoFence.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Arun on 10/09/2014.
|
|
3
|
-
* Copyright : Bluedot Innovations.
|
|
4
|
-
* Owner :
|
|
5
|
-
*/
|
|
6
|
-
let mongoose = require('mongoose')
|
|
7
|
-
|
|
8
|
-
let FenceSchema = new mongoose.Schema({
|
|
9
|
-
_id: {type: String},
|
|
10
|
-
'geometry': {
|
|
11
|
-
'type': { type: String, required: true },
|
|
12
|
-
'coordinates': {type: Array, required: true}
|
|
13
|
-
},
|
|
14
|
-
'fenceId': String,
|
|
15
|
-
'fenceName': String
|
|
16
|
-
},
|
|
17
|
-
{collection: 'GeoFence'})
|
|
18
|
-
|
|
19
|
-
let GeoFence = mongoose.model('GeoFence', FenceSchema)
|
|
20
|
-
|
|
21
|
-
module.exports = GeoFence
|
package/models/Geofeature.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Andrew on 7/06/2016.
|
|
3
|
-
* Copyright : Bluedot Innovations.
|
|
4
|
-
* Owner :
|
|
5
|
-
*/
|
|
6
|
-
let mongoose = require('mongoose')
|
|
7
|
-
let Schema = mongoose.Schema
|
|
8
|
-
|
|
9
|
-
let GeofeatureSchema = new Schema({
|
|
10
|
-
geometry: Schema.Types.Mixed,
|
|
11
|
-
referenceId: String,
|
|
12
|
-
apiKey: String,
|
|
13
|
-
zoneId: String,
|
|
14
|
-
type: String,
|
|
15
|
-
name: String,
|
|
16
|
-
beaconType: String,
|
|
17
|
-
creationTime: {type: Date, default: Date.now},
|
|
18
|
-
lastUpdateTime: {type: Date, default: Date.now}
|
|
19
|
-
},
|
|
20
|
-
{ collection: 'geofeature' })
|
|
21
|
-
|
|
22
|
-
let Geofeature = mongoose.model('Geofeature', GeofeatureSchema)
|
|
23
|
-
|
|
24
|
-
module.exports = Geofeature
|