@bluedot-innovation/models 3.0.6-alpha.1 → 3.0.6-alpha.2
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/__tests__/beacon/beacon.data.json +1 -0
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.spec.js +10 -9
- package/__tests__/project/project.data.json +2 -1
- package/__tests__/user/user.data.js +1 -0
- package/__tests__/zone/zone.data.json +1 -0
- package/__tests__/zone/zone.geofeatures.spec.js +10 -10
- package/models/Project.js +5 -1
- package/models/User.js +5 -2
- package/models/Zone.js +5 -1
- package/models/ZoneBeacon.js +1 -0
- package/package.json +1 -1
|
@@ -3,8 +3,8 @@ let mongoose = require('mongoose')
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
5
|
let ZoneBeaconModel = require('../../../Models').ZoneBeacon(mongoose)
|
|
6
|
-
let
|
|
7
|
-
let
|
|
6
|
+
let describe = require('mocha').describe
|
|
7
|
+
let it = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
9
9
|
|
|
10
10
|
let assert = chai.assert
|
|
@@ -19,11 +19,12 @@ beforeEach(() => {
|
|
|
19
19
|
zoneBeacon = JSON.parse(JSON.stringify(require('./zoneBeacon.data.json')))
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
describe('ZoneBeacon', () => {
|
|
23
|
+
describe('Valid ZoneBeacon', () => {
|
|
24
|
+
it('should validate a valid zoneBeacon ', (done) => {
|
|
25
25
|
const ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
|
|
26
26
|
ZoneBeacon.validate((err, res) => {
|
|
27
|
+
console.log("err", err)
|
|
27
28
|
assert.notExists(res)
|
|
28
29
|
assert(err === null, 'err should equals null')
|
|
29
30
|
done()
|
|
@@ -31,8 +32,8 @@ testCase('ZoneBeacon', () => {
|
|
|
31
32
|
})
|
|
32
33
|
})
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
describe('Invalid ZoneBeacon', () => {
|
|
36
|
+
it('should not validate a zoneBeacon with invalid ZoneBeacon', (done) => {
|
|
36
37
|
delete zoneBeacon[rules.requiredFields[0]]
|
|
37
38
|
let ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
|
|
38
39
|
ZoneBeacon.validate((err, res) => {
|
|
@@ -41,10 +42,10 @@ testCase('ZoneBeacon', () => {
|
|
|
41
42
|
done()
|
|
42
43
|
})
|
|
43
44
|
})
|
|
44
|
-
|
|
45
|
+
describe('check each required property of the model and validate that it is present', () => {
|
|
45
46
|
let requiredFields = rules.requiredFields
|
|
46
47
|
requiredFields.map((i) => {
|
|
47
|
-
|
|
48
|
+
it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
48
49
|
// delete i from geofeatures' zoneBeacon child
|
|
49
50
|
delete zoneBeacon[i]
|
|
50
51
|
let ZoneBeacon = new ZoneBeaconModel(zoneBeacon)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"_id": "11d57188-269a-4028-8034-1c08b76ed6a8",
|
|
2
3
|
"state": "ACTIVE",
|
|
3
4
|
"nextRuleUpdateInterval": 3600,
|
|
4
5
|
"lastUpdateTime": "2018-02-14T04:12:02.103Z",
|
|
@@ -11,4 +12,4 @@
|
|
|
11
12
|
"enabled": true
|
|
12
13
|
},
|
|
13
14
|
"firebaseApiKey": "88888888-4444-4444-4444-121212121212"
|
|
14
|
-
}
|
|
15
|
+
}
|
|
@@ -3,8 +3,8 @@ let mongoose = require('mongoose')
|
|
|
3
3
|
mongoose.Promise = global.Promise
|
|
4
4
|
|
|
5
5
|
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
6
|
-
let
|
|
7
|
-
let
|
|
6
|
+
let describe = require('mocha').describe
|
|
7
|
+
let it = require('mocha').it
|
|
8
8
|
let chai = require('chai')
|
|
9
9
|
let assert = chai.assert
|
|
10
10
|
let mocha = require('mocha')
|
|
@@ -27,12 +27,12 @@ beforeEach(() => {
|
|
|
27
27
|
delete zone.actions
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
describe('Zone - Action', () => {
|
|
31
|
+
describe('Valid Zone - Action', () => {
|
|
32
|
+
it('should not throw an error when a valid geofeature is instantiated within a zone', (done) => {
|
|
33
33
|
let Zone = new ZoneModel(zone)
|
|
34
34
|
Zone.validate((err, res) => {
|
|
35
|
-
console.log(err)
|
|
35
|
+
console.log('brasa', err)
|
|
36
36
|
assert.notExists(res)
|
|
37
37
|
assert(err === null, 'err should be null')
|
|
38
38
|
done()
|
|
@@ -40,8 +40,8 @@ testCase('Zone - Action', () => {
|
|
|
40
40
|
})
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
describe('Invalid Zone - Action', () => {
|
|
44
|
+
it('should throw an error when an invalid geofeature is instantiated within a zone', (done) => {
|
|
45
45
|
delete zone.geofeatures[0].name
|
|
46
46
|
let Zone = new ZoneModel(zone)
|
|
47
47
|
Zone.validate((err, res) => {
|
|
@@ -51,7 +51,7 @@ testCase('Zone - Action', () => {
|
|
|
51
51
|
done()
|
|
52
52
|
})
|
|
53
53
|
})
|
|
54
|
-
|
|
54
|
+
it('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', (done) => {
|
|
55
55
|
delete zone.geofeatures[0].minor
|
|
56
56
|
let Zone = new ZoneModel(zone)
|
|
57
57
|
Zone.validate((err, res) => {
|
|
@@ -61,7 +61,7 @@ testCase('Zone - Action', () => {
|
|
|
61
61
|
done()
|
|
62
62
|
})
|
|
63
63
|
})
|
|
64
|
-
|
|
64
|
+
it('should throw an error when an no geofeature is instantiated within a zone', (done) => {
|
|
65
65
|
zone.geofeatures = []
|
|
66
66
|
let Zone = new ZoneModel(zone)
|
|
67
67
|
Zone.validate((err, res) => {
|
package/models/Project.js
CHANGED
|
@@ -14,7 +14,11 @@ let helpers = require('../helpers')
|
|
|
14
14
|
let WebhookSchema = require('../schemas/Webhook')
|
|
15
15
|
|
|
16
16
|
let ProjectSchema = new mongoose.Schema({
|
|
17
|
-
_id: {
|
|
17
|
+
_id: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true,
|
|
20
|
+
validator: helpers.validateUUIDv4
|
|
21
|
+
},
|
|
18
22
|
apiKey: {type: String, default: uuidv4}, // Backwards compatability
|
|
19
23
|
state: {type: String, default: StateEnum.active},
|
|
20
24
|
nextRuleUpdateInterval: {
|
package/models/User.js
CHANGED
|
@@ -8,10 +8,13 @@ const mongoose = require('mongoose')
|
|
|
8
8
|
const patcher = require('mongoose-json-patch')
|
|
9
9
|
const helpers = require('../helpers')
|
|
10
10
|
const ProjectPermission = require('../schemas/ProjectPermission')
|
|
11
|
-
const uuidv4 = require('uuid/v4')
|
|
12
11
|
|
|
13
12
|
let UserSchema = new mongoose.Schema({
|
|
14
|
-
_id: {
|
|
13
|
+
_id: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true,
|
|
16
|
+
validator: helpers.validateUUIDv4
|
|
17
|
+
},
|
|
15
18
|
username: {
|
|
16
19
|
type: String,
|
|
17
20
|
required: true,
|
package/models/Zone.js
CHANGED
|
@@ -45,7 +45,11 @@ let geofeatureSchema = new Schema({},
|
|
|
45
45
|
{ discriminatorKey: 'type', _id: false })
|
|
46
46
|
|
|
47
47
|
let zoneSchema = new Schema({
|
|
48
|
-
_id: {
|
|
48
|
+
_id: {
|
|
49
|
+
type: String,
|
|
50
|
+
required: true,
|
|
51
|
+
validator: helpers.validateUUIDv4
|
|
52
|
+
},
|
|
49
53
|
name: {type: String, required: [true, 'name is required']},
|
|
50
54
|
minimumRetriggerTime: {
|
|
51
55
|
type: Number,
|
package/models/ZoneBeacon.js
CHANGED
package/package.json
CHANGED