@bluedot-innovation/models 6.1.2-alpha.3 → 6.1.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/.gitlab-ci.yml CHANGED
@@ -59,7 +59,7 @@ create_dev_indexes:
59
59
  - master
60
60
 
61
61
  script:
62
- - DB_NAME=$DB_NAME MONGO_DB_URI="$DEV_MONGO_DB_URI" node utils/dbInitialiser.js
62
+ - MONGO_DB_URI=$DEV_MONGO_DB_URI make deploy-db-changes
63
63
 
64
64
  # Create any newly required indexes in the production dbs
65
65
  create_production_indexes:
@@ -68,8 +68,10 @@ create_production_indexes:
68
68
  - infrastructure
69
69
  when: manual
70
70
  allow_failure: false
71
+ only:
72
+ - master
71
73
 
72
74
  script:
73
- - DB_NAME=$DB_NAME MONGO_DB_URI="$AU_MONGO_DB_URI" node utils/dbInitialiser.js
74
- - DB_NAME=$DB_NAME MONGO_DB_URI="$EU_MONGO_DB_URI" node utils/dbInitialiser.js
75
- - DB_NAME=$DB_NAME MONGO_DB_URI="$US_MONGO_DB_URI" node utils/dbInitialiser.js
75
+ - MONGO_DB_URI="$AU_MONGO_DB_URI" make deploy-db-changes
76
+ - MONGO_DB_URI="$EU_MONGO_DB_URI" make deploy-db-changes
77
+ - MONGO_DB_URI="$US_MONGO_DB_URI" make deploy-db-changes
package/Makefile ADDED
@@ -0,0 +1,21 @@
1
+ pre:
2
+ rm -rf node_modules
3
+ npm ci
4
+
5
+ test: pre
6
+ npm test
7
+
8
+ test-coverage: pre
9
+ npm run test:coverage
10
+
11
+ deploy-db-changes:
12
+
13
+ ifndef DB_NAME
14
+ $(error 'DB_NAME is not set')
15
+ endif
16
+
17
+ ifndef MONGO_DB_URI
18
+ $(error 'MONGO_DB_URI is not set')
19
+ endif
20
+
21
+ node utils/dbInitialiser.js
@@ -106,42 +106,20 @@ describe('Zone', () => {
106
106
  })
107
107
  })
108
108
 
109
- it('should save without errors when eta.destinationId is set and there is a single polygon geofeature', (done) => {
110
- zone.eta = {
111
- "destinationId": "test-destination-id"
112
- }
113
- zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polygon$/))
114
- let Zone = new ZoneModel(zone)
115
- Zone.validate((err, res) => {
116
- assert.notExists(res)
117
- assert.notExists(err)
118
- done()
119
- })
120
- })
109
+ const validEtaGeofeatureTypes = ['boundingBox', 'circle', 'polygon']
121
110
 
122
- it('should save without errors when eta.destinationId is set and there is a single boundingBox geofeature', (done) => {
123
- zone.eta = {
124
- "destinationId": "test-destination-id"
125
- }
126
- zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^boundingBox$/))
127
- let Zone = new ZoneModel(zone)
128
- Zone.validate((err, res) => {
129
- assert.notExists(res)
130
- assert.notExists(err)
131
- done()
132
- })
133
- })
134
- it('should save without errors when eta.destinationId is set and there is a single circle geofeature', (done) => {
135
-
136
- zone.eta = {
137
- "destinationId": "test-destination-id"
138
- }
139
- zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^circle$/))
140
- let Zone = new ZoneModel(zone)
141
- Zone.validate((err, res) => {
142
- assert.notExists(res)
143
- assert.notExists(err)
144
- done()
111
+ validEtaGeofeatureTypes.map(type => {
112
+ it(`should save without errors when eta.destinationId is set and there is a single ${type} geofeature`, (done) => {
113
+ zone.eta = {
114
+ "destinationId": "test-destination-id"
115
+ }
116
+ zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(new RegExp(type)))
117
+ let Zone = new ZoneModel(zone)
118
+ Zone.validate((err, res) => {
119
+ assert.notExists(res)
120
+ assert.notExists(err)
121
+ done()
122
+ })
145
123
  })
146
124
  })
147
125
  })
@@ -448,34 +426,25 @@ describe('Zone', () => {
448
426
  let Zone = new ZoneModel(zone)
449
427
  Zone.validate((err, res) => {
450
428
  assert.exists(err, 'err object should exist')
451
- assert.match(err.message, /(destinationId must be no more than 128 characters long)/i)
429
+ assert.match(err.message, /(destinationId must be less than 129 characters long)/i)
452
430
  done()
453
431
  })
454
432
  })
455
433
 
456
- it('should throw an error when eta.destinationId is set and there is a single geoline geofeature', (done) => {
457
- zone.eta = {
458
- "destinationId": "test-destination-id"
459
- }
460
- zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^geoline$/))
461
- let Zone = new ZoneModel(zone)
462
- Zone.validate((err, res) => {
463
- assert.exists(err, 'err object should exist')
464
- assert.match(err.message, /(destinationId cannot be set on zones with a geoline or beacon)/i)
465
- done()
466
- })
467
- })
434
+ const invalidEtaGeofeatures = ['geoline', 'beacon']
468
435
 
469
- it('should throw an error when eta.destinationId is set and there is a single beacon geofeature', (done) => {
470
- zone.eta = {
471
- "destinationId": "test-destination-id"
472
- }
473
- zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^beacon$/))
474
- let Zone = new ZoneModel(zone)
475
- Zone.validate((err, res) => {
476
- assert.exists(err, 'err object should exist')
477
- assert.match(err.message, /(destinationId cannot be set on zones with a geoline or beacon)/i)
478
- done()
436
+ invalidEtaGeofeatures.map(type => {
437
+ it(`should throw an error when eta.destinationId is set and there is a single ${type} geofeature`, (done) => {
438
+ zone.eta = {
439
+ "destinationId": "test-destination-id"
440
+ }
441
+ zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(new RegExp(type)))
442
+ let Zone = new ZoneModel(zone)
443
+ Zone.validate((err, res) => {
444
+ assert.exists(err, 'err object should exist')
445
+ assert.match(err.message, /(destinationId cannot be set on zones with a geoline or beacon)/i)
446
+ done()
447
+ })
479
448
  })
480
449
  })
481
450
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "6.1.2-alpha.3",
3
+ "version": "6.1.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",
@@ -3,7 +3,7 @@ let helpers = require('../helpers')
3
3
 
4
4
  let ZoneEtaSchema = new mongoose.Schema({
5
5
  destinationId: {type: String, validate: [
6
- { validator: helpers.validateEtaDestinationIdLength, msg: 'destinationId must be no more than 128 characters long' },
6
+ { validator: helpers.validateEtaDestinationIdLength, msg: 'destinationId must be less than 129 characters long' },
7
7
  { validator: helpers.validateEtaDestinationSingleGeofeature, msg: 'destinationId can only be set on zones with a single geofeature' },
8
8
  { validator: helpers.validateEtaDestinationIdGeofeatureType, msg: 'destinationId cannot be set on zones with a geoline or beacon' }
9
9
  ]}