@bluedot-innovation/models 3.0.5 → 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/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.0.6
2
+ - Require `_id`'s instead of defaulting them
3
+
1
4
  ## 3.0.5
2
5
  - `User` - Remove password field
3
6
 
@@ -1,4 +1,5 @@
1
1
  {
2
+ "_id": "d1257188-269a-4028-8034-1c08b76ed6a8",
2
3
  "type": "beacon",
3
4
  "name": "create beacon",
4
5
  "proximityUUID": "23a01af0-232a-4518-9c0e-323fb773f5ef",
@@ -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 testCase = require('mocha').describe
7
- let assertions = require('mocha').it
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
- testCase('ZoneBeacon', () => {
23
- testCase('Valid ZoneBeacon', () => {
24
- assertions('should validate a valid zoneBeacon ', (done) => {
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
- testCase('Invalid ZoneBeacon', () => {
35
- assertions('should not validate a zoneBeacon with invalid ZoneBeacon', (done) => {
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
- testCase('check each required property of the model and validate that it is present', () => {
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
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
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
+ }
@@ -1,4 +1,5 @@
1
1
  module.exports = {
2
+ _id: 'e3257188-269a-4028-8034-1c08b76ed6a8',
2
3
  username: 'test@bluedot.io',
3
4
  email: 'test@bluedot.io',
4
5
  password: 'jfmamjasond',
@@ -1,4 +1,5 @@
1
1
  {
2
+ "_id": "e41b2623-8ce9-4b03-909d-68f4e3ad444a",
2
3
  "name": "TDD zone",
3
4
  "minimumRetriggerTime": "60",
4
5
  "checkout": true,
@@ -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 testCase = require('mocha').describe
7
- let assertions = require('mocha').it
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
- testCase('Zone - Action', () => {
31
- testCase('Valid Zone - Action', () => {
32
- assertions('should not throw an error when a valid geofeature is instantiated within a zone', (done) => {
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
- testCase('Invalid Zone - Action', () => {
44
- assertions('should throw an error when an invalid geofeature is instantiated within a zone', (done) => {
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
- assertions('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', (done) => {
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
- assertions('should throw an error when an no geofeature is instantiated within a zone', (done) => {
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/Beacon.js CHANGED
@@ -4,9 +4,14 @@ let Point = require('../schemas/Point')
4
4
  let PointGeometry = require('../schemas/PointGeometry')
5
5
  let uuidv4 = require('uuid/v4')
6
6
  let patcher = require('mongoose-json-patch')
7
+ let helpers = require('../helpers')
7
8
 
8
9
  let schema = {
9
- _id: {type: String, default: uuidv4},
10
+ _id: {
11
+ type: String,
12
+ required: true,
13
+ validator: helpers.validateUUIDv4
14
+ },
10
15
  name: {type: String, required: [true, 'name is required.']},
11
16
  description: {type: String, default: ''},
12
17
  creationTime: {type: Date, default: Date.now},
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: {type: String, default: uuidv4},
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: {type: String, default: uuidv4},
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: {type: String, default: uuidv4},
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,
@@ -9,6 +9,7 @@ delete schema.state
9
9
  delete schema.creationTime
10
10
  delete schema.lastUpdateTime
11
11
  delete schema.__v
12
+ delete schema._id
12
13
 
13
14
  schema.proximity = {
14
15
  type: String,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "3.0.5",
3
+ "version": "3.0.6-alpha.2",
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",