@bluedot-innovation/models 9.1.1 → 10.0.0-beta-1

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.
@@ -10,21 +10,18 @@ const cumulativeRulesRequest = {
10
10
  }
11
11
 
12
12
  testCase('Creating new cumulativeRulesRequest document ', () => {
13
- assertions('validates data types and structure of cumulativeRulesRequest document', (done) => {
13
+ assertions('validates data types and structure of cumulativeRulesRequest document', async () => {
14
14
  const createCumulativeRulesRequests = new CumulativeRulesRequests(cumulativeRulesRequest)
15
15
  assert(createCumulativeRulesRequests._id)
16
16
  assert(createCumulativeRulesRequests._id.match(/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/))
17
- createCumulativeRulesRequests.validate()
18
- .then(() => {
19
- assert(true)
20
- done()
21
- }).catch(err => {
22
- console.log('Errors found:')
23
- for (let key of Object.keys(err.errors)) {
24
- console.log(err.errors[key].message)
25
- }
26
- assert(false)
27
- done(err)
28
- })
17
+ try {
18
+ await createCumulativeRulesRequests.validate()
19
+ assert(true)
20
+ } catch (err) {
21
+ for (let key of Object.keys(err.errors)) {
22
+ console.log(err.errors[key].message)
23
+ }
24
+ assert(false)
25
+ }
29
26
  })
30
27
  })
@@ -20,59 +20,58 @@ beforeEach(() => {
20
20
 
21
21
  testCase('DailyStats', () => {
22
22
  testCase('Valid DailyStats document', () => {
23
- assertions('should validate a valid DailyStats document ', (done) => {
23
+ assertions('should validate a valid DailyStats document ', async () => {
24
24
  let DailyStats = new DailyStatsModel(dailyStats)
25
- DailyStats.validate((err, res) => {
26
- assert.notExists(res)
27
- assert(err === null, 'err should equals null')
28
- done()
29
- })
25
+ const res = await DailyStats.validate()
26
+ assert.notExists(res)
27
+
30
28
  })
31
- assertions('should validate a valid DailyStats document ', (done) => {
29
+ assertions('should validate a valid DailyStats document ', async () => {
32
30
  let DailyStats = new DailyStatsModelBuiltInMongoose(dailyStats)
33
- DailyStats.validate((err, res) => {
34
- assert.notExists(res)
35
- assert(err === null, 'err should equals null')
36
- done()
37
- })
31
+ const res = await DailyStats.validate()
32
+ assert.notExists(res)
38
33
  })
39
- assertions('should not accept a invalid accountId', (done) => {
34
+ assertions('should not accept a invalid accountId', async () => {
40
35
  dailyStats.accountId = 'invalid-accountId'
41
36
  let DailyStats = new DailyStatsModel(dailyStats)
42
- DailyStats.validate((err, res) => {
43
- assert.exists(err, 'invalid accountId')
37
+ try {
38
+ await DailyStats.validate()
39
+ } catch (err) {
40
+ assert.exists(err, 'err object should exist')
44
41
  assert.isObject(err.errors)
45
- done()
46
- })
42
+ }
47
43
  })
48
- assertions('should not accept a invalid projectId', (done) => {
44
+ assertions('should not accept a invalid projectId', async () => {
49
45
  dailyStats.projectId = 'invalid-projectId'
50
46
  let DailyStats = new DailyStatsModel(dailyStats)
51
- DailyStats.validate((err, res) => {
52
- assert.exists(err, 'invalid projectId')
47
+ try {
48
+ await DailyStats.validate()
49
+ } catch (err) {
50
+ assert.exists(err, 'err object should exist')
53
51
  assert.isObject(err.errors)
54
- done()
55
- })
52
+ }
56
53
  })
57
- assertions('should not accept a negative iosCount value', (done) => {
54
+ assertions('should not accept a negative iosCount value', async () => {
58
55
  const negativeIosCount = -100
59
56
  dailyStats.iosCount = negativeIosCount
60
57
  let DailyStats = new DailyStatsModel(dailyStats)
61
- DailyStats.validate((err, res) => {
58
+ try {
59
+ await DailyStats.validate()
60
+ } catch (err) {
62
61
  assert.exists(err, 'Path `iosCount` (' + negativeIosCount + ') is less than minimum allowed value (0)')
63
62
  assert.isObject(err.errors)
64
- done()
65
- })
63
+ }
66
64
  })
67
- assertions('should not accept a negative androidCount value', (done) => {
65
+ assertions('should not accept a negative androidCount value', async () => {
68
66
  const negativeAndroidCount = -100
69
67
  dailyStats.androidCount = negativeAndroidCount
70
68
  let DailyStats = new DailyStatsModel(dailyStats)
71
- DailyStats.validate((err, res) => {
69
+ try {
70
+ await DailyStats.validate()
71
+ } catch (err) {
72
72
  assert.exists(err, 'Path `androidCount` (' + negativeAndroidCount + ') is less than minimum allowed value (0)')
73
73
  assert.isObject(err.errors)
74
- done()
75
- })
74
+ }
76
75
  })
77
76
  })
78
77
  })
@@ -12,81 +12,51 @@ describe('Valid Destination ', () => {
12
12
  destination = JSON.parse(JSON.stringify(destinationJson))
13
13
  })
14
14
 
15
- it('should validate a valid destination ', (done) => {
15
+ it('should validate a valid destination ', async () => {
16
16
  let Destination = new DestinationModel(destination)
17
- Destination.validate((err, res) => {
18
- assert.notExists(res)
19
- assert(err === null, 'err equals null')
20
- done()
21
- })
17
+ const res = await Destination.validate()
18
+ assert.notExists(res)
22
19
  })
23
20
 
24
- it('should validate a valid destination when using built in mongoose ', (done) => {
21
+ it('should validate a valid destination when using built in mongoose ', async () => {
25
22
  let Destination = new DestinationModelBuiltInMongoose(destination)
26
- Destination.validate((err, res) => {
27
- assert.notExists(res)
28
- assert(err === null, 'err equals null')
29
- done()
30
- })
31
- })
32
-
33
- it('should validate a valid destination ', (done) => {
34
- let Destination = new DestinationModel(destination)
35
- Destination.validate((err, res) => {
36
- assert.notExists(res)
37
- assert(err === null, 'err equals null')
38
- done()
39
- })
23
+ const res = await Destination.validate()
24
+ assert.notExists(res)
40
25
  })
41
26
 
42
- it('should validate a valid destination without an email', (done) => {
27
+ it('should validate a valid destination without an email', async () => {
43
28
  delete destination.email
44
29
  let Destination = new DestinationModel(destination)
45
- Destination.validate((err, res) => {
46
- assert.notExists(res)
47
- assert(err === null, 'err equals null')
48
- done()
49
- })
30
+ const res = await Destination.validate()
31
+ assert.notExists(res)
50
32
  })
51
33
 
52
- it('should validate a valid destination without wait time goals', (done) => {
34
+ it('should validate a valid destination without wait time goals', async () => {
53
35
  delete destination.hello.waitTime
54
36
  let Destination = new DestinationModel(destination)
55
- Destination.validate((err, res) => {
56
- assert.notExists(res)
57
- assert(err === null, 'err equals null')
58
- done()
59
- })
37
+ const res = await Destination.validate()
38
+ assert.notExists(res)
60
39
  })
61
40
 
62
- it('should validate a valid destination without stateTemplateId', (done) => {
41
+ it('should validate a valid destination without stateTemplateId', async () => {
63
42
  delete destination.hello.stateTemplateId
64
43
  let Destination = new DestinationModel(destination)
65
- Destination.validate((err, res) => {
66
- assert.notExists(res)
67
- assert(err === null, 'err equals null')
68
- done()
69
- })
44
+ const res = await Destination.validate()
45
+ assert.notExists(res)
70
46
  })
71
47
 
72
- it('should validate a valid destination without consolidationAlert', (done) => {
48
+ it('should validate a valid destination without consolidationAlert', async () => {
73
49
  delete destination.hello.consolidationAlert
74
50
  let Destination = new DestinationModel(destination)
75
- Destination.validate((err, res) => {
76
- assert.notExists(res)
77
- assert(err === null, 'err equals null')
78
- done()
79
- })
51
+ const res = await Destination.validate()
52
+ assert.notExists(res)
80
53
  })
81
54
 
82
- it('should validate a valid destination without any hello properties', (done) => {
55
+ it('should validate a valid destination without any hello properties', async () => {
83
56
  delete destination.hello
84
57
  let Destination = new DestinationModel(destination)
85
- Destination.validate((err, res) => {
86
- assert.notExists(res)
87
- assert(err === null, 'err equals null')
88
- done()
89
- })
58
+ const res = await Destination.validate()
59
+ assert.notExists(res)
90
60
  })
91
61
  })
92
62
 
@@ -98,169 +68,175 @@ describe('Invalid Destination ', () => {
98
68
  describe('required fields check', () => {
99
69
  const requiredFields = rules.requiredFields
100
70
  requiredFields.map((i) => {
101
- it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
71
+ it(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
102
72
  destination = JSON.parse(JSON.stringify(destination))
103
73
  delete destination[i]
104
74
  let Destination = new DestinationModel(destination)
105
- Destination.validate((err, res) => {
106
- assert.notExists(res)
75
+ try {
76
+ await Destination.validate()
77
+ } catch (err) {
107
78
  assert.exists(err, 'err object should exist')
108
79
  assert.isObject(err.errors)
109
80
  assert.nestedProperty(err, `errors.${i}`, 'error should have a radius property')
110
- done()
111
- })
81
+ }
112
82
  })
113
83
  })
114
84
  })
115
85
 
116
- it("should throw an error if location latitude is greater than 90", (done) => {
86
+ it("should throw an error if location latitude is greater than 90", async () => {
117
87
  destination.location.latitude = 91.0213441
118
88
  let Destination = new DestinationModel(destination)
119
- Destination.validate((err, res) => {
120
- assert.notExists(res)
121
- assert.exists(err)
89
+ try {
90
+ await Destination.validate()
91
+ } catch (err) {
92
+ assert.exists(err, 'err object should exist')
93
+ assert.isObject(err.errors)
122
94
  assert.match(err.message, /latitude must be between a value between -90 and 90/)
123
- done()
124
- })
95
+ }
125
96
  })
126
97
 
127
- it("should throw an error if location latitude is less than -90", (done) => {
98
+ it("should throw an error if location latitude is less than -90", async () => {
128
99
  destination.location.latitude = -999.0213441
129
100
  let Destination = new DestinationModel(destination)
130
- Destination.validate((err, res) => {
131
- assert.notExists(res)
132
- assert.exists(err)
101
+ try {
102
+ await Destination.validate()
103
+ } catch (err) {
104
+ assert.exists(err, 'err object should exist')
105
+ assert.isObject(err.errors)
133
106
  assert.match(err.message, /latitude must be between a value between -90 and 90/)
134
- done()
135
- })
107
+ }
136
108
  })
137
109
 
138
- it("should throw an error if location longitude is greater than 180", (done) => {
110
+ it("should throw an error if location longitude is greater than 180", async () => {
139
111
  destination.location.longitude = 181.0213441
140
112
  let Destination = new DestinationModel(destination)
141
- Destination.validate((err, res) => {
142
- assert.notExists(res)
143
- assert.exists(err)
113
+ try {
114
+ await Destination.validate()
115
+ } catch (err) {
116
+ assert.exists(err, 'err object should exist')
117
+ assert.isObject(err.errors)
144
118
  assert.match(err.message, /longitude must be between a value between -180 and 180/)
145
- done()
146
- })
119
+ }
147
120
  })
148
121
 
149
- it("should throw an error if location longitude is less than -180", (done) => {
122
+ it("should throw an error if location longitude is less than -180", async () => {
150
123
  destination.location.longitude = -180.0213441
151
124
  let Destination = new DestinationModel(destination)
152
- Destination.validate((err, res) => {
153
- assert.notExists(res)
154
- assert.exists(err)
125
+ try {
126
+ await Destination.validate()
127
+ } catch (err) {
128
+ assert.exists(err, 'err object should exist')
129
+ assert.isObject(err.errors)
155
130
  assert.match(err.message, /longitude must be between a value between -180 and 180/)
156
- done()
157
- })
131
+ }
158
132
  })
159
133
 
160
- it("should throw an error if destinationId is longer than 128 characters", (done) => {
134
+ it("should throw an error if destinationId is longer than 128 characters", async () => {
161
135
  let destinationId = ""
162
136
  for(let i = 0; i < 129; i++){
163
137
  destinationId += "a"
164
138
  }
165
139
  destination.destinationId = destinationId
166
140
  let Destination = new DestinationModel(destination)
167
- Destination.validate((err, res) => {
168
- assert.notExists(res)
169
- assert.exists(err)
141
+ try {
142
+ await Destination.validate()
143
+ } catch (err) {
144
+ assert.exists(err, 'err object should exist')
145
+ assert.isObject(err.errors)
170
146
  assert.match(err.message, /destinationId must be less than 129 characters long/)
171
- done()
172
- })
147
+ }
173
148
  })
174
149
 
175
- it("should throw an error if email is not a valid email", (done) => {
150
+ it("should throw an error if email is not a valid email", async () => {
176
151
  destination.email = "invalid-email"
177
152
  let Destination = new DestinationModel(destination)
178
- Destination.validate((err, res) => {
179
- assert.notExists(res)
180
- assert.exists(err)
153
+ try {
154
+ await Destination.validate()
155
+ } catch (err) {
156
+ assert.exists(err, 'err object should exist')
157
+ assert.isObject(err.errors)
181
158
  assert.match(err.message, /is not a valid email/)
182
- done()
183
- })
159
+ }
184
160
  })
185
161
 
186
- it("should throw an error if name is more than 128 characters long", (done) => {
162
+ it("should throw an error if name is more than 128 characters long", async () => {
187
163
  destination.name = "ukhwwO8J9qSinhmNB3wA04O24MJgX5Ne04RRt9cJkoJryes8jlyv33H83YdCn8Vza6F8CKoL5Il574JHHs7LC94bC7APHEMZ7aW9Csw8GS6L2Mzo28R35ppxDE5kaVhya"
188
164
  let Destination = new DestinationModel(destination)
189
- Destination.validate((err, res) => {
190
- assert.notExists(res)
191
- assert.exists(err)
192
- console.log(err.message)
165
+ try {
166
+ await Destination.validate()
167
+ } catch (err) {
168
+ assert.exists(err, 'err object should exist')
169
+ assert.isObject(err.errors)
193
170
  assert.match(err.message, /is longer than the maximum allowed length \(128\)/)
194
- done()
195
- })
171
+ }
196
172
  })
197
173
 
198
- it("should throw an error if wait time alert is greater than goal", (done) => {
174
+ it("should throw an error if wait time alert is greater than goal", async () => {
199
175
  destination.hello.waitTime.alert = 600
200
176
  let Destination = new DestinationModel(destination)
201
- Destination.validate((err, res) => {
202
- assert.notExists(res)
203
- assert.exists(err)
204
- console.log(err.message)
177
+ try {
178
+ await Destination.validate()
179
+ } catch (err) {
180
+ assert.exists(err, 'err object should exist')
205
181
  assert.match(err.message, /alert must be less than the goal value/)
206
- done()
207
- })
182
+ }
208
183
  })
209
184
 
210
- it("should throw an error if alert is not a number", (done) => {
185
+ it("should throw an error if alert is not a number", async () => {
211
186
  destination.hello.waitTime.alert = "Twelve"
212
187
  let Destination = new DestinationModel(destination)
213
- Destination.validate((err, res) => {
214
- assert.notExists(res)
215
- assert.exists(err)
216
- console.log(err.message)
188
+ try {
189
+ await Destination.validate()
190
+ } catch (err) {
191
+ assert.exists(err, 'err object should exist')
217
192
  assert.match(err.message, /Cast to Number failed for value "Twelve" \(type string\) at path "alert"/)
218
- done()
219
- })
193
+ }
220
194
  })
221
195
 
222
- it("should throw an error if goal is negative", (done) => {
196
+ it("should throw an error if goal is negative", async () => {
223
197
  destination.hello.waitTime.alert = -1
224
198
  let Destination = new DestinationModel(destination)
225
- Destination.validate((err, res) => {
226
- assert.notExists(res)
227
- assert.exists(err)
199
+ try {
200
+ await Destination.validate()
201
+ } catch (err) {
202
+ assert.exists(err, 'err object should exist')
203
+ assert.isObject(err.errors)
228
204
  assert.match(err.message, /Path `alert` \(-1\) is less than minimum allowed value \(0\)/)
229
- done()
230
- })
205
+ }
231
206
  })
232
207
 
233
- it("should throw an error if consolidationAlert is less than the minimum", (done) => {
208
+ it("should throw an error if consolidationAlert is less than the minimum", async () => {
234
209
  destination.hello.consolidationAlert = 0
235
210
  let Destination = new DestinationModel(destination)
236
- Destination.validate((err, res) => {
237
- assert.notExists(res)
238
- assert.exists(err)
211
+ try {
212
+ await Destination.validate()
213
+ } catch (err) {
214
+ assert.exists(err, 'err object should exist')
215
+ assert.isObject(err.errors)
239
216
  assert.match(err.message, /Path `consolidationAlert` \(0\) is less than minimum allowed value \(1\)/)
240
- done()
241
- })
217
+ }
242
218
  })
243
219
 
244
- it("should throw an error if consolidationAlert is not a number", (done) => {
220
+ it("should throw an error if consolidationAlert is not a number", async () => {
245
221
  destination.hello.consolidationAlert = "Twelve"
246
222
  let Destination = new DestinationModel(destination)
247
- Destination.validate((err, res) => {
248
- assert.notExists(res)
249
- assert.exists(err)
223
+ try {
224
+ await Destination.validate()
225
+ } catch (err) {
226
+ assert.exists(err, 'err object should exist')
227
+ assert.isObject(err.errors)
250
228
  assert.match(err.message, /Cast to Number failed for value "Twelve" \(type string\) at path "consolidationAlert"/)
251
- done()
252
- })
229
+ }
253
230
  })
254
231
 
255
- it("should throw an error if stateTemplateId is not a uuid", (done) => {
232
+ it("should throw an error if stateTemplateId is not a uuid", async () => {
256
233
  destination.hello.stateTemplateId = "something"
257
234
  let Destination = new DestinationModel(destination)
258
- Destination.validate((err, res) => {
259
- assert.notExists(res)
260
- assert.exists(err)
261
- console.log(err.message)
235
+ try {
236
+ await Destination.validate()
237
+ } catch (err) {
238
+ assert.exists(err, 'err object should exist')
262
239
  assert.match(err.message, /Invalid state template id/)
263
- done()
264
- })
240
+ }
265
241
  })
266
242
  })
@@ -24,77 +24,71 @@ beforeEach(() => {
24
24
 
25
25
  describe('BoundingBox', () => {
26
26
  describe('Valid BoundingBox', () => {
27
- it('should validate a valid boundingBox ', (done) => {
27
+ it('should validate a valid boundingBox ', async () => {
28
28
  let BoundingBox = new BoundingBoxModel(boundingBox)
29
- BoundingBox.validate((err, res) => {
30
- assert.notExists(res)
31
- assert(err === null, 'err should equals null')
32
- done()
33
- })
29
+ const res = await BoundingBox.validate()
30
+ assert.notExists(res)
34
31
  })
35
- it('should validate a valid boundingBox ', (done) => {
32
+ it('should validate a valid boundingBox ', async () => {
36
33
  let BoundingBox = new BoundingBoxModelBuiltInMongoose(boundingBox)
37
- BoundingBox.validate((err, res) => {
38
- assert.notExists(res)
39
- assert(err === null, 'err should equals null')
40
- done()
41
- })
34
+ const res = await BoundingBox.validate()
35
+ assert.notExists(res)
42
36
  })
43
37
 
44
- it('should return Double type for longitude and latitude', (done) => {
38
+ it('should return Double type for longitude and latitude', async () => {
45
39
  boundingBox.northEast = {"latitude": -37, "longitude": 144}
46
40
  let BoundingBox = new BoundingBoxModel(boundingBox)
47
41
  assert.isTrue(BoundingBox.northEast.latitude instanceof mongoose.Types.Double)
48
42
  assert.isTrue(BoundingBox.northEast.longitude instanceof mongoose.Types.Double)
49
- done()
50
43
  })
51
44
  })
52
45
 
53
46
  describe('Invalid BoundingBox', () => {
54
- it('should not validate a boundingBox with invalid BoundingBox', (done) => {
47
+ it('should not validate a boundingBox with invalid BoundingBox', async () => {
55
48
  delete boundingBox[rules.requiredFields[0]]
56
49
  let BoundingBox = new BoundingBoxModel(boundingBox)
57
- BoundingBox.validate((err, res) => {
50
+ try {
51
+ await BoundingBox.validate()
52
+ } catch (err) {
58
53
  assert.exists(err, 'err object should exist')
59
54
  assert.isObject(err.errors)
60
- done()
61
- })
55
+ }
62
56
  })
63
57
 
64
58
  describe('check each required property of the model and validate that it is present', () => {
65
59
  let requiredFields = rules.requiredFields
66
60
  requiredFields.map((i) => {
67
- it(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
61
+ it(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
68
62
  // delete i from geofeatures' boundingBox child
69
63
  delete boundingBox[i]
70
64
  let BoundingBox = new BoundingBoxModel(boundingBox)
71
- BoundingBox.validate((err, res) => {
72
- assert.notExists(res)
65
+ try {
66
+ await BoundingBox.validate()
67
+ } catch (err) {
73
68
  assert.exists(err, 'err object should exist')
74
69
  assert.isObject(err.errors)
75
70
  assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
76
- done()
77
- })
71
+ }
78
72
  })
79
73
  })
80
74
  })
81
75
 
82
- it('should be invalid when southWest and NorthEast are the same', (done) => {
76
+ it('should be invalid when southWest and NorthEast are the same', async () => {
83
77
  boundingBox.southWest = {
84
78
  latitude: -37.81794619852986,
85
79
  longitude: 144.97999548912048
86
80
  }
87
81
 
88
82
  const BoundingBox = new BoundingBoxModel(boundingBox)
89
-
90
- BoundingBox.validate((err, res) => {
83
+ try {
84
+ await BoundingBox.validate()
85
+ } catch (err) {
91
86
  assert.exists(err, 'err object should exist')
92
87
  assert.isObject(err.errors)
93
- done()
94
- })
88
+ }
95
89
  })
96
90
 
97
- it('should fail when area is less than 70 square metres', (done) => {
91
+ it('should fail when area is less than 70 square metres', async () => {
98
92
  boundingBox.geometry ={
99
93
  type: "Polygon",
100
94
  coordinates: [
@@ -108,13 +102,13 @@ describe('BoundingBox', () => {
108
102
  ]
109
103
  }
110
104
  const BoundingBox = new BoundingBoxModel(boundingBox)
111
-
112
- BoundingBox.validate((err, res) => {
105
+ try {
106
+ await BoundingBox.validate()
107
+ } catch (err) {
113
108
  assert.exists(err, 'err object should exist')
114
109
  assert.isObject(err.errors)
115
110
  assert.match(err.message, /(Bounding box area should be at least 70 square metres)/i)
116
- done()
117
- })
111
+ }
118
112
  })
119
113
  })
120
114
  })