@bluedot-innovation/models 9.1.1 → 10.0.0-beta

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
+ ## 10.0.0
2
+ - BREAKING CHANGE - Upgrade to Mongoose 8
3
+
1
4
  ## 9.1.1
2
5
  - Reverted changes on 9.1.0 to remove UberEats integration from Project
3
6
 
@@ -18,48 +18,35 @@ beforeEach(() => {
18
18
 
19
19
  testCase('Account', () => {
20
20
  testCase('Valid Account ', () => {
21
- assertions('should validate a valid account when initializing the model with an external mongoose instance', (done) => {
21
+ assertions('should validate a valid account when initializing the model with an external mongoose instance', async () => {
22
22
  let Account = new AccountModel(account)
23
-
24
- Account.validate((err, res) => {
25
- assert.notExists(res)
26
- assert(err === null, 'err equals null')
27
- done()
28
- })
23
+ const res = await Account.validate()
24
+ assert.notExists(res)
29
25
 
30
26
  assert.deepEqual(JSON.parse(JSON.stringify(Account)), account, "All values should be present in Account model")
31
27
  })
32
28
 
33
- assertions('should validate a valid account', (done) => {
29
+ assertions('should validate a valid account', async () => {
34
30
  let Account = new AccountModelBuiltInMongoose(account)
35
31
 
36
- Account.validate((err, res) => {
37
- assert.notExists(res)
38
- assert(err === null, 'err equals null')
39
- done()
40
- })
32
+ const res = await Account.validate()
33
+ assert.notExists(res)
41
34
  })
42
35
 
43
- it('Should valid the account when CEMD whitelistedFields is null', (done) => {
36
+ it('Should valid the account when CEMD whitelistedFields is null', async () => {
44
37
  account = JSON.parse(JSON.stringify(account))
45
38
  account.features.cemdPersistence.whitelistedFields = null
46
39
  const Account = new AccountModel(account)
47
- Account.validate((err, res) => {
48
- assert.notExists(res)
49
- assert(err === null, 'err equals null')
50
- done()
51
- })
40
+ const res = await Account.validate()
41
+ assert.notExists(res)
52
42
  })
53
43
 
54
- it('Should valid the account when CEMD whitelistedFields is undefined', (done) => {
44
+ it('Should valid the account when CEMD whitelistedFields is undefined', async () => {
55
45
  account = JSON.parse(JSON.stringify(account))
56
46
  delete account.features.cemdPersistence.whitelistedFields
57
47
  const Account = new AccountModel(account)
58
- Account.validate((err, res) => {
59
- assert.notExists(res)
60
- assert(err === null, 'err equals null')
61
- done()
62
- })
48
+ const res = await Account.validate()
49
+ assert.notExists(res)
63
50
  })
64
51
  })
65
52
 
@@ -67,32 +54,31 @@ testCase('Account', () => {
67
54
  testCase('recursive property check', () => {
68
55
  let requiredFields = rules.requiredFields
69
56
  requiredFields.forEach((requiredField) => {
70
- assertions(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, (done) => {
57
+ assertions(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, async () => {
71
58
  account = JSON.parse(JSON.stringify(account))
72
59
  delete account[requiredField]
73
60
  let Account = new AccountModel(account)
74
- Account.validate((err, res) => {
75
- assert.notExists(res)
61
+ try {
62
+ await Account.validate()
63
+ } catch (err) {
76
64
  assert.exists(err, 'err object should exist')
77
65
  assert.isObject(err.errors)
78
66
  assert.nestedProperty(err, `errors.${requiredField}`, `error should have a ${requiredField} property`)
79
- done()
80
- })
67
+ }
81
68
  })
82
69
  })
83
70
  })
84
71
 
85
- assertions('should throw an error when Account has invalid type', (done) => {
72
+ assertions('should throw an error when Account has invalid type', async () => {
86
73
  let Account = new AccountModel(account)
87
74
  Account.type = "Invalid"
88
-
89
- Account.validate((err, res) => {
90
- assert.notExists(res)
75
+ try {
76
+ await Account.validate()
77
+ } catch (err) {
91
78
  assert.exists(err, 'err object should exist')
92
79
  assert.isObject(err.errors)
93
80
  assert.match(err.message, /`Invalid` is not a valid enum value for path `type`/)
94
- done()
95
- })
81
+ }
96
82
  })
97
83
  })
98
84
 
@@ -101,18 +87,17 @@ testCase('Account', () => {
101
87
 
102
88
  customValidators.forEach((customValidator) => {
103
89
  customValidator.invalidInputs.forEach((invalidInput) => {
104
- assertions(`should throw an error with property '${customValidator.name}' if '${customValidator.name}' is invalid => ${customValidator.name} = ${invalidInput}`, (done) => {
90
+ assertions(`should throw an error with property '${customValidator.name}' if '${customValidator.name}' is invalid => ${customValidator.name} = ${invalidInput}`, async () => {
105
91
  account = JSON.parse(JSON.stringify(account))
106
92
  account[customValidator.name] = invalidInput
107
93
  let Account = new AccountModel(account)
108
-
109
- Account.validate((err, res) => {
110
- assert.notExists(res)
94
+ try {
95
+ await Account.validate()
96
+ } catch (err) {
111
97
  assert.exists(err, 'err object should exist')
112
98
  assert.isObject(err.errors)
113
99
  assert.nestedProperty(err, `errors.${customValidator.name}`, `error should have a ${customValidator.name} property`)
114
- done()
115
- })
100
+ }
116
101
  })
117
102
  })
118
103
  })
@@ -123,16 +108,16 @@ testCase('Account', () => {
123
108
  const { requiredFields } = rules.sfmcIntegration;
124
109
 
125
110
  requiredFields.forEach((requiredField) => {
126
- assertions(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, (done) => {
111
+ assertions(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, async () => {
127
112
  account = JSON.parse(JSON.stringify(account))
128
113
  const sfmc = account.integrations.sfmc;
129
114
  delete sfmc[requiredField]
130
115
  let Account = new AccountModel(account)
131
- Account.validate((err, res) => {
132
- assert.notExists(res)
116
+ try {
117
+ await Account.validate()
118
+ } catch (err) {
133
119
  assert.exists(err, 'err object should exist')
134
- done()
135
- })
120
+ }
136
121
  })
137
122
  })
138
123
  })
@@ -22,72 +22,69 @@ beforeEach(() => {
22
22
 
23
23
  testCase('DayRangeCondition', () => {
24
24
  testCase('Valid DayRangeCondition', () => {
25
- assertions('should validate a valid dayRange', (done) => {
25
+ assertions('should validate a valid dayRange', async () => {
26
26
  let DayRangeCondition = new DayRangeModel(dayRange)
27
- DayRangeCondition.validate((err, res) => {
28
- assert.notExists(res)
29
- assert(err === null, 'err should equals null')
30
- done()
31
- })
27
+ const res = await DayRangeCondition.validate()
28
+ assert.notExists(res)
32
29
  })
33
30
  })
34
31
  testCase('Valid DayRangeCondition', () => {
35
- assertions('should validate a valid dayRange', (done) => {
32
+ assertions('should validate a valid dayRange', async () => {
36
33
  let DayRangeCondition = new DayRangeModelBuiltInSchema(dayRange)
37
- DayRangeCondition.validate((err, res) => {
38
- assert.notExists(res)
39
- assert(err === null, 'err should equals null')
40
- done()
41
- })
34
+ const res = await DayRangeCondition.validate()
35
+ assert.notExists(res)
42
36
  })
43
37
  })
44
38
 
45
39
  testCase('Invalid DayRangeCondition', () => {
46
- assertions('should not validate a dayRange with invalid DayRangeCondition', (done) => {
40
+ assertions('should not validate a dayRange with invalid DayRangeCondition', async () => {
47
41
  delete dayRange[rules.requiredFields[0]]
48
42
  let DayRangeCondition = new DayRangeModel(dayRange)
49
- DayRangeCondition.validate((err, res) => {
43
+ try {
44
+ await DayRangeCondition.validate()
45
+ } catch (err) {
50
46
  assert.exists(err, 'err object should exist')
51
47
  assert.isObject(err.errors)
52
- done()
53
- })
48
+ }
54
49
  })
55
50
 
56
- assertions('should not validate a dayRange with startDate < endDate', (done) => {
51
+ assertions('should not validate a dayRange with startDate < endDate', async () => {
57
52
  dayRange.endDate = '1990-11-14'
58
53
  let DayRangeCondition = new DayRangeModel(dayRange)
59
- DayRangeCondition.validate((err) => {
54
+ try {
55
+ await DayRangeCondition.validate()
56
+ } catch (err) {
60
57
  assert.exists(err, 'err object should exist')
61
58
  assert.isObject(err.errors)
62
59
  assert.match(err.message, /startDate.*less than.*endDate/i)
63
- done()
64
- })
60
+ }
65
61
  })
66
- assertions('should throw an error if both startDate and endDate are not provided', (done) => {
62
+ assertions('should throw an error if both startDate and endDate are not provided', async () => {
67
63
  delete dayRange.startDate
68
64
  delete dayRange.endDate
69
65
  let DayRangeCondition = new DayRangeModel(dayRange)
70
- DayRangeCondition.validate((err, res) => {
66
+ try {
67
+ await DayRangeCondition.validate()
68
+ } catch (err) {
71
69
  assert.exists(err, 'err object should exist')
72
70
  assert.isObject(err.errors)
73
- done()
74
- })
71
+ }
75
72
  })
76
73
 
77
74
  testCase('check each required property of the model and validate that it is present', () => {
78
75
  let requiredFields = rules.requiredFields
79
76
  requiredFields.map((i) => {
80
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
77
+ assertions(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
81
78
  // delete i from geofeatures' dayRange child
82
79
  delete dayRange[i]
83
80
  let DayRangeCondition = new DayRangeModel(dayRange)
84
- DayRangeCondition.validate((err, res) => {
85
- assert.notExists(res)
81
+ try {
82
+ await DayRangeCondition.validate()
83
+ } catch (err) {
86
84
  assert.exists(err, 'err object should exist')
87
85
  assert.isObject(err.errors)
88
86
  assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
89
- done()
90
- })
87
+ }
91
88
  })
92
89
  })
93
90
  })
@@ -22,49 +22,44 @@ beforeEach(() => {
22
22
 
23
23
  testCase('PercentageCrossedCondition', () => {
24
24
  testCase('Valid PercentageCrossedCondition', () => {
25
- assertions('should validate a valid travelPath ', (done) => {
25
+ assertions('should validate a valid travelPath ', async () => {
26
26
  let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
27
- PercentageCrossedCondition.validate((err, res) => {
28
- assert.notExists(res)
29
- assert(err === null, 'err should equals null')
30
- done()
31
- })
27
+ const res = await PercentageCrossedCondition.validate()
28
+ assert.notExists(res)
32
29
  })
33
30
  })
34
31
  testCase('Valid PercentageCrossedCondition', () => {
35
- assertions('should validate a valid travelPath ', (done) => {
32
+ assertions('should validate a valid travelPath ', async () => {
36
33
  let PercentageCrossedCondition = new TravelPathConditionModelBuiltInMongoose(travelPath)
37
- PercentageCrossedCondition.validate((err, res) => {
38
- assert.notExists(res)
39
- assert(err === null, 'err should equals null')
40
- done()
41
- })
34
+ const res = await PercentageCrossedCondition.validate()
35
+ assert.notExists(res)
42
36
  })
43
37
  })
44
38
  testCase('Invalid PercentageCrossedCondition', () => {
45
- assertions('should not validate a travelPath with invalid PercentageCrossedCondition', (done) => {
39
+ assertions('should not validate a travelPath with invalid PercentageCrossedCondition', async () => {
46
40
  delete travelPath[rules.requiredFields[0]]
47
41
  let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
48
- PercentageCrossedCondition.validate((err, res) => {
42
+ try {
43
+ await PercentageCrossedCondition.validate()
44
+ } catch (err) {
49
45
  assert.exists(err, 'err object should exist')
50
46
  assert.isObject(err.errors)
51
- done()
52
- })
47
+ }
53
48
  })
54
49
  testCase('check each required property of the model and validate that it is present', () => {
55
50
  let requiredFields = rules.requiredFields
56
51
  requiredFields.map((i) => {
57
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
52
+ assertions(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
58
53
  // delete i from geofeatures' travelPath child
59
54
  delete travelPath[i]
60
55
  let PercentageCrossedCondition = new TravelPathConditionModel(travelPath)
61
- PercentageCrossedCondition.validate((err, res) => {
62
- assert.notExists(res)
56
+ try {
57
+ await PercentageCrossedCondition.validate()
58
+ } catch (err) {
63
59
  assert.exists(err, 'err object should exist')
64
60
  assert.isObject(err.errors)
65
61
  assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
66
- done()
67
- })
62
+ }
68
63
  })
69
64
  })
70
65
  })
@@ -22,71 +22,68 @@ beforeEach(() => {
22
22
 
23
23
  testCase('SpeedCondition', () => {
24
24
  testCase('Valid SpeedCondition', () => {
25
- assertions('should validate a valid speedCondition ', (done) => {
25
+ assertions('should validate a valid speedCondition ', async () => {
26
26
  let SpeedCondition = new SpeedConditionModel(speedCondition)
27
- SpeedCondition.validate((err, res) => {
28
- assert.notExists(res)
29
- assert(err === null, 'err should equals null')
30
- done()
31
- })
27
+ const res = await SpeedCondition.validate()
28
+ assert.notExists(res)
32
29
  })
33
- assertions('should validate a valid speedCondition ', (done) => {
30
+ assertions('should validate a valid speedCondition ', async () => {
34
31
  let SpeedCondition = new SpeedConditionModelBuiltInMongoose(speedCondition)
35
- SpeedCondition.validate((err, res) => {
36
- assert.notExists(res)
37
- assert(err === null, 'err should equals null')
38
- done()
39
- })
32
+ const res = await SpeedCondition.validate()
33
+ assert.notExists(res)
40
34
  })
41
35
  })
42
36
 
43
37
  testCase('Invalid SpeedCondition', () => {
44
- assertions('should not validate a speedCondition with invalid SpeedCondition', (done) => {
38
+ assertions('should not validate a speedCondition with invalid SpeedCondition', async () => {
45
39
  delete speedCondition[rules.requiredFields[0]]
46
40
  let SpeedCondition = new SpeedConditionModel(speedCondition)
47
- SpeedCondition.validate((err, res) => {
41
+ try {
42
+ await SpeedCondition.validate()
43
+ } catch (err) {
48
44
  assert.exists(err, 'err object should exist')
49
45
  assert.isObject(err.errors)
50
- done()
51
- })
46
+ }
52
47
  })
53
- assertions('should throw an error when maxSpeed is less than 5 greater than minSpeed', (done) => {
48
+ assertions('should throw an error when maxSpeed is less than 5 greater than minSpeed', async () => {
54
49
  speedCondition.minimumSpeed = 10
55
50
  speedCondition.maximumSpeed = 11
56
51
  let SpeedCondition = new SpeedConditionModel(speedCondition)
57
- SpeedCondition.validate((err, res) => {
52
+ try {
53
+ await SpeedCondition.validate()
54
+ } catch (err) {
58
55
  assert.exists(err, 'err object should exist')
59
56
  assert.isObject(err.errors)
60
57
  assert.nestedProperty(err, `errors.maximumSpeed`, 'error should have a maximumSpeed property')
61
58
  assert.equal(err.errors.maximumSpeed.message, 'Maximum speed has to be at least 5 m/s greater than minimum speed')
62
- done()
63
- })
59
+ }
64
60
  })
65
- assertions('should throw an error when maxSpeed is less than 5 m/s', (done) => {
61
+ assertions('should throw an error when maxSpeed is less than 5 m/s', async () => {
66
62
  speedCondition.maximumSpeed = 4
67
63
  let SpeedCondition = new SpeedConditionModel(speedCondition)
68
- SpeedCondition.validate((err, res) => {
64
+ try {
65
+ await SpeedCondition.validate()
66
+ } catch (err) {
69
67
  assert.exists(err, 'err object should exist')
70
68
  assert.isObject(err.errors)
71
69
  assert.nestedProperty(err, `errors.maximumSpeed`, 'error should have a maximumSpeed property')
72
70
  assert.equal(err.errors.maximumSpeed.message, 'Maximum speed has to be at least 5 m/s')
73
- done()
74
- })
71
+ }
75
72
  })
76
73
  testCase('check each required property of the model and validate that it is present', () => {
77
74
  let requiredFields = rules.requiredFields
78
75
  requiredFields.map((i) => {
79
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
76
+ assertions(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
80
77
  // delete i from geofeatures' speedCondition child
81
78
  delete speedCondition[i]
82
79
  let SpeedCondition = new SpeedConditionModel(speedCondition)
83
- SpeedCondition.validate((err, res) => {
84
- assert.notExists(res)
80
+ try {
81
+ await SpeedCondition.validate()
82
+ } catch (err) {
85
83
  assert.exists(err, 'err object should exist')
86
84
  assert.isObject(err.errors)
87
85
  assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
88
- done()
89
- })
86
+ }
90
87
  })
91
88
  })
92
89
  })
@@ -21,45 +21,41 @@ beforeEach(() => {
21
21
 
22
22
  testCase('TimeOfDayRangeCondition', () => {
23
23
  testCase('Valid TimeOfDayRangeCondition', () => {
24
- assertions('should validate a valid timeActiveCondition ', (done) => {
24
+ assertions('should validate a valid timeActiveCondition ', async () => {
25
25
  let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
26
- TimeOfDayRangeCondition.validate((err, res) => {
27
- assert.notExists(res)
28
- assert(err === null, 'err should equals null')
29
- done()
30
- })
26
+ const res = await TimeOfDayRangeCondition.validate()
27
+ assert.notExists(res)
31
28
  })
32
- assertions('should validate a valid timeActiveCondition ', (done) => {
29
+ assertions('should validate a valid timeActiveCondition ', async () => {
33
30
  let TimeOfDayRangeCondition = new TimeActiveConditionModelBuiltInMongoose(timeActiveCondition)
34
- TimeOfDayRangeCondition.validate((err, res) => {
35
- assert.notExists(res)
36
- assert(err === null, 'err should equals null')
37
- done()
38
- })
31
+ const res = await TimeOfDayRangeCondition.validate()
32
+ assert.notExists(res)
39
33
  })
40
34
  })
41
35
 
42
36
  testCase('Invalid TimeOfDayRangeCondition', () => {
43
- assertions('should not validate a timeActiveCondition with invalid TimeOfDayRangeCondition', (done) => {
37
+ assertions('should not validate a timeActiveCondition with invalid TimeOfDayRangeCondition', async () => {
44
38
  delete timeActiveCondition[rules.requiredFields[0]]
45
39
  let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
46
- TimeOfDayRangeCondition.validate((err, res) => {
40
+ try {
41
+ await TimeOfDayRangeCondition.validate()
42
+ } catch (err) {
47
43
  assert.exists(err, 'err object should exist')
48
44
  assert.isObject(err.errors)
49
- done()
50
- })
45
+ }
51
46
  })
52
- assertions('should throw an error when toTime === fromTime', (done) => {
47
+ assertions('should throw an error when toTime === fromTime', async () => {
53
48
  timeActiveCondition.toTime = "00:30:00"
54
49
  timeActiveCondition.fromTime = "00:30:00"
55
50
  let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
56
- TimeOfDayRangeCondition.validate((err, res) => {
51
+ try {
52
+ await TimeOfDayRangeCondition.validate()
53
+ } catch (err) {
57
54
  assert.exists(err, 'err object should exist')
58
55
  assert.isObject(err.errors)
59
56
  assert.nestedProperty(err, `errors.toTime`, 'error should have a toTime property')
60
57
  assert.equal(err.errors.toTime, 'fromTime and toTime cannot be the same')
61
- done()
62
- })
58
+ }
63
59
  })
64
60
 
65
61
  testCase('recursive invalid time inputs check', () => {
@@ -67,17 +63,18 @@ testCase('TimeOfDayRangeCondition', () => {
67
63
 
68
64
  invalidTimes.map(i => {
69
65
  i.invalidInput.map(j => {
70
- assertions(`should throw an error with property '${i.name}' if '${i.name} is invalid => ${i.name} = ${j}'`, done => {
66
+ assertions(`should throw an error with property '${i.name}' if '${i.name} is invalid => ${i.name} = ${j}'`, async () => {
71
67
  timeActiveCondition = JSON.parse(JSON.stringify(timeActiveCondition))
72
68
  timeActiveCondition[i.name] = j
73
69
  let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
74
- TimeOfDayRangeCondition.validate((err, res) => {
75
- assert.exists(err, 'err object should exits')
70
+ try {
71
+ await TimeOfDayRangeCondition.validate()
72
+ } catch (err) {
73
+ assert.exists(err, 'err object should exist')
76
74
  assert.isObject(err.errors)
77
75
  assert.nestedProperty(err, `errors.${i.name}`, 'error should have a fromTime property')
78
76
  assert.include(err.errors[`${i.name}`].message, 'time format must be hh:mm:ss')
79
- done()
80
- })
77
+ }
81
78
  })
82
79
  })
83
80
  })
@@ -86,17 +83,17 @@ testCase('TimeOfDayRangeCondition', () => {
86
83
  testCase('check each required property of the model and validate that it is present', () => {
87
84
  let requiredFields = rules.requiredFields
88
85
  requiredFields.map((i) => {
89
- assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
86
+ assertions(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
90
87
  // delete i from geofeatures' timeActiveCondition child
91
88
  delete timeActiveCondition[i]
92
89
  let TimeOfDayRangeCondition = new TimeActiveConditionModel(timeActiveCondition)
93
- TimeOfDayRangeCondition.validate((err, res) => {
94
- assert.notExists(res)
90
+ try {
91
+ await TimeOfDayRangeCondition.validate()
92
+ } catch (err) {
95
93
  assert.exists(err, 'err object should exist')
96
94
  assert.isObject(err.errors)
97
95
  assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
98
- done()
99
- })
96
+ }
100
97
  })
101
98
  })
102
99
  })
@@ -20,81 +20,79 @@ beforeEach(() => {
20
20
 
21
21
  describe('TravelDirection', () => {
22
22
  describe('Valid TravelDirection', () => {
23
- it('should validate a valid travelDirectionCondition ', (done) => {
23
+ it('should validate a valid travelDirectionCondition ', async () => {
24
24
  let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
25
- TravelDirection.validate((err, res) => {
26
- assert.notExists(res)
27
- assert(err === null, 'err should equals null')
28
- done()
29
- })
25
+ const res = await TravelDirection.validate()
26
+ assert.notExists(res)
30
27
  })
31
- it('should validate a valid travelDirectionCondition ', (done) => {
28
+ it('should validate a valid travelDirectionCondition ', async () => {
32
29
  let TravelDirection = new TravelDirectionModelBuiltInMongoose(travelDirectionCondition)
33
- TravelDirection.validate((err, res) => {
34
- assert.notExists(res)
35
- assert(err === null, 'err should equals null')
36
- done()
37
- })
30
+ const res = await TravelDirection.validate()
31
+ assert.notExists(res)
38
32
  })
39
33
  })
40
34
 
41
35
  describe('Invalid TravelDirection', () => {
42
- it('should not validate a travelDirectionCondition with invalid TravelDirection', (done) => {
36
+ it('should not validate a travelDirectionCondition with invalid TravelDirection', async () => {
43
37
  delete travelDirectionCondition[rules.requiredFields[0]]
44
38
  let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
45
- TravelDirection.validate((err, res) => {
39
+ try {
40
+ await TravelDirection.validate()
41
+ } catch (err) {
46
42
  assert.exists(err, 'err object should exist')
47
43
  assert.isObject(err.errors)
48
- done()
49
- })
44
+ }
50
45
  })
51
- it('should throw an error when toAngle === fromAngle', (done) => {
46
+ it('should throw an error when toAngle === fromAngle', async () => {
52
47
  travelDirectionCondition.toAngle = 10
53
48
  travelDirectionCondition.fromAngle = 10
54
49
  let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
55
- TravelDirection.validate((err, res) => {
50
+ try {
51
+ await TravelDirection.validate()
52
+ } catch (err) {
56
53
  assert.exists(err, 'err object should exist')
57
54
  assert.isObject(err.errors)
58
55
  assert.nestedProperty(err, `errors.toAngle`, 'error should have a toAngle property')
59
- done()
60
- })
56
+ }
61
57
  })
62
- it('should throw an error when toAngle < 90 degrees from fromAngle (and toAngle < fromAngle)', (done) => {
58
+ it('should throw an error when toAngle < 90 degrees from fromAngle (and toAngle < fromAngle)', async () => {
63
59
  travelDirectionCondition.toAngle = 5
64
60
  travelDirectionCondition.fromAngle = 10
65
61
  let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
66
- TravelDirection.validate((err, res) => {
62
+ try {
63
+ await TravelDirection.validate()
64
+ } catch (err) {
67
65
  assert.exists(err, 'err object should exist')
68
66
  assert.isObject(err.errors)
69
67
  assert.nestedProperty(err, `errors.toAngle`, 'error should have a toAngle property')
70
- done()
71
- })
68
+ }
72
69
  })
73
- it('should throw an error when toAngle < 90 degrees from fromAngle (and toAngle > fromAngle)', (done) => {
70
+ it('should throw an error when toAngle < 90 degrees from fromAngle (and toAngle > fromAngle)', async () => {
74
71
  travelDirectionCondition.toAngle = 10
75
72
  travelDirectionCondition.fromAngle = 5
76
73
  let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
77
- TravelDirection.validate((err, res) => {
74
+ try {
75
+ await TravelDirection.validate()
76
+ } catch (err) {
78
77
  assert.exists(err, 'err object should exist')
79
78
  assert.isObject(err.errors)
80
79
  assert.nestedProperty(err, `errors.toAngle`, 'error should have a toAngle property')
81
- done()
82
- })
80
+ }
83
81
  })
84
82
  describe('check each required property of the model and validate that it is present', () => {
85
83
  let requiredFields = rules.requiredFields
86
84
  requiredFields.map((i) => {
87
- it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
85
+ it(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
88
86
  // delete i from geofeatures' travelDirectionCondition child
89
87
  delete travelDirectionCondition[i]
90
88
  let TravelDirection = new TravelDirectionModel(travelDirectionCondition)
91
- TravelDirection.validate((err, res) => {
92
- assert.notExists(res)
89
+ try {
90
+ await TravelDirection.validate()
91
+ } catch (err) {
93
92
  assert.exists(err, 'err object should exist')
94
93
  assert.isObject(err.errors)
95
94
  assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
96
- done()
97
- })
95
+ }
98
96
  })
99
97
  })
100
98
  })