@bluedot-innovation/models 3.0.6-alpha.1 → 3.0.6-alpha.3

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,5 +1,5 @@
1
1
  ## 3.0.6
2
- - Require `_id`'s instead of defaulting them
2
+ - `txPower` no longer mandatory
3
3
 
4
4
  ## 3.0.5
5
5
  - `User` - Remove password field
@@ -5,8 +5,8 @@
5
5
  "property": "beaconType",
6
6
  "pairings": [
7
7
  {"value": "ios", "requiredFields": ["major", "minor"]},
8
- {"value": "android", "requiredFields": ["txPower", "macAddress"]},
9
- {"value": "both", "requiredFields": ["major", "minor", "txPower", "macAddress"]}
8
+ {"value": "android", "requiredFields": ["macAddress"]},
9
+ {"value": "both", "requiredFields": ["major", "minor", "macAddress"]}
10
10
  ]
11
11
  }
12
12
  ]
@@ -3,8 +3,8 @@ let mongoose = require('mongoose')
3
3
  mongoose.Promise = global.Promise
4
4
 
5
5
  let BeaconModel = require('../../Models').Beacon(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,9 +19,9 @@ beforeEach(() => {
19
19
  beacon = JSON.parse(JSON.stringify(require('./beacon.data.json')))
20
20
  })
21
21
 
22
- testCase('Beacon', () => {
23
- testCase('Valid Beacon', () => {
24
- assertions('should validate a valid beacon', (done) => {
22
+ describe('Beacon', () => {
23
+ describe('Valid Beacon', () => {
24
+ it('should validate a valid beacon', (done) => {
25
25
  const Beacon = new BeaconModel(beacon)
26
26
  Beacon.validate((err, res) => {
27
27
  assert.notExists(res)
@@ -29,7 +29,7 @@ testCase('Beacon', () => {
29
29
  done()
30
30
  })
31
31
  })
32
- assertions('should accept a valid API Key and customer API Key', (done) => {
32
+ it('should accept a valid API Key and customer API Key', (done) => {
33
33
  beacon.apiKey = '23a01af0-232a-4518-9c0e-323fb773f5ef'
34
34
  beacon.customerApiKey = '23a01af0-232a-4518-9c0e-323fb773ffff'
35
35
  let Beacon = new BeaconModel(beacon)
@@ -41,8 +41,8 @@ testCase('Beacon', () => {
41
41
  })
42
42
  })
43
43
 
44
- testCase('Invalid Beacon', () => {
45
- assertions('should not validate a beacon with invalid Beacon', (done) => {
44
+ describe('Invalid Beacon', () => {
45
+ it('should not validate a beacon with invalid Beacon', (done) => {
46
46
  delete beacon[rules.requiredFields[0]]
47
47
  let Beacon = new BeaconModel(beacon)
48
48
  Beacon.validate((err, res) => {
@@ -51,12 +51,14 @@ testCase('Beacon', () => {
51
51
  done()
52
52
  })
53
53
  })
54
- testCase('check each required property of the model and validate that it is present', () => {
54
+
55
+ describe('check each required property of the model and validate that it is present', () => {
55
56
  let dependentRequiredFields = rules.dependentRequiredFields
56
- dependentRequiredFields.map((parent) => {
57
- parent.pairings.map((i) => {
58
- i.requiredFields.map((field) => {
59
- assertions(`should throw an error with property '${parent.property}' if '${i.value}' is selected and '${field}' is invalid`, (done) => {
57
+ dependentRequiredFields.forEach((parent) => {
58
+ console.log("parent", parent)
59
+ parent.pairings.forEach((i) => {
60
+ i.requiredFields.forEach((field) => {
61
+ it(`should throw an error with property '${parent.property}' if '${i.value}' is selected and '${field}' is invalid`, (done) => {
60
62
  // delete beacon[field] i.e. txPower from beacon
61
63
  delete beacon[field]
62
64
  // set required dependent field property
@@ -74,10 +76,11 @@ testCase('Beacon', () => {
74
76
  })
75
77
  })
76
78
  })
77
- testCase('check each required property of the model and validate that it is present', () => {
79
+
80
+ describe('check each required property of the model and validate that it is present', () => {
78
81
  let requiredFields = rules.requiredFields
79
- requiredFields.map((i) => {
80
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
82
+ requiredFields.forEach((i) => {
83
+ it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
81
84
  // delete i from geofeatures' beacon child
82
85
  delete beacon[i]
83
86
  let Beacon = new BeaconModel(beacon)
package/models/Beacon.js CHANGED
@@ -4,14 +4,9 @@ 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')
8
7
 
9
8
  let schema = {
10
- _id: {
11
- type: String,
12
- required: true,
13
- validator: helpers.validateUUIDv4
14
- },
9
+ _id: {type: String, default: uuidv4},
15
10
  name: {type: String, required: [true, 'name is required.']},
16
11
  description: {type: String, default: ''},
17
12
  creationTime: {type: Date, default: Date.now},
@@ -72,11 +67,11 @@ function validateBeaconType (v, magicCallback) {
72
67
  let bothRegex = new RegExp(/(both)/ig)
73
68
 
74
69
  if (androidRegex.test(beaconType)) {
75
- magicCallback((!!macAddress && !!txPower), 'Beacon type `Android` must have both mac address and tx power values')
70
+ magicCallback((!!macAddress), 'Beacon type `Android` must have a mac address')
76
71
  } else if (iosRegex.test(beaconType)) {
77
72
  magicCallback((!!minor && !!major), 'Beacon type `IOS` must have both minor and major values')
78
73
  } else if (bothRegex.test(beaconType)) {
79
- magicCallback((!!minor && !!major && !!txPower && !!macAddress), 'Beacon type `Both` must have all of minor, major, tx power, and mac address values')
74
+ magicCallback((!!minor && !!major && !!macAddress), 'Beacon type `Both` must have all of minor, major, and mac address values')
80
75
  } else {
81
76
  magicCallback(true)
82
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "3.0.6-alpha.1",
3
+ "version": "3.0.6-alpha.3",
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",