@bluedot-innovation/models 8.4.1 → 8.5.0

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,9 @@
1
+ ## 8.5.0
2
+ - Add activeTtl and finalTtl to project.hello and remove registrationTtl
3
+
4
+ ## 8.4.2
5
+ - Validate Hello report recipient emails
6
+
1
7
  ## 8.4.1
2
8
  - Add reportConfigurations to Project model
3
9
 
@@ -102,7 +102,8 @@
102
102
  "isochroneBracketInterval": [60, 120, 300]
103
103
  },
104
104
  "hello": {
105
- "registrationTtl": 86400,
105
+ "activeTtl": 604800,
106
+ "finalTtl": 86400,
106
107
  "ssoLinkingCode": "HGDUS69SDJJ0"
107
108
  },
108
109
  "reportConfigurations": [
@@ -273,12 +273,22 @@ describe('Project', () => {
273
273
  })
274
274
  })
275
275
 
276
- it('should not validate if hello.registrationTtl is not an integer', (done) => {
277
- project.hello.registrationTtl = 1.5
276
+ it('should not validate if hello.activeTtl is not an integer', (done) => {
277
+ project.hello.activeTtl = 1.5
278
278
  let Project = new ProjectModel(project)
279
279
  Project.validate((err, res) => {
280
280
  assert.exists(err)
281
- assert.match(err.message, /hello.registrationTtl should be an integer number/)
281
+ assert.match(err.message, /hello.activeTtl should be an integer number/)
282
+ done()
283
+ })
284
+ })
285
+
286
+ it('should not validate if hello.finalTtl is not an integer', (done) => {
287
+ project.hello.finalTtl = 1.5
288
+ let Project = new ProjectModel(project)
289
+ Project.validate((err, res) => {
290
+ assert.exists(err)
291
+ assert.match(err.message, /hello.finalTtl should be an integer number/)
282
292
  done()
283
293
  })
284
294
  })
@@ -852,6 +862,16 @@ describe('Project', () => {
852
862
  done()
853
863
  })
854
864
  })
865
+
866
+ it('Should throw an error when recipients are invalid', (done) => {
867
+ project.reportConfigurations[0].recipients = "abc@example.com, invalid-1, invalid-2@example"
868
+ let Project = new ProjectModel(project)
869
+ Project.validate((err, res) => {
870
+ assert.exists(err)
871
+ assert.match(err.message, /Invalid email address\(es\): invalid-1,invalid-2@example/)
872
+ done()
873
+ })
874
+ })
855
875
  })
856
876
  })
857
877
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "8.4.1",
3
+ "version": "8.5.0",
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",
@@ -2,7 +2,8 @@ let mongoose = require('mongoose')
2
2
  const helpers = require('../helpers')
3
3
 
4
4
  let ProjectHelloSchema = new mongoose.Schema({
5
- registrationTtl: {type: Number, validate: { validator: Number.isInteger, msg: 'hello.registrationTtl should be an integer number' }},
5
+ activeTtl: {type: Number, validate: { validator: Number.isInteger, msg: 'hello.activeTtl should be an integer number' }},
6
+ finalTtl: {type: Number, validate: { validator: Number.isInteger, msg: 'hello.finalTtl should be an integer number' }},
6
7
  ssoLinkingCode: {type: String, validate: {validator: helpers.validateSsoLinkingCode, msg: 'SSO linking code must be a 12 character capital alphanumeric text'}}
7
8
  }, {
8
9
  _id: false
@@ -1,5 +1,6 @@
1
1
  let mongoose = require('mongoose')
2
2
  const moment = require('moment-timezone')
3
+ const helpers = require('../helpers')
3
4
 
4
5
  function validateReportDay(reportDay) {
5
6
  if (this.frequency === 'weekly' && (!Number.isInteger(reportDay) || !(reportDay >= 0 && reportDay <= 6))) {
@@ -17,12 +18,27 @@ function validateTimeZone(timezone) {
17
18
  return true
18
19
  }
19
20
 
21
+ function validateRecipients(value) {
22
+ const invalidEmails = []
23
+ const recipients = value.split(',').map((email) => email.trim())
24
+ recipients.forEach((email) => {
25
+ if (!helpers.validateEmail(email)) {
26
+ invalidEmails.push(email)
27
+ }
28
+ });
29
+
30
+ if (invalidEmails.length) {
31
+ throw new Error(`Invalid email address(es): ${invalidEmails.join(",")}`)
32
+ }
33
+ return true
34
+ }
35
+
20
36
  let ReportConfigurationSchema = new mongoose.Schema({
21
37
  type: {type: String, enum: ['hello'], required: true},
22
38
  frequency: {type: String, enum: ['daily', 'weekly', 'monthly'], required: true},
23
39
  reportDay: {type: Number, validate: {validator: validateReportDay}},
24
40
  timezone: {type: String, required: true, validate: { validator: validateTimeZone, msg: 'Invalid timezone'}},
25
- recipients: {type: String, required: true}
41
+ recipients: {type: String, required: true, validate: {validator: validateRecipients}}
26
42
  }, {
27
43
  _id: false
28
44
  })