@bluedot-innovation/models 9.1.0 → 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 +6 -0
- package/__tests__/account/account.spec.js +32 -47
- package/__tests__/condition/dayRange/dayRange.spec.js +26 -29
- package/__tests__/condition/percentageCrossed/travelPath.spec.js +16 -21
- package/__tests__/condition/speed/speed.spec.js +26 -29
- package/__tests__/condition/timeActive/timeActive.spec.js +27 -30
- package/__tests__/condition/travelDirection/travelDirection.spec.js +31 -33
- package/__tests__/cumulativeRulesRequests/checkDailyStats.js +10 -13
- package/__tests__/dailyStats/dailyStats.spec.js +29 -30
- package/__tests__/destination/destination.spec.js +114 -138
- package/__tests__/geofeature/boundingBox/boundingBox.spec.js +27 -33
- package/__tests__/geofeature/circle/circle.spec.js +23 -28
- package/__tests__/geofeature/geoline/geoline.spec.js +17 -22
- package/__tests__/geofeature/polygon/polygon.spec.js +38 -41
- package/__tests__/helpers.js +10 -8
- package/__tests__/monthlyStats/monthlyStats.spec.js +23 -26
- package/__tests__/project/project.data.json +0 -3
- package/__tests__/project/project.spec.js +447 -435
- package/__tests__/user/user.spec.js +53 -65
- package/__tests__/zone/zone.condition.spec.js +22 -24
- package/__tests__/zone/zone.geofeatures.spec.js +32 -30
- package/__tests__/zone/zone.spec.js +174 -166
- package/package.json +2 -2
- package/schemas/Integration.js +1 -3
- package/utils/DbInitialiser/indexInitialiser.js +1 -1
- package/utils/validators.js +0 -1
- package/schemas/UberEatsIntegration.js +0 -9
|
@@ -17,73 +17,52 @@ beforeEach(() => {
|
|
|
17
17
|
|
|
18
18
|
describe('Zone', () => {
|
|
19
19
|
describe('Valid Zone ', () => {
|
|
20
|
-
it('should validate a valid zone ', (
|
|
20
|
+
it('should validate a valid zone ', async () => {
|
|
21
21
|
let Zone = new ZoneModel(zone)
|
|
22
|
-
Zone.validate(
|
|
23
|
-
|
|
24
|
-
assert.notExists(err)
|
|
25
|
-
done()
|
|
26
|
-
})
|
|
22
|
+
const res = await Zone.validate()
|
|
23
|
+
assert.notExists(res)
|
|
27
24
|
})
|
|
28
25
|
|
|
29
|
-
it('should validate a valid zone ', (
|
|
26
|
+
it('should validate a valid zone ', async () => {
|
|
30
27
|
let Zone = new ZoneModelBuiltInMongoose(zone)
|
|
31
|
-
Zone.validate(
|
|
32
|
-
|
|
33
|
-
assert(err === null, 'err equals null')
|
|
34
|
-
done()
|
|
35
|
-
})
|
|
28
|
+
const res = await Zone.validate()
|
|
29
|
+
assert.notExists(res)
|
|
36
30
|
})
|
|
37
31
|
|
|
38
|
-
it('should instantiate a circle', (
|
|
32
|
+
it('should instantiate a circle', async () => {
|
|
39
33
|
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^circle$/))
|
|
40
34
|
let Zone = new ZoneModel(zone)
|
|
41
|
-
Zone.validate(
|
|
42
|
-
|
|
43
|
-
assert.notExists(err)
|
|
44
|
-
done()
|
|
45
|
-
})
|
|
35
|
+
const res = await Zone.validate()
|
|
36
|
+
assert.notExists(res)
|
|
46
37
|
})
|
|
47
38
|
|
|
48
|
-
it('should instantiate a bounding box', (
|
|
39
|
+
it('should instantiate a bounding box', async () => {
|
|
49
40
|
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^boundingBox$/))
|
|
50
41
|
let Zone = new ZoneModel(zone)
|
|
51
|
-
Zone.validate(
|
|
52
|
-
|
|
53
|
-
assert.notExists(err)
|
|
54
|
-
done()
|
|
55
|
-
})
|
|
42
|
+
const res = await Zone.validate()
|
|
43
|
+
assert.notExists(res)
|
|
56
44
|
})
|
|
57
45
|
|
|
58
|
-
it('should instantiate a polygon', (
|
|
46
|
+
it('should instantiate a polygon', async () => {
|
|
59
47
|
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polygon$/))
|
|
60
48
|
let Zone = new ZoneModel(zone)
|
|
61
|
-
Zone.validate(
|
|
62
|
-
|
|
63
|
-
assert.notExists(err)
|
|
64
|
-
done()
|
|
65
|
-
})
|
|
49
|
+
const res = await Zone.validate()
|
|
50
|
+
assert.notExists(res)
|
|
66
51
|
})
|
|
67
52
|
|
|
68
|
-
it('should instantiate a geoline', (
|
|
53
|
+
it('should instantiate a geoline', async () => {
|
|
69
54
|
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^geoline$/))
|
|
70
55
|
let Zone = new ZoneModel(zone)
|
|
71
|
-
Zone.validate(
|
|
72
|
-
|
|
73
|
-
assert.notExists(err)
|
|
74
|
-
done()
|
|
75
|
-
})
|
|
56
|
+
const res = await Zone.validate()
|
|
57
|
+
assert.notExists(res)
|
|
76
58
|
})
|
|
77
59
|
|
|
78
|
-
it('should set triggerOnExit default and save without errors', (
|
|
60
|
+
it('should set triggerOnExit default and save without errors', async () => {
|
|
79
61
|
delete zone.triggerOnExit
|
|
80
62
|
|
|
81
63
|
let Zone = new ZoneModel(zone)
|
|
82
|
-
Zone.validate(
|
|
83
|
-
|
|
84
|
-
assert.notExists(err)
|
|
85
|
-
done()
|
|
86
|
-
})
|
|
64
|
+
const res = await Zone.validate()
|
|
65
|
+
assert.notExists(res)
|
|
87
66
|
})
|
|
88
67
|
|
|
89
68
|
it('should set tags to lowercase and remove the duplicated tag', () => {
|
|
@@ -94,281 +73,307 @@ describe('Zone', () => {
|
|
|
94
73
|
assert.strictEqual(zone.tags[1], "1")
|
|
95
74
|
})
|
|
96
75
|
|
|
97
|
-
it('should save without errors when destinationId is null', (
|
|
76
|
+
it('should save without errors when destinationId is null', async () => {
|
|
98
77
|
zone.destinationId = null;
|
|
99
78
|
let Zone = new ZoneModel(zone)
|
|
100
|
-
Zone.validate(
|
|
101
|
-
|
|
102
|
-
assert.notExists(err)
|
|
103
|
-
done()
|
|
104
|
-
})
|
|
79
|
+
const res = await Zone.validate()
|
|
80
|
+
assert.notExists(res)
|
|
105
81
|
})
|
|
106
82
|
|
|
107
83
|
const validTempoGeofeatureTypes = ['boundingBox', 'circle', 'polygon']
|
|
108
84
|
|
|
109
85
|
validTempoGeofeatureTypes.map(type => {
|
|
110
|
-
it(`should save without errors when destinationId is set and there is a single ${type} geofeature`, (
|
|
86
|
+
it(`should save without errors when destinationId is set and there is a single ${type} geofeature`, async () => {
|
|
111
87
|
zone.destinationId = "test-destination-id";
|
|
112
88
|
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(new RegExp(type)))
|
|
113
89
|
let Zone = new ZoneModel(zone)
|
|
114
|
-
Zone.validate(
|
|
115
|
-
|
|
116
|
-
assert.notExists(err)
|
|
117
|
-
done()
|
|
118
|
-
})
|
|
90
|
+
const res = await Zone.validate()
|
|
91
|
+
assert.notExists(res)
|
|
119
92
|
})
|
|
120
93
|
})
|
|
121
94
|
})
|
|
122
95
|
|
|
123
96
|
describe('Invalid Zone ', () => {
|
|
124
|
-
it('should throw an error when validating an invalid zone ', (
|
|
97
|
+
it('should throw an error when validating an invalid zone ', async () => {
|
|
125
98
|
delete zone.name
|
|
126
99
|
let Zone = new ZoneModel(zone)
|
|
127
|
-
|
|
100
|
+
try {
|
|
101
|
+
await Zone.validate()
|
|
102
|
+
} catch (err) {
|
|
128
103
|
assert.exists(err, 'err object should exist')
|
|
129
104
|
assert.isObject(err.errors)
|
|
130
|
-
|
|
131
|
-
})
|
|
105
|
+
}
|
|
132
106
|
})
|
|
133
107
|
|
|
134
|
-
it('should throw an error when a condition is invalid', (
|
|
108
|
+
it('should throw an error when a condition is invalid', async () => {
|
|
135
109
|
zone.conditions[0].startDate = 'abc'
|
|
136
110
|
let Zone = new ZoneModel(zone)
|
|
137
|
-
|
|
111
|
+
try {
|
|
112
|
+
await Zone.validate()
|
|
113
|
+
} catch (err) {
|
|
138
114
|
assert.exists(err, 'err object should exist')
|
|
139
115
|
assert.isObject(err.errors)
|
|
140
116
|
assert('conditions.0.startDate' in err.errors, `errors should have a 'conditions.0.startDate' property`)
|
|
141
|
-
|
|
142
|
-
})
|
|
117
|
+
}
|
|
143
118
|
})
|
|
144
119
|
|
|
145
|
-
it('should throw an error when a condition type is missing', (
|
|
120
|
+
it('should throw an error when a condition type is missing', async () => {
|
|
146
121
|
delete zone.conditions[0].type
|
|
147
122
|
let Zone = new ZoneModel(zone)
|
|
148
|
-
|
|
123
|
+
try {
|
|
124
|
+
await Zone.validate()
|
|
125
|
+
} catch (err) {
|
|
149
126
|
assert.exists(err, 'err object should exist')
|
|
150
127
|
assert.isObject(err.errors)
|
|
151
128
|
assert.match(err.message, /(Condition requires a type of `dayRange`, `speed`, `timeActive`, `travelDirection` or `travelPath`.)/i)
|
|
152
|
-
|
|
153
|
-
})
|
|
129
|
+
}
|
|
154
130
|
})
|
|
155
131
|
|
|
156
|
-
it('should throw an error when a condition object is empty', (
|
|
132
|
+
it('should throw an error when a condition object is empty', async () => {
|
|
157
133
|
zone.conditions = [{}]
|
|
158
134
|
let Zone = new ZoneModel(zone)
|
|
159
|
-
|
|
135
|
+
try {
|
|
136
|
+
await Zone.validate()
|
|
137
|
+
} catch (err) {
|
|
160
138
|
assert.exists(err, 'err object should exist')
|
|
161
139
|
assert.isObject(err.errors)
|
|
162
140
|
assert.match(err.message, /(Condition requires a type of `dayRange`, `speed`, `timeActive`, `travelDirection` or `travelPath`.)/i)
|
|
163
|
-
|
|
164
|
-
})
|
|
141
|
+
}
|
|
165
142
|
})
|
|
166
143
|
|
|
167
|
-
it('should throw an error when a conditions is null', (
|
|
144
|
+
it('should throw an error when a conditions is null', async () => {
|
|
168
145
|
zone.conditions = null
|
|
169
146
|
let Zone = new ZoneModel(zone)
|
|
170
|
-
|
|
147
|
+
try {
|
|
148
|
+
await Zone.validate()
|
|
149
|
+
} catch (err) {
|
|
171
150
|
assert.exists(err, 'err object should exist')
|
|
172
151
|
assert.isObject(err.errors)
|
|
173
152
|
assert.match(err.message, /(conditions must have a value)/i)
|
|
174
|
-
|
|
175
|
-
})
|
|
153
|
+
}
|
|
176
154
|
})
|
|
177
155
|
|
|
178
|
-
it('should throw an error when custom data is null', (
|
|
156
|
+
it('should throw an error when custom data is null', async () => {
|
|
179
157
|
zone.customData = null
|
|
180
158
|
let Zone = new ZoneModel(zone)
|
|
181
|
-
|
|
159
|
+
try {
|
|
160
|
+
await Zone.validate()
|
|
161
|
+
} catch (err) {
|
|
182
162
|
assert.exists(err, 'err object should exist')
|
|
183
163
|
assert.isObject(err.errors)
|
|
184
164
|
assert.match(err.message, /Zone validation failed: customData/i)
|
|
185
|
-
|
|
186
|
-
})
|
|
165
|
+
}
|
|
187
166
|
})
|
|
188
167
|
|
|
189
|
-
it('should throw an error when custom data is undefined', (
|
|
168
|
+
it('should not throw an error when custom data is undefined', async () => {
|
|
190
169
|
zone.customData = undefined
|
|
191
170
|
let Zone = new ZoneModel(zone)
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
assert.notExists(err, 'err is neither `null` nor `undefined`')
|
|
195
|
-
done()
|
|
196
|
-
})
|
|
171
|
+
const res = await Zone.validate()
|
|
172
|
+
assert.notExists(res)
|
|
197
173
|
})
|
|
198
174
|
|
|
199
|
-
it('should throw an error when custom data is not an object', (
|
|
175
|
+
it('should throw an error when custom data is not an object', async () => {
|
|
200
176
|
zone.customData = 1
|
|
201
177
|
let Zone = new ZoneModel(zone)
|
|
202
|
-
|
|
178
|
+
try {
|
|
179
|
+
await Zone.validate()
|
|
180
|
+
} catch (err) {
|
|
203
181
|
assert.exists(err, 'err object should exist')
|
|
204
182
|
assert.isObject(err.errors)
|
|
205
183
|
assert.match(err.message, /Zone validation failed: customData/i)
|
|
206
|
-
|
|
207
|
-
})
|
|
184
|
+
}
|
|
208
185
|
})
|
|
209
186
|
|
|
210
|
-
it('should throw an error if CustomData key does not have alpha numeric and _ characters only', (
|
|
187
|
+
it('should throw an error if CustomData key does not have alpha numeric and _ characters only', async () => {
|
|
211
188
|
zone.customData["name#3"] = "A Custom action"
|
|
212
189
|
let Zone = new ZoneModel(zone)
|
|
213
|
-
|
|
190
|
+
try {
|
|
191
|
+
await Zone.validate()
|
|
192
|
+
} catch (err) {
|
|
193
|
+
assert.exists(err, 'err object should exist')
|
|
194
|
+
assert.isObject(err.errors)
|
|
214
195
|
assert.match(err.message, /(CustomData key should have alpha numeric, - and _ characters only)/i);
|
|
215
|
-
|
|
216
|
-
})
|
|
196
|
+
}
|
|
217
197
|
})
|
|
218
198
|
|
|
219
|
-
it('should throw an error if custom data keys count is greater than 20', (
|
|
199
|
+
it('should throw an error if custom data keys count is greater than 20', async () => {
|
|
220
200
|
for (let i = 0; i <= 21; i++) {
|
|
221
201
|
zone.customData[`key${i}`] = `value ${i}`
|
|
222
202
|
}
|
|
223
203
|
|
|
224
204
|
let Zone = new ZoneModel(zone)
|
|
225
|
-
|
|
205
|
+
try {
|
|
206
|
+
await Zone.validate()
|
|
207
|
+
} catch (err) {
|
|
208
|
+
assert.exists(err, 'err object should exist')
|
|
226
209
|
assert.match(err.message, /(Only 20 custom data fields are allowed to be added per zone)/i)
|
|
227
|
-
|
|
228
|
-
})
|
|
210
|
+
}
|
|
229
211
|
})
|
|
230
212
|
|
|
231
|
-
it('should throw an error if CustomData value is null', (
|
|
213
|
+
it('should throw an error if CustomData value is null', async () => {
|
|
232
214
|
zone.customData["name3"] = null;
|
|
233
215
|
|
|
234
216
|
let Zone = new ZoneModel(zone)
|
|
235
|
-
|
|
217
|
+
try {
|
|
218
|
+
await Zone.validate()
|
|
219
|
+
} catch (err) {
|
|
220
|
+
assert.exists(err, 'err object should exist')
|
|
236
221
|
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
237
|
-
|
|
238
|
-
})
|
|
222
|
+
}
|
|
239
223
|
})
|
|
240
224
|
|
|
241
|
-
it('should throw an error if CustomData value is undefined', (
|
|
225
|
+
it('should throw an error if CustomData value is undefined', async () => {
|
|
242
226
|
zone.customData["name3"] = undefined;
|
|
243
227
|
|
|
244
228
|
let Zone = new ZoneModel(zone)
|
|
245
|
-
|
|
229
|
+
try {
|
|
230
|
+
await Zone.validate()
|
|
231
|
+
} catch (err) {
|
|
232
|
+
assert.exists(err, 'err object should exist')
|
|
246
233
|
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
247
|
-
|
|
248
|
-
})
|
|
234
|
+
}
|
|
249
235
|
})
|
|
250
236
|
|
|
251
|
-
it('should throw an error if CustomData value is an empty string', (
|
|
237
|
+
it('should throw an error if CustomData value is an empty string', async () => {
|
|
252
238
|
zone.customData["name3"] = ' ';
|
|
253
239
|
|
|
254
240
|
let Zone = new ZoneModel(zone)
|
|
255
|
-
|
|
241
|
+
try {
|
|
242
|
+
await Zone.validate()
|
|
243
|
+
} catch (err) {
|
|
244
|
+
assert.exists(err, 'err object should exist')
|
|
256
245
|
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
257
|
-
|
|
258
|
-
})
|
|
246
|
+
}
|
|
259
247
|
})
|
|
260
248
|
|
|
261
|
-
it('should throw an error if CustomData value is an empty object', (
|
|
249
|
+
it('should throw an error if CustomData value is an empty object', async () => {
|
|
262
250
|
zone.customData["name3"] = {};
|
|
263
251
|
|
|
264
252
|
let Zone = new ZoneModel(zone)
|
|
265
|
-
|
|
253
|
+
try {
|
|
254
|
+
await Zone.validate()
|
|
255
|
+
} catch (err) {
|
|
256
|
+
assert.exists(err, 'err object should exist')
|
|
266
257
|
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
267
|
-
|
|
268
|
-
})
|
|
258
|
+
}
|
|
269
259
|
})
|
|
270
260
|
|
|
271
|
-
it('should throw an error if CustomData value is an object', (
|
|
261
|
+
it('should throw an error if CustomData value is an object', async () => {
|
|
272
262
|
zone.customData["name3"] = { key: 'value' };
|
|
273
263
|
|
|
274
264
|
let Zone = new ZoneModel(zone)
|
|
275
|
-
|
|
265
|
+
try {
|
|
266
|
+
await Zone.validate()
|
|
267
|
+
} catch (err) {
|
|
268
|
+
assert.exists(err, 'err object should exist')
|
|
276
269
|
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
277
|
-
|
|
278
|
-
})
|
|
270
|
+
}
|
|
279
271
|
})
|
|
280
272
|
|
|
281
|
-
it('should throw an error if CustomData value is an empty array', (
|
|
273
|
+
it('should throw an error if CustomData value is an empty array', async () => {
|
|
282
274
|
zone.customData["name3"] = [];
|
|
283
275
|
|
|
284
276
|
let Zone = new ZoneModel(zone)
|
|
285
|
-
|
|
277
|
+
try {
|
|
278
|
+
await Zone.validate()
|
|
279
|
+
} catch (err) {
|
|
280
|
+
assert.exists(err, 'err object should exist')
|
|
286
281
|
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
287
|
-
|
|
288
|
-
})
|
|
282
|
+
}
|
|
289
283
|
})
|
|
290
284
|
|
|
291
|
-
it('should throw an error if CustomData value is an array', (
|
|
285
|
+
it('should throw an error if CustomData value is an array', async () => {
|
|
292
286
|
zone.customData["name3"] = ['value1', 'value2'];
|
|
293
287
|
|
|
294
288
|
let Zone = new ZoneModel(zone)
|
|
295
|
-
|
|
289
|
+
try {
|
|
290
|
+
await Zone.validate()
|
|
291
|
+
} catch (err) {
|
|
292
|
+
assert.exists(err, 'err object should exist')
|
|
296
293
|
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
297
|
-
|
|
298
|
-
})
|
|
294
|
+
}
|
|
299
295
|
})
|
|
300
296
|
|
|
301
|
-
it('should throw an error if CustomData value is a number', (
|
|
297
|
+
it('should throw an error if CustomData value is a number', async () => {
|
|
302
298
|
zone.customData["name3"] = 1;
|
|
303
299
|
|
|
304
300
|
let Zone = new ZoneModel(zone)
|
|
305
|
-
|
|
301
|
+
try {
|
|
302
|
+
await Zone.validate()
|
|
303
|
+
} catch (err) {
|
|
304
|
+
assert.exists(err, 'err object should exist')
|
|
306
305
|
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
307
|
-
|
|
308
|
-
})
|
|
306
|
+
}
|
|
309
307
|
})
|
|
310
308
|
|
|
311
|
-
it('should throw an error if CustomData value is a boolean', (
|
|
309
|
+
it('should throw an error if CustomData value is a boolean', async () => {
|
|
312
310
|
zone.customData["name3"] = true;
|
|
313
311
|
|
|
314
312
|
let Zone = new ZoneModel(zone)
|
|
315
|
-
|
|
313
|
+
try {
|
|
314
|
+
await Zone.validate()
|
|
315
|
+
} catch (err) {
|
|
316
|
+
assert.exists(err, 'err object should exist')
|
|
316
317
|
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
317
|
-
|
|
318
|
-
})
|
|
318
|
+
}
|
|
319
319
|
})
|
|
320
320
|
|
|
321
|
-
it('should throw an error if CustomData value is a NaN', (
|
|
321
|
+
it('should throw an error if CustomData value is a NaN', async () => {
|
|
322
322
|
zone.customData["name3"] = NaN;
|
|
323
323
|
|
|
324
324
|
let Zone = new ZoneModel(zone)
|
|
325
|
-
|
|
325
|
+
try {
|
|
326
|
+
await Zone.validate()
|
|
327
|
+
} catch (err) {
|
|
328
|
+
assert.exists(err, 'err object should exist')
|
|
326
329
|
assert.match(err.message, /(CustomData value should be a string and should not be empty)/i);
|
|
327
|
-
|
|
328
|
-
})
|
|
330
|
+
}
|
|
329
331
|
})
|
|
330
332
|
|
|
331
|
-
it('should throw an error when it contains both a beacon and a travelDirection condition', (
|
|
333
|
+
it('should throw an error when it contains both a beacon and a travelDirection condition', async () => {
|
|
332
334
|
zone.conditions.push(require('../condition/travelDirection/travelDirection.data.json'));
|
|
333
335
|
let Zone = new ZoneModel(zone)
|
|
334
|
-
|
|
336
|
+
try {
|
|
337
|
+
await Zone.validate()
|
|
338
|
+
} catch (err) {
|
|
335
339
|
assert.exists(err, 'err object should exist')
|
|
336
340
|
assert(err instanceof Error, "Should throw error.")
|
|
337
|
-
|
|
338
|
-
})
|
|
341
|
+
}
|
|
339
342
|
})
|
|
340
343
|
|
|
341
|
-
it('should throw an error when it contains both a beacon and a speed condition', (
|
|
344
|
+
it('should throw an error when it contains both a beacon and a speed condition', async () => {
|
|
342
345
|
zone.conditions.push(require('../condition/speed/speed.data.json'));
|
|
343
346
|
let Zone = new ZoneModel(zone)
|
|
344
|
-
|
|
347
|
+
try {
|
|
348
|
+
await Zone.validate()
|
|
349
|
+
} catch (err) {
|
|
345
350
|
assert.exists(err, 'err object should exist')
|
|
346
351
|
assert(err instanceof Error, "Should throw error.")
|
|
347
|
-
|
|
348
|
-
})
|
|
352
|
+
}
|
|
349
353
|
})
|
|
350
354
|
|
|
351
|
-
it('should throw an error when triggerOnExit is null', (
|
|
355
|
+
it('should throw an error when triggerOnExit is null', async () => {
|
|
352
356
|
zone.triggerOnExit = null
|
|
353
|
-
helpers.testNullValue(zone, ZoneModel
|
|
357
|
+
await helpers.testNullValue(zone, ZoneModel)
|
|
354
358
|
})
|
|
355
359
|
|
|
356
|
-
it('should throw an error when tags is null', (
|
|
360
|
+
it('should throw an error when tags is null', async () => {
|
|
357
361
|
zone.tags = null
|
|
358
|
-
helpers.testNullValue(zone, ZoneModel
|
|
362
|
+
await helpers.testNullValue(zone, ZoneModel)
|
|
359
363
|
})
|
|
360
364
|
|
|
361
|
-
it('should throw an error when projectId is invalid', (
|
|
365
|
+
it('should throw an error when projectId is invalid', async () => {
|
|
362
366
|
zone.projectId = "invalid id"
|
|
363
367
|
let Zone = new ZoneModel(zone)
|
|
364
|
-
|
|
368
|
+
try {
|
|
369
|
+
await Zone.validate()
|
|
370
|
+
} catch (err) {
|
|
365
371
|
assert.exists(err, 'err object should exist')
|
|
366
372
|
assert.match(err.message, /(Invalid Project Id)/i)
|
|
367
|
-
|
|
368
|
-
})
|
|
373
|
+
}
|
|
369
374
|
})
|
|
370
375
|
|
|
371
|
-
it('should throw an error when a zone has a low accuracy fence with Speed/travelDirection condition', (
|
|
376
|
+
it('should throw an error when a zone has a low accuracy fence with Speed/travelDirection condition', async () => {
|
|
372
377
|
zone.conditions.push({
|
|
373
378
|
"type": "speed",
|
|
374
379
|
"minimumSpeed": 0,
|
|
@@ -390,11 +395,12 @@ describe('Zone', () => {
|
|
|
390
395
|
}
|
|
391
396
|
]
|
|
392
397
|
let Zone = new ZoneModel(zone)
|
|
393
|
-
|
|
398
|
+
try {
|
|
399
|
+
await Zone.validate()
|
|
400
|
+
} catch (err) {
|
|
394
401
|
assert.exists(err, 'err object should exist')
|
|
395
402
|
assert.match(err.message, /(This Zone contains one or more large Geofences. Travel Direction\/Speed conditions cannot be added to a Zone that contains large Geofences.)/i)
|
|
396
|
-
|
|
397
|
-
})
|
|
403
|
+
}
|
|
398
404
|
})
|
|
399
405
|
|
|
400
406
|
describe('should throw an error when any of the values of the array contains a falsy value', () => {
|
|
@@ -402,32 +408,34 @@ describe('Zone', () => {
|
|
|
402
408
|
|
|
403
409
|
arrayTypeFields.map(arrayField => {
|
|
404
410
|
FALSY_VALUES.map(falsyValue => {
|
|
405
|
-
it(`should trow an error when it contains ${falsyValue} on a ${arrayField}`, (
|
|
406
|
-
helpers.testFalsyValue(falsyValue, arrayField, zone, ZoneModel
|
|
411
|
+
it(`should trow an error when it contains ${falsyValue} on a ${arrayField}`, async () => {
|
|
412
|
+
await helpers.testFalsyValue(falsyValue, arrayField, zone, ZoneModel)
|
|
407
413
|
})
|
|
408
414
|
})
|
|
409
415
|
})
|
|
410
416
|
})
|
|
411
417
|
|
|
412
|
-
it('should throw an error when geofeatures have the same _id', (
|
|
418
|
+
it('should throw an error when geofeatures have the same _id', async () => {
|
|
413
419
|
zone.geofeatures[0]._id = GEOFEATURE_ID
|
|
414
420
|
zone.geofeatures[1]._id = GEOFEATURE_ID
|
|
415
421
|
let Zone = new ZoneModel(zone)
|
|
416
|
-
|
|
422
|
+
try {
|
|
423
|
+
await Zone.validate()
|
|
424
|
+
} catch (err) {
|
|
417
425
|
assert.exists(err, 'err object should exist')
|
|
418
426
|
assert.match(err.message, /(Duplicate values are not allowed for geofeatures _id.)/i)
|
|
419
|
-
|
|
420
|
-
})
|
|
427
|
+
}
|
|
421
428
|
})
|
|
422
429
|
|
|
423
|
-
it('should throw an error when destinationId is longer than 128 characters', (
|
|
430
|
+
it('should throw an error when destinationId is longer than 128 characters', async () => {
|
|
424
431
|
zone.destinationId = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s';
|
|
425
432
|
let Zone = new ZoneModel(zone)
|
|
426
|
-
|
|
433
|
+
try {
|
|
434
|
+
await Zone.validate()
|
|
435
|
+
} catch (err) {
|
|
427
436
|
assert.exists(err, 'err object should exist')
|
|
428
437
|
assert.match(err.message, /(destinationId must be less than 129 characters long)/i)
|
|
429
|
-
|
|
430
|
-
})
|
|
438
|
+
}
|
|
431
439
|
})
|
|
432
440
|
})
|
|
433
441
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluedot-innovation/models",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0-beta",
|
|
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",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"fast-deep-equal": "^2.0.1",
|
|
39
39
|
"lodash.clonedeep": "4.5.0",
|
|
40
40
|
"moment-timezone": "^0.5.45",
|
|
41
|
-
"mongoose": "
|
|
41
|
+
"mongoose": "^8.5.4",
|
|
42
42
|
"uuid": "^3.1.0"
|
|
43
43
|
}
|
|
44
44
|
}
|
package/schemas/Integration.js
CHANGED
|
@@ -9,7 +9,6 @@ const incentivioIntegrationSchema = require('./IncentivioIntegration')
|
|
|
9
9
|
const mparticleIntegrationSchema = require('./MparticleIntegration')
|
|
10
10
|
const klaviyoIntegrationSchema = require('./KlaviyoIntegration')
|
|
11
11
|
const doordashIntegrationSchema = require('./DoordashIntegration')
|
|
12
|
-
const uberEatsIntegrationSchema = require('./UberEatsIntegration')
|
|
13
12
|
|
|
14
13
|
function mParticleValidator(value) {
|
|
15
14
|
const { androidApiKey, iosApiKey, webApiKey } = value;
|
|
@@ -26,8 +25,7 @@ const IntegrationSchema = new mongoose.Schema({
|
|
|
26
25
|
attentive: { type: projectAttentiveIntegrationSchema },
|
|
27
26
|
incentivio: { type: incentivioIntegrationSchema },
|
|
28
27
|
klaviyo: { type: klaviyoIntegrationSchema },
|
|
29
|
-
doordash: { type: doordashIntegrationSchema }
|
|
30
|
-
uberEats: { type: uberEatsIntegrationSchema }
|
|
28
|
+
doordash: { type: doordashIntegrationSchema }
|
|
31
29
|
},{ _id : false });
|
|
32
30
|
|
|
33
31
|
module.exports = IntegrationSchema
|
|
@@ -143,7 +143,7 @@ const createAllIndexesIfNotExists = async db => {
|
|
|
143
143
|
const createIndexPromises = []
|
|
144
144
|
for(const collectionName in indexes){
|
|
145
145
|
if(!await db.listCollections({ name: collectionName }).hasNext()){
|
|
146
|
-
db.createCollection(collectionName)
|
|
146
|
+
await db.createCollection(collectionName)
|
|
147
147
|
}
|
|
148
148
|
const collection = db.collection(collectionName);
|
|
149
149
|
for(const index of indexes[collectionName]){
|
package/utils/validators.js
CHANGED