@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.
- 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 +3 -3
- package/utils/DbInitialiser/indexInitialiser.js +1 -1
- package/utils/validators.js +0 -1
|
@@ -23,70 +23,65 @@ beforeEach(() => {
|
|
|
23
23
|
|
|
24
24
|
testCase('Circle', () => {
|
|
25
25
|
testCase('Valid Circle', () => {
|
|
26
|
-
assertions('should validate zone with Circle ', (
|
|
26
|
+
assertions('should validate zone with Circle ', async () => {
|
|
27
27
|
let Circle = new CircleModel(circle)
|
|
28
|
-
Circle.validate(
|
|
29
|
-
|
|
30
|
-
assert(err === null, 'err should equals null')
|
|
31
|
-
done()
|
|
32
|
-
})
|
|
28
|
+
const res = await Circle.validate()
|
|
29
|
+
assert.notExists(res)
|
|
33
30
|
})
|
|
34
|
-
assertions('should validate zone with Circle (built in mongoose)', (
|
|
31
|
+
assertions('should validate zone with Circle (built in mongoose)', async () => {
|
|
35
32
|
let Circle = new CircleModelBuiltInMongoose(circle)
|
|
36
|
-
Circle.validate(
|
|
37
|
-
|
|
38
|
-
assert(err === null, 'err should equals null')
|
|
39
|
-
done()
|
|
40
|
-
})
|
|
33
|
+
const res = await Circle.validate()
|
|
34
|
+
assert.notExists(res)
|
|
41
35
|
})
|
|
42
36
|
|
|
43
|
-
assertions('should return Double type for longitude and latitude', (
|
|
37
|
+
assertions('should return Double type for longitude and latitude', () => {
|
|
44
38
|
circle.center = {"latitude": -37, "longitude": 144}
|
|
45
39
|
let Circle = new CircleModel(circle)
|
|
46
40
|
assert.isTrue(Circle.center.latitude instanceof mongoose.Types.Double)
|
|
47
41
|
assert.isTrue(Circle.center.longitude instanceof mongoose.Types.Double)
|
|
48
42
|
assert.isTrue(Circle.radius instanceof mongoose.Types.Double)
|
|
49
|
-
done()
|
|
50
43
|
})
|
|
51
44
|
})
|
|
52
45
|
|
|
53
46
|
testCase('Invalid Circle', () => {
|
|
54
47
|
// BD2571
|
|
55
|
-
assertions('should not validate a Circle with radius <5 meters', (
|
|
48
|
+
assertions('should not validate a Circle with radius <5 meters', async () => {
|
|
56
49
|
circle.radius = 3
|
|
57
50
|
let Circle = new CircleModelBuiltInMongoose(circle)
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
try {
|
|
52
|
+
await Circle.validate()
|
|
53
|
+
} catch (err) {
|
|
54
|
+
assert.exists(err, 'err object should exist')
|
|
60
55
|
assert.isObject(err.errors)
|
|
61
56
|
assert.strictEqual(err.errors.radius.message, `radius [3m] must be greater than 5m`)
|
|
62
|
-
|
|
63
|
-
})
|
|
57
|
+
}
|
|
64
58
|
})
|
|
65
59
|
|
|
66
|
-
assertions('should not validate a Circle with no radius', (
|
|
60
|
+
assertions('should not validate a Circle with no radius', async () => {
|
|
67
61
|
delete circle.radius
|
|
68
62
|
let Circle = new CircleModel(circle)
|
|
69
|
-
|
|
63
|
+
try {
|
|
64
|
+
await Circle.validate()
|
|
65
|
+
} catch (err) {
|
|
70
66
|
assert.exists(err, 'err object should exist')
|
|
71
67
|
assert.isObject(err.errors)
|
|
72
|
-
|
|
73
|
-
})
|
|
68
|
+
}
|
|
74
69
|
})
|
|
75
70
|
|
|
76
71
|
testCase('recursive property check', () => {
|
|
77
72
|
let requiredFields = rules.requiredFields
|
|
78
73
|
requiredFields.map((i) => {
|
|
79
|
-
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (
|
|
74
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
|
|
80
75
|
// delete i from geofeatures' circle child
|
|
81
76
|
delete circle[i]
|
|
82
77
|
let Circle = new CircleModel(circle)
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
try {
|
|
79
|
+
await Circle.validate()
|
|
80
|
+
} catch (err) {
|
|
85
81
|
assert.exists(err, 'err object should exist')
|
|
86
82
|
assert.isObject(err.errors)
|
|
87
83
|
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
88
|
-
|
|
89
|
-
})
|
|
84
|
+
}
|
|
90
85
|
})
|
|
91
86
|
})
|
|
92
87
|
})
|
|
@@ -23,55 +23,50 @@ beforeEach(() => {
|
|
|
23
23
|
})
|
|
24
24
|
testCase('Geoline', () => {
|
|
25
25
|
testCase('Valid Geoline', () => {
|
|
26
|
-
assertions('should validate a valid geoline ', (
|
|
26
|
+
assertions('should validate a valid geoline ', async () => {
|
|
27
27
|
let Geoline = new GeolineModel(geoline)
|
|
28
|
-
Geoline.validate(
|
|
29
|
-
|
|
30
|
-
assert(err === null, 'err should equals null')
|
|
31
|
-
done()
|
|
32
|
-
})
|
|
28
|
+
const res = await Geoline.validate()
|
|
29
|
+
assert.notExists(res)
|
|
33
30
|
})
|
|
34
|
-
assertions('should validate a valid geoline (built in mongoose)', (
|
|
31
|
+
assertions('should validate a valid geoline (built in mongoose)', async () => {
|
|
35
32
|
let Geoline = new GeolineModelBuiltInMongoose(geoline)
|
|
36
|
-
Geoline.validate(
|
|
37
|
-
|
|
38
|
-
assert(err === null, 'err should equals null')
|
|
39
|
-
done()
|
|
40
|
-
})
|
|
33
|
+
const res = await Geoline.validate()
|
|
34
|
+
assert.notExists(res)
|
|
41
35
|
})
|
|
42
36
|
|
|
43
|
-
assertions('should return Double type for longitude and latitude', (
|
|
37
|
+
assertions('should return Double type for longitude and latitude', async () => {
|
|
44
38
|
geoline.vertices[0] = {"latitude": -37, "longitude": 144}
|
|
45
39
|
let Geoline = new GeolineModel(geoline)
|
|
46
40
|
assert.isTrue(Geoline.vertices[0].latitude instanceof mongoose.Types.Double)
|
|
47
41
|
assert.isTrue(Geoline.vertices[0].longitude instanceof mongoose.Types.Double)
|
|
48
|
-
done()
|
|
49
42
|
})
|
|
50
43
|
})
|
|
51
44
|
|
|
52
45
|
testCase('Invalid Geoline', () => {
|
|
53
|
-
assertions('should not validate a geoline with invalid geoline', (
|
|
46
|
+
assertions('should not validate a geoline with invalid geoline', async () => {
|
|
54
47
|
delete geoline[rules.requiredFields[0]]
|
|
55
48
|
let Geoline = new GeolineModel(geoline)
|
|
56
|
-
|
|
49
|
+
try {
|
|
50
|
+
await Geoline.validate()
|
|
51
|
+
} catch (err) {
|
|
57
52
|
assert.exists(err, 'err object should exist')
|
|
58
53
|
assert.isObject(err.errors)
|
|
59
|
-
|
|
60
|
-
})
|
|
54
|
+
}
|
|
61
55
|
})
|
|
62
56
|
testCase('check each required property of the model and validate that it is present', () => {
|
|
63
57
|
let requiredFields = rules.requiredFields
|
|
64
58
|
requiredFields.map((i) => {
|
|
65
|
-
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (
|
|
59
|
+
assertions(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
|
|
66
60
|
// delete i from geofeatures' geoline child
|
|
67
61
|
delete geoline[i]
|
|
68
62
|
let Geoline = new GeolineModel(geoline)
|
|
69
|
-
|
|
63
|
+
try {
|
|
64
|
+
await Geoline.validate()
|
|
65
|
+
} catch (err) {
|
|
70
66
|
assert.exists(err, 'err object should exist')
|
|
71
67
|
assert.isObject(err.errors)
|
|
72
68
|
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
73
|
-
|
|
74
|
-
})
|
|
69
|
+
}
|
|
75
70
|
})
|
|
76
71
|
})
|
|
77
72
|
})
|
|
@@ -18,62 +18,56 @@ beforeEach(() => {
|
|
|
18
18
|
|
|
19
19
|
describe('Polygon', () => {
|
|
20
20
|
describe('Valid Polygon', () => {
|
|
21
|
-
it('should validate a valid polygon ', (
|
|
21
|
+
it('should validate a valid polygon ', async () => {
|
|
22
22
|
let Polygon = new PolygonModel(polygon)
|
|
23
|
-
Polygon.validate(
|
|
24
|
-
|
|
25
|
-
assert(err === null, 'err should equals null')
|
|
26
|
-
done()
|
|
27
|
-
})
|
|
23
|
+
const res = await Polygon.validate()
|
|
24
|
+
assert.notExists(res)
|
|
28
25
|
})
|
|
29
|
-
it('should validate a valid polygon (built in mongoose)', (
|
|
26
|
+
it('should validate a valid polygon (built in mongoose)', async () => {
|
|
30
27
|
let Polygon = new PolygonModelBuiltInMongoose(polygon)
|
|
31
|
-
Polygon.validate(
|
|
32
|
-
|
|
33
|
-
assert(err === null, 'err should equals null')
|
|
34
|
-
done()
|
|
35
|
-
})
|
|
28
|
+
const res = await Polygon.validate()
|
|
29
|
+
assert.notExists(res)
|
|
36
30
|
})
|
|
37
31
|
|
|
38
|
-
it('should return Double type for longitude and latitude', (
|
|
32
|
+
it('should return Double type for longitude and latitude', async () => {
|
|
39
33
|
polygon.vertices[0] = {"latitude": -37, "longitude": 144}
|
|
40
34
|
let Polygon = new PolygonModel(polygon)
|
|
41
35
|
assert.isTrue(Polygon.vertices[0].latitude instanceof mongoose.Types.Double)
|
|
42
36
|
assert.isTrue(Polygon.vertices[0].longitude instanceof mongoose.Types.Double)
|
|
43
|
-
done()
|
|
44
37
|
})
|
|
45
38
|
})
|
|
46
39
|
|
|
47
40
|
describe('Invalid Polygon', () => {
|
|
48
|
-
it('should not validate a polygon with invalid Polygon', (
|
|
41
|
+
it('should not validate a polygon with invalid Polygon', async () => {
|
|
49
42
|
delete polygon[rules.requiredFields[0]]
|
|
50
43
|
let Polygon = new PolygonModel(polygon)
|
|
51
|
-
|
|
44
|
+
try {
|
|
45
|
+
await Polygon.validate()
|
|
46
|
+
} catch (err) {
|
|
52
47
|
assert.exists(err, 'err object should exist')
|
|
53
48
|
assert.isObject(err.errors)
|
|
54
|
-
|
|
55
|
-
})
|
|
49
|
+
}
|
|
56
50
|
})
|
|
57
51
|
|
|
58
52
|
describe('check each required property of the model and validate that it is present', () => {
|
|
59
53
|
let requiredFields = rules.requiredFields
|
|
60
54
|
requiredFields.map((i) => {
|
|
61
|
-
it(`should throw an error with property '${i}' if '${i}' is not present`, (
|
|
55
|
+
it(`should throw an error with property '${i}' if '${i}' is not present`, async () => {
|
|
62
56
|
// delete i from geofeatures' polygon child
|
|
63
57
|
delete polygon[i]
|
|
64
58
|
let Polygon = new PolygonModel(polygon)
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
try {
|
|
60
|
+
await Polygon.validate()
|
|
61
|
+
} catch (err) {
|
|
67
62
|
assert.exists(err, 'err object should exist')
|
|
68
63
|
assert.isObject(err.errors)
|
|
69
64
|
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
70
|
-
|
|
71
|
-
})
|
|
65
|
+
}
|
|
72
66
|
})
|
|
73
67
|
})
|
|
74
68
|
})
|
|
75
69
|
|
|
76
|
-
it('when it has less than 3 vertices, it should error', (
|
|
70
|
+
it('when it has less than 3 vertices, it should error', async () => {
|
|
77
71
|
polygon.vertices = [{
|
|
78
72
|
"latitude": -37.81902680201739,
|
|
79
73
|
"longitude": 144.9821037054062
|
|
@@ -84,15 +78,16 @@ describe('Polygon', () => {
|
|
|
84
78
|
}]
|
|
85
79
|
|
|
86
80
|
let Polygon = new PolygonModel(polygon)
|
|
87
|
-
|
|
81
|
+
try {
|
|
82
|
+
await Polygon.validate()
|
|
83
|
+
} catch (err) {
|
|
88
84
|
const regex = new RegExp(CANT_HAVE_THREE_OR_MORE_VERTICES)
|
|
89
85
|
assert.match(err, regex)
|
|
90
|
-
|
|
91
|
-
})
|
|
86
|
+
}
|
|
92
87
|
})
|
|
93
88
|
|
|
94
|
-
describe('For any given vertex, if any of the next 2 vertices (accurate to 6 decimal points) are the same, it should error', (
|
|
95
|
-
it('next vertice is the same', (
|
|
89
|
+
describe('For any given vertex, if any of the next 2 vertices (accurate to 6 decimal points) are the same, it should error', async () => {
|
|
90
|
+
it('next vertice is the same', async () => {
|
|
96
91
|
polygon.vertices = [{
|
|
97
92
|
"latitude": -37.81902680201733,
|
|
98
93
|
"longitude": 144.9821037054044
|
|
@@ -108,14 +103,15 @@ describe('Polygon', () => {
|
|
|
108
103
|
}]
|
|
109
104
|
|
|
110
105
|
let Polygon = new PolygonModel(polygon)
|
|
111
|
-
|
|
106
|
+
try {
|
|
107
|
+
await Polygon.validate()
|
|
108
|
+
} catch (err) {
|
|
112
109
|
const regex = new RegExp(VERTICES_TOO_CLOSE)
|
|
113
110
|
assert.match(err, regex)
|
|
114
|
-
|
|
115
|
-
})
|
|
111
|
+
}
|
|
116
112
|
})
|
|
117
113
|
|
|
118
|
-
it('the one after next is the same', (
|
|
114
|
+
it('the one after next is the same', async () => {
|
|
119
115
|
polygon.vertices = [{
|
|
120
116
|
"latitude": -37.81902680201739,
|
|
121
117
|
"longitude": 144.9821037054062
|
|
@@ -131,15 +127,16 @@ describe('Polygon', () => {
|
|
|
131
127
|
}]
|
|
132
128
|
|
|
133
129
|
let Polygon = new PolygonModel(polygon)
|
|
134
|
-
|
|
130
|
+
try {
|
|
131
|
+
await Polygon.validate()
|
|
132
|
+
} catch (err) {
|
|
135
133
|
const regex = new RegExp(VERTICES_TOO_CLOSE)
|
|
136
134
|
assert.match(err, regex)
|
|
137
|
-
|
|
138
|
-
})
|
|
135
|
+
}
|
|
139
136
|
})
|
|
140
137
|
})
|
|
141
138
|
|
|
142
|
-
it('should fail when area is less than 70 square metres', (
|
|
139
|
+
it('should fail when area is less than 70 square metres', async () => {
|
|
143
140
|
polygon.geometry ={
|
|
144
141
|
type: "Polygon",
|
|
145
142
|
coordinates: [
|
|
@@ -153,13 +150,13 @@ describe('Polygon', () => {
|
|
|
153
150
|
]
|
|
154
151
|
}
|
|
155
152
|
let Polygon = new PolygonModel(polygon)
|
|
156
|
-
|
|
157
|
-
|
|
153
|
+
try {
|
|
154
|
+
await Polygon.validate()
|
|
155
|
+
} catch (err) {
|
|
158
156
|
assert.exists(err, 'err object should exist')
|
|
159
157
|
assert.isObject(err.errors)
|
|
160
158
|
assert.match(err.message, /(Polygon area should be at least 70 square metres)/i)
|
|
161
|
-
|
|
162
|
-
})
|
|
159
|
+
}
|
|
163
160
|
})
|
|
164
161
|
})
|
|
165
162
|
})
|
package/__tests__/helpers.js
CHANGED
|
@@ -3,24 +3,26 @@ let assert = chai.assert
|
|
|
3
3
|
|
|
4
4
|
let helpers = {}
|
|
5
5
|
|
|
6
|
-
helpers.testFalsyValue = (falsyValue, arrayField, docObject, model
|
|
6
|
+
helpers.testFalsyValue = async (falsyValue, arrayField, docObject, model) => {
|
|
7
7
|
docObject = JSON.parse(JSON.stringify(docObject))
|
|
8
8
|
docObject[arrayField] = [falsyValue]
|
|
9
9
|
const Model = new model(docObject)
|
|
10
|
-
|
|
10
|
+
try {
|
|
11
|
+
await Model.validate()
|
|
12
|
+
} catch (err) {
|
|
11
13
|
assert.exists(err)
|
|
12
14
|
assert(err instanceof Error, "Should throw error.")
|
|
13
|
-
|
|
14
|
-
})
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
helpers.testNullValue = (docObject, model
|
|
18
|
+
helpers.testNullValue = async (docObject, model) => {
|
|
18
19
|
let Model = new model(docObject)
|
|
19
|
-
|
|
20
|
+
try {
|
|
21
|
+
await Model.validate()
|
|
22
|
+
} catch (err) {
|
|
20
23
|
assert.exists(err, 'err object should exist')
|
|
21
24
|
assert(err instanceof Error, "Should throw error.")
|
|
22
|
-
|
|
23
|
-
})
|
|
25
|
+
}
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
helpers.removeDuplicatedTags = zone => {
|
|
@@ -20,32 +20,27 @@ beforeEach(() => {
|
|
|
20
20
|
|
|
21
21
|
describe('MonthlyStat', () => {
|
|
22
22
|
describe('Valid MonthlyStat document', () => {
|
|
23
|
-
it('should validate a valid MonthlyStat document ', (
|
|
23
|
+
it('should validate a valid MonthlyStat document ', async () => {
|
|
24
24
|
let MonthlyStats = new MonthlyStatsModel(monthlyStats)
|
|
25
|
-
MonthlyStats.validate(
|
|
26
|
-
|
|
27
|
-
assert(err === null, 'err should equals null')
|
|
28
|
-
done()
|
|
29
|
-
})
|
|
25
|
+
const res = await MonthlyStats.validate()
|
|
26
|
+
assert.notExists(res)
|
|
30
27
|
})
|
|
31
|
-
it('should validate a valid MonthlyStat document ', (
|
|
28
|
+
it('should validate a valid MonthlyStat document ', async () => {
|
|
32
29
|
let MonthlyStats = new MonthlyStatsModelBuiltInMongoose(monthlyStats)
|
|
33
|
-
MonthlyStats.validate(
|
|
34
|
-
|
|
35
|
-
assert(err === null, 'err should equals null')
|
|
36
|
-
done()
|
|
37
|
-
})
|
|
30
|
+
const res = await MonthlyStats.validate()
|
|
31
|
+
assert.notExists(res)
|
|
38
32
|
})
|
|
39
|
-
it('should not accept a invalid accountId', (
|
|
33
|
+
it('should not accept a invalid accountId', async () => {
|
|
40
34
|
monthlyStats.accountId = 'invalid-accountId'
|
|
41
35
|
let MonthlyStats = new MonthlyStatsModel(monthlyStats)
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
try {
|
|
37
|
+
await MonthlyStats.validate()
|
|
38
|
+
} catch (err) {
|
|
39
|
+
assert.exists(err, 'err object should exist')
|
|
44
40
|
assert.isObject(err.errors)
|
|
45
|
-
|
|
46
|
-
})
|
|
41
|
+
}
|
|
47
42
|
})
|
|
48
|
-
it('should not accept a invalid projectId', (
|
|
43
|
+
it('should not accept a invalid projectId', async () => {
|
|
49
44
|
const invalidProjectId = {
|
|
50
45
|
projectId: 'invalid-projectId',
|
|
51
46
|
iosUserCount: 0,
|
|
@@ -53,13 +48,14 @@ describe('MonthlyStat', () => {
|
|
|
53
48
|
}
|
|
54
49
|
monthlyStats.projects.push(invalidProjectId)
|
|
55
50
|
let MonthlyStats = new MonthlyStatsModel(monthlyStats)
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
try {
|
|
52
|
+
await MonthlyStats.validate()
|
|
53
|
+
} catch (err) {
|
|
54
|
+
assert.exists(err, 'err object should exist')
|
|
58
55
|
assert.isObject(err.errors)
|
|
59
|
-
|
|
60
|
-
})
|
|
56
|
+
}
|
|
61
57
|
})
|
|
62
|
-
it('should not accept a negative monthlyUsers value', (
|
|
58
|
+
it('should not accept a negative monthlyUsers value', async () => {
|
|
63
59
|
const invalidUsersCount = {
|
|
64
60
|
projectId: 'd49fdf10-3744-462c-84f8-abad444d7044',
|
|
65
61
|
iosUserCount: -100,
|
|
@@ -67,11 +63,12 @@ describe('MonthlyStat', () => {
|
|
|
67
63
|
}
|
|
68
64
|
monthlyStats.projects.push(invalidUsersCount)
|
|
69
65
|
let MonthlyStats = new MonthlyStatsModel(monthlyStats)
|
|
70
|
-
|
|
66
|
+
try {
|
|
67
|
+
await MonthlyStats.validate()
|
|
68
|
+
} catch (err) {
|
|
71
69
|
assert.exists(err, 'Path `iosUserCount` (-100) is less than minimum allowed value (0)')
|
|
72
70
|
assert.isObject(err.errors)
|
|
73
|
-
|
|
74
|
-
})
|
|
71
|
+
}
|
|
75
72
|
})
|
|
76
73
|
})
|
|
77
74
|
})
|