@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 +3 -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.spec.js +447 -423
- 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/utils/DbInitialiser/indexInitialiser.js +1 -1
- package/utils/validators.js +0 -1
|
@@ -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', (
|
|
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
|
-
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
console.log(
|
|
23
|
-
|
|
24
|
-
|
|
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 ', (
|
|
23
|
+
assertions('should validate a valid DailyStats document ', async () => {
|
|
24
24
|
let DailyStats = new DailyStatsModel(dailyStats)
|
|
25
|
-
DailyStats.validate(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
done()
|
|
29
|
-
})
|
|
25
|
+
const res = await DailyStats.validate()
|
|
26
|
+
assert.notExists(res)
|
|
27
|
+
|
|
30
28
|
})
|
|
31
|
-
assertions('should validate a valid DailyStats document ', (
|
|
29
|
+
assertions('should validate a valid DailyStats document ', async () => {
|
|
32
30
|
let DailyStats = new DailyStatsModelBuiltInMongoose(dailyStats)
|
|
33
|
-
DailyStats.validate(
|
|
34
|
-
|
|
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', (
|
|
34
|
+
assertions('should not accept a invalid accountId', async () => {
|
|
40
35
|
dailyStats.accountId = 'invalid-accountId'
|
|
41
36
|
let DailyStats = new DailyStatsModel(dailyStats)
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
try {
|
|
38
|
+
await DailyStats.validate()
|
|
39
|
+
} catch (err) {
|
|
40
|
+
assert.exists(err, 'err object should exist')
|
|
44
41
|
assert.isObject(err.errors)
|
|
45
|
-
|
|
46
|
-
})
|
|
42
|
+
}
|
|
47
43
|
})
|
|
48
|
-
assertions('should not accept a invalid projectId', (
|
|
44
|
+
assertions('should not accept a invalid projectId', async () => {
|
|
49
45
|
dailyStats.projectId = 'invalid-projectId'
|
|
50
46
|
let DailyStats = new DailyStatsModel(dailyStats)
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
try {
|
|
48
|
+
await DailyStats.validate()
|
|
49
|
+
} catch (err) {
|
|
50
|
+
assert.exists(err, 'err object should exist')
|
|
53
51
|
assert.isObject(err.errors)
|
|
54
|
-
|
|
55
|
-
})
|
|
52
|
+
}
|
|
56
53
|
})
|
|
57
|
-
assertions('should not accept a negative iosCount value', (
|
|
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
|
-
|
|
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
|
-
|
|
65
|
-
})
|
|
63
|
+
}
|
|
66
64
|
})
|
|
67
|
-
assertions('should not accept a negative androidCount value', (
|
|
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
|
-
|
|
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
|
-
|
|
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 ', (
|
|
15
|
+
it('should validate a valid destination ', async () => {
|
|
16
16
|
let Destination = new DestinationModel(destination)
|
|
17
|
-
Destination.validate(
|
|
18
|
-
|
|
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 ', (
|
|
21
|
+
it('should validate a valid destination when using built in mongoose ', async () => {
|
|
25
22
|
let Destination = new DestinationModelBuiltInMongoose(destination)
|
|
26
|
-
Destination.validate(
|
|
27
|
-
|
|
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', (
|
|
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(
|
|
46
|
-
|
|
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', (
|
|
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(
|
|
56
|
-
|
|
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', (
|
|
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(
|
|
66
|
-
|
|
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', (
|
|
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(
|
|
76
|
-
|
|
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', (
|
|
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(
|
|
86
|
-
|
|
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`, (
|
|
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
|
-
|
|
106
|
-
|
|
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
|
-
|
|
111
|
-
})
|
|
81
|
+
}
|
|
112
82
|
})
|
|
113
83
|
})
|
|
114
84
|
})
|
|
115
85
|
|
|
116
|
-
it("should throw an error if location latitude is greater than 90", (
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
124
|
-
})
|
|
95
|
+
}
|
|
125
96
|
})
|
|
126
97
|
|
|
127
|
-
it("should throw an error if location latitude is less than -90", (
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
135
|
-
})
|
|
107
|
+
}
|
|
136
108
|
})
|
|
137
109
|
|
|
138
|
-
it("should throw an error if location longitude is greater than 180", (
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
146
|
-
})
|
|
119
|
+
}
|
|
147
120
|
})
|
|
148
121
|
|
|
149
|
-
it("should throw an error if location longitude is less than -180", (
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
157
|
-
})
|
|
131
|
+
}
|
|
158
132
|
})
|
|
159
133
|
|
|
160
|
-
it("should throw an error if destinationId is longer than 128 characters", (
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
172
|
-
})
|
|
147
|
+
}
|
|
173
148
|
})
|
|
174
149
|
|
|
175
|
-
it("should throw an error if email is not a valid email", (
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
183
|
-
})
|
|
159
|
+
}
|
|
184
160
|
})
|
|
185
161
|
|
|
186
|
-
it("should throw an error if name is more than 128 characters long", (
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
195
|
-
})
|
|
171
|
+
}
|
|
196
172
|
})
|
|
197
173
|
|
|
198
|
-
it("should throw an error if wait time alert is greater than goal", (
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
207
|
-
})
|
|
182
|
+
}
|
|
208
183
|
})
|
|
209
184
|
|
|
210
|
-
it("should throw an error if alert is not a number", (
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
219
|
-
})
|
|
193
|
+
}
|
|
220
194
|
})
|
|
221
195
|
|
|
222
|
-
it("should throw an error if goal is negative", (
|
|
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
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
230
|
-
})
|
|
205
|
+
}
|
|
231
206
|
})
|
|
232
207
|
|
|
233
|
-
it("should throw an error if consolidationAlert is less than the minimum", (
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
241
|
-
})
|
|
217
|
+
}
|
|
242
218
|
})
|
|
243
219
|
|
|
244
|
-
it("should throw an error if consolidationAlert is not a number", (
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
252
|
-
})
|
|
229
|
+
}
|
|
253
230
|
})
|
|
254
231
|
|
|
255
|
-
it("should throw an error if stateTemplateId is not a uuid", (
|
|
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
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
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 ', (
|
|
27
|
+
it('should validate a valid boundingBox ', async () => {
|
|
28
28
|
let BoundingBox = new BoundingBoxModel(boundingBox)
|
|
29
|
-
BoundingBox.validate(
|
|
30
|
-
|
|
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 ', (
|
|
32
|
+
it('should validate a valid boundingBox ', async () => {
|
|
36
33
|
let BoundingBox = new BoundingBoxModelBuiltInMongoose(boundingBox)
|
|
37
|
-
BoundingBox.validate(
|
|
38
|
-
|
|
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', (
|
|
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', (
|
|
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
|
-
|
|
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
|
-
|
|
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`, (
|
|
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
|
-
|
|
72
|
-
|
|
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
|
-
|
|
77
|
-
})
|
|
71
|
+
}
|
|
78
72
|
})
|
|
79
73
|
})
|
|
80
74
|
})
|
|
81
75
|
|
|
82
|
-
it('should be invalid when southWest and NorthEast are the same', (
|
|
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
|
-
|
|
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
|
-
|
|
94
|
-
})
|
|
88
|
+
}
|
|
95
89
|
})
|
|
96
90
|
|
|
97
|
-
it('should fail when area is less than 70 square metres', (
|
|
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
|
-
|
|
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
|
-
|
|
117
|
-
})
|
|
111
|
+
}
|
|
118
112
|
})
|
|
119
113
|
})
|
|
120
114
|
})
|