@bluedot-innovation/models 8.1.2 → 8.2.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 +6 -0
- package/Models.js +0 -4
- package/__tests__/account/account.data.json +5 -0
- package/__tests__/destination/destination.data.json +2 -1
- package/__tests__/destination/destination.spec.js +58 -0
- package/__tests__/zone/zone.rules.json +1 -2
- package/__tests__/zone/zone.spec.js +0 -45
- package/helpers.js +6 -0
- package/models/Destination.js +2 -1
- package/models/Zone.js +0 -22
- package/package.json +1 -1
- package/schemas/AccountFeatures.js +3 -1
- package/schemas/HelloSso.js +11 -0
- package/utils/DbInitialiser/indexInitialiser.js +12 -0
- package/__tests__/action/message/messageAction.data.json +0 -5
- package/__tests__/action/message/messageAction.rules.json +0 -3
- package/__tests__/action/message/messageAction.spec.js +0 -73
- package/__tests__/action/url/urlAction.data.json +0 -4
- package/__tests__/action/url/urlAction.rules.json +0 -3
- package/__tests__/action/url/urlAction.spec.js +0 -74
- package/__tests__/zone/zone.action.spec.js +0 -50
- package/models/MessageAction.js +0 -29
- package/models/UrlAction.js +0 -36
package/CHANGELOG.md
CHANGED
package/Models.js
CHANGED
|
@@ -7,9 +7,7 @@ let Models = {}
|
|
|
7
7
|
|
|
8
8
|
Models.Account = require('./models/Account').Model
|
|
9
9
|
Models.Destination = require('./models/Destination').Model
|
|
10
|
-
Models.MessageAction = require('./models/MessageAction').Model
|
|
11
10
|
Models.Project = require('./models/Project').Model
|
|
12
|
-
Models.UrlAction = require('./models/UrlAction').Model
|
|
13
11
|
Models.User = require('./models/User').Model
|
|
14
12
|
Models.Zone = require('./models/Zone').Model
|
|
15
13
|
|
|
@@ -48,10 +46,8 @@ let Schemas = {}
|
|
|
48
46
|
|
|
49
47
|
Schemas.Account = require('./models/Account').Schema
|
|
50
48
|
Schemas.Destination = require('./models/Destination').Schema
|
|
51
|
-
Schemas.MessageAction = require('./models/MessageAction').Schema
|
|
52
49
|
Schemas.Application = require('./models/Application').Schema
|
|
53
50
|
Schemas.Project = require('./models/Project').Schema
|
|
54
|
-
Schemas.UrlAction = require('./models/UrlAction').Schema
|
|
55
51
|
Schemas.User = require('./models/User').Schema
|
|
56
52
|
Schemas.Zone = require('./models/Zone').Schema
|
|
57
53
|
|
|
@@ -58,6 +58,16 @@ describe('Valid Destination ', () => {
|
|
|
58
58
|
done()
|
|
59
59
|
})
|
|
60
60
|
})
|
|
61
|
+
|
|
62
|
+
it('should validate a valid destination without helloSsoCode', (done) => {
|
|
63
|
+
delete destination.helloSsoCode
|
|
64
|
+
let Destination = new DestinationModel(destination)
|
|
65
|
+
Destination.validate((err, res) => {
|
|
66
|
+
assert.notExists(res)
|
|
67
|
+
assert(err === null, 'err equals null')
|
|
68
|
+
done()
|
|
69
|
+
})
|
|
70
|
+
})
|
|
61
71
|
})
|
|
62
72
|
|
|
63
73
|
describe('Invalid Destination ', () => {
|
|
@@ -188,4 +198,52 @@ describe('Invalid Destination ', () => {
|
|
|
188
198
|
done()
|
|
189
199
|
})
|
|
190
200
|
})
|
|
201
|
+
|
|
202
|
+
it("should throw an error if helloSsoCode is shorter than 12 characters", (done) => {
|
|
203
|
+
destination.helloSsoCode = "HGDUS69SD"
|
|
204
|
+
let Destination = new DestinationModel(destination)
|
|
205
|
+
Destination.validate((err, res) => {
|
|
206
|
+
assert.notExists(res)
|
|
207
|
+
assert.exists(err)
|
|
208
|
+
console.log(err.message)
|
|
209
|
+
assert.match(err.message, /Hello SSO code must be a 12 character capital alphanumeric text/)
|
|
210
|
+
done()
|
|
211
|
+
})
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it("should throw an error if helloSsoCode is longer than 12 characters", (done) => {
|
|
215
|
+
destination.helloSsoCode = "HGDUS69SDASLDKJSFDHWUER7Y"
|
|
216
|
+
let Destination = new DestinationModel(destination)
|
|
217
|
+
Destination.validate((err, res) => {
|
|
218
|
+
assert.notExists(res)
|
|
219
|
+
assert.exists(err)
|
|
220
|
+
console.log(err.message)
|
|
221
|
+
assert.match(err.message, /Hello SSO code must be a 12 character capital alphanumeric text/)
|
|
222
|
+
done()
|
|
223
|
+
})
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
it("should throw an error if helloSsoCode include lowercase characters", (done) => {
|
|
227
|
+
destination.helloSsoCode = "3HgDUs69SD95"
|
|
228
|
+
let Destination = new DestinationModel(destination)
|
|
229
|
+
Destination.validate((err, res) => {
|
|
230
|
+
assert.notExists(res)
|
|
231
|
+
assert.exists(err)
|
|
232
|
+
console.log(err.message)
|
|
233
|
+
assert.match(err.message, /Hello SSO code must be a 12 character capital alphanumeric text/)
|
|
234
|
+
done()
|
|
235
|
+
})
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it("should throw an error if helloSsoCode is empty", (done) => {
|
|
239
|
+
destination.helloSsoCode = ""
|
|
240
|
+
let Destination = new DestinationModel(destination)
|
|
241
|
+
Destination.validate((err, res) => {
|
|
242
|
+
assert.notExists(res)
|
|
243
|
+
assert.exists(err)
|
|
244
|
+
console.log(err.message)
|
|
245
|
+
assert.match(err.message, /Hello SSO code must be a 12 character capital alphanumeric text/)
|
|
246
|
+
done()
|
|
247
|
+
})
|
|
248
|
+
})
|
|
191
249
|
})
|
|
@@ -131,51 +131,6 @@ describe('Zone', () => {
|
|
|
131
131
|
})
|
|
132
132
|
})
|
|
133
133
|
|
|
134
|
-
it('should throw an error when action is invalid', (done) => {
|
|
135
|
-
delete zone.actions[1].url
|
|
136
|
-
let Zone = new ZoneModel(zone)
|
|
137
|
-
Zone.validate((err, res) => {
|
|
138
|
-
assert.exists(err, 'err object should exist')
|
|
139
|
-
assert.isObject(err.errors)
|
|
140
|
-
assert('actions.1.url' in err.errors, `errors should have a 'actions.1.url' property`)
|
|
141
|
-
done()
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('should throw an error when action type is missing', (done) => {
|
|
146
|
-
delete zone.actions[0].type
|
|
147
|
-
delete zone.actions[1].type
|
|
148
|
-
let Zone = new ZoneModel(zone)
|
|
149
|
-
Zone.validate((err, res) => {
|
|
150
|
-
assert.exists(err, 'err object should exist')
|
|
151
|
-
assert.isObject(err.errors)
|
|
152
|
-
assert.match(err.message, /(Action requires a type of `url` or `message`.)/i)
|
|
153
|
-
done()
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
it('should throw an error when action object is empty', (done) => {
|
|
158
|
-
zone.actions = [{}]
|
|
159
|
-
let Zone = new ZoneModel(zone)
|
|
160
|
-
Zone.validate((err, res) => {
|
|
161
|
-
assert.exists(err, 'err object should exist')
|
|
162
|
-
assert.isObject(err.errors)
|
|
163
|
-
assert.match(err.message, /(Action requires a type of `url` or `message`.)/i)
|
|
164
|
-
done()
|
|
165
|
-
})
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
it('should throw an error when actions is null', (done) => {
|
|
169
|
-
zone.actions = null
|
|
170
|
-
let Zone = new ZoneModel(zone)
|
|
171
|
-
Zone.validate((err, res) => {
|
|
172
|
-
assert.exists(err, 'err object should exist')
|
|
173
|
-
assert.isObject(err.errors)
|
|
174
|
-
assert.match(err.message, /(actions must have a value)/i)
|
|
175
|
-
done()
|
|
176
|
-
})
|
|
177
|
-
})
|
|
178
|
-
|
|
179
134
|
it('should throw an error when a condition is invalid', (done) => {
|
|
180
135
|
zone.conditions[0].startDate = 'abc'
|
|
181
136
|
let Zone = new ZoneModel(zone)
|
package/helpers.js
CHANGED
|
@@ -247,4 +247,10 @@ helpers.validateLongitude = function(longitude){
|
|
|
247
247
|
return longitude >= -180 && longitude <= 180
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
helpers.validateHelloSsoCode = function(code){
|
|
251
|
+
const expression = '^[A-Z0-9]{12}$'
|
|
252
|
+
const regex = new RegExp(expression)
|
|
253
|
+
return regex.test(code)
|
|
254
|
+
}
|
|
255
|
+
|
|
250
256
|
module.exports = helpers
|
package/models/Destination.js
CHANGED
|
@@ -17,7 +17,8 @@ const DestinationSchema = new mongoose.Schema({
|
|
|
17
17
|
projectId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, msg: 'Invalid projectId'}},
|
|
18
18
|
creationTime: {type: Date, default: Date.now},
|
|
19
19
|
lastUpdateTime: {type: Date, default: Date.now},
|
|
20
|
-
waitTime: { type: WaitTime }
|
|
20
|
+
waitTime: { type: WaitTime },
|
|
21
|
+
helloSsoCode: {type: String, validate: {validator: helpers.validateHelloSsoCode, msg: 'Hello SSO code must be a 12 character capital alphanumeric text'}}
|
|
21
22
|
}, {collection: 'destination'})
|
|
22
23
|
|
|
23
24
|
DestinationSchema.plugin(patcher)
|
package/models/Zone.js
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
let mongoose = require('mongoose')
|
|
8
8
|
let Schema = mongoose.Schema
|
|
9
9
|
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
10
|
-
let messageActionSchema = require('./MessageAction').messageActionSchema
|
|
11
|
-
let urlActionSchema = require('./UrlAction').urlActionSchema
|
|
12
10
|
let circleSchema = require('./geofeatures/Circle').circleSchema
|
|
13
11
|
let boundingBoxSchema = require('./geofeatures/BoundingBox').boundingBoxSchema
|
|
14
12
|
let geolineSchema = require('./geofeatures/Geoline').geolineSchema
|
|
@@ -42,16 +40,6 @@ const tagsFormation = (zone) => {
|
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
let actionSchema = new Schema({},
|
|
46
|
-
{ discriminatorKey: 'type', _id: false })
|
|
47
|
-
|
|
48
|
-
actionSchema.pre('validate', function(next){
|
|
49
|
-
if(this.type === undefined){
|
|
50
|
-
return next(new Error('Action requires a type of `url` or `message`.'))
|
|
51
|
-
}
|
|
52
|
-
next()
|
|
53
|
-
})
|
|
54
|
-
|
|
55
43
|
let conditionSchema = new Schema({},
|
|
56
44
|
{ discriminatorKey: 'type', _id: false })
|
|
57
45
|
|
|
@@ -96,13 +84,6 @@ let zoneSchema = new Schema({
|
|
|
96
84
|
message: 'conditions must have a value'
|
|
97
85
|
}
|
|
98
86
|
},
|
|
99
|
-
actions: {
|
|
100
|
-
type: [actionSchema],
|
|
101
|
-
validate: {
|
|
102
|
-
validator: helpers.validateNotNull,
|
|
103
|
-
message: 'actions must have a value'
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
87
|
geofeatures: {
|
|
107
88
|
type: [geofeatureSchema],
|
|
108
89
|
required: true,
|
|
@@ -125,9 +106,6 @@ let zoneSchema = new Schema({
|
|
|
125
106
|
// plugin for PATCH operations
|
|
126
107
|
zoneSchema.plugin(patcher)
|
|
127
108
|
|
|
128
|
-
zoneSchema.path('actions').discriminator('url', new Schema(urlActionSchema, {_id: false}))
|
|
129
|
-
zoneSchema.path('actions').discriminator('message', new Schema(messageActionSchema, {_id: false}))
|
|
130
|
-
|
|
131
109
|
zoneSchema.path('conditions').discriminator('dayRange', new Schema(dayRangeRawSchema, {_id: false}))
|
|
132
110
|
zoneSchema.path('conditions').discriminator('speed', new Schema(speedRawSchema, {_id: false}))
|
|
133
111
|
zoneSchema.path('conditions').discriminator('timeActive', new Schema(timeActiveRawSchema, {_id: false}))
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ let AccountTempoSchema = require('./AccountTempo')
|
|
|
3
3
|
let AccountBasicFeatureSchema = require('./AccountBasicFeature')
|
|
4
4
|
let AccountScreensSchema = require('./AccountScreens')
|
|
5
5
|
let AccountCemdPersistenceSchema = require('./AccountCemdPersistence')
|
|
6
|
+
let HelloSsoSchema = require('./HelloSso')
|
|
6
7
|
|
|
7
8
|
let AccountFeaturesSchema = new mongoose.Schema({
|
|
8
9
|
tempo: AccountTempoSchema,
|
|
@@ -12,7 +13,8 @@ let AccountFeaturesSchema = new mongoose.Schema({
|
|
|
12
13
|
cemdPersistence: AccountCemdPersistenceSchema,
|
|
13
14
|
hideStores: AccountBasicFeatureSchema,
|
|
14
15
|
automaticDestinationCreation: AccountBasicFeatureSchema,
|
|
15
|
-
nowReadyConfiguration: AccountBasicFeatureSchema
|
|
16
|
+
nowReadyConfiguration: AccountBasicFeatureSchema,
|
|
17
|
+
helloSso: HelloSsoSchema
|
|
16
18
|
}, {
|
|
17
19
|
_id: false
|
|
18
20
|
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let HelloSsoSchema = new mongoose.Schema({
|
|
4
|
+
enabled: {type: Boolean, default: true},
|
|
5
|
+
identityProvider: {type: String, required: true},
|
|
6
|
+
domain: {type: String, required: true}
|
|
7
|
+
}, {
|
|
8
|
+
_id: false
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
module.exports = HelloSsoSchema
|
|
@@ -53,6 +53,18 @@ const indexes = {
|
|
|
53
53
|
options: {
|
|
54
54
|
name: "geometry_index"
|
|
55
55
|
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
fields: {
|
|
59
|
+
helloSsoCode: 1
|
|
60
|
+
},
|
|
61
|
+
options: {
|
|
62
|
+
name: "helloSsoCode_index",
|
|
63
|
+
unique: true,
|
|
64
|
+
partialFilterExpression: {
|
|
65
|
+
helloSsoCode: { $type: "string" }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
56
68
|
}
|
|
57
69
|
]
|
|
58
70
|
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
let mongoose = require('mongoose')
|
|
2
|
-
|
|
3
|
-
mongoose.Promise = global.Promise
|
|
4
|
-
|
|
5
|
-
let MessageActionModel = require('../../../Models').MessageAction(mongoose)
|
|
6
|
-
let MessageActionModelBuiltInMongoose = require('../../../Models').MessageAction()
|
|
7
|
-
|
|
8
|
-
let testCase = require('mocha').describe
|
|
9
|
-
let assertions = require('mocha').it
|
|
10
|
-
let chai = require('chai')
|
|
11
|
-
|
|
12
|
-
let assert = chai.assert
|
|
13
|
-
let mocha = require('mocha')
|
|
14
|
-
let beforeEach = mocha.beforeEach
|
|
15
|
-
let rules = require('./messageAction.rules.json')
|
|
16
|
-
|
|
17
|
-
let messageAction
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
messageAction = JSON.parse(JSON.stringify(require('./messageAction.data.json')))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
testCase('MessageAction', () => {
|
|
24
|
-
testCase('Valid MessageAction', () => {
|
|
25
|
-
assertions('should validate a valid messageAction ', (done) => {
|
|
26
|
-
let MessageAction = new MessageActionModel(messageAction)
|
|
27
|
-
MessageAction.validate((err, res) => {
|
|
28
|
-
assert.notExists(res)
|
|
29
|
-
assert(err === null, 'err should equals null')
|
|
30
|
-
done()
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
testCase('Valid MessageAction', () => {
|
|
35
|
-
assertions('should validate a valid messageAction ', (done) => {
|
|
36
|
-
let MessageAction = new MessageActionModelBuiltInMongoose(messageAction)
|
|
37
|
-
MessageAction.validate((err, res) => {
|
|
38
|
-
assert.notExists(res)
|
|
39
|
-
assert(err === null, 'err should equals null')
|
|
40
|
-
done()
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
testCase('Invalid MessageAction', () => {
|
|
46
|
-
assertions('should not validate a messageAction with invalid MessageAction', (done) => {
|
|
47
|
-
delete messageAction[rules.requiredFields[0]]
|
|
48
|
-
let MessageAction = new MessageActionModel(messageAction)
|
|
49
|
-
MessageAction.validate((err, res) => {
|
|
50
|
-
assert.exists(err, 'err object should exist')
|
|
51
|
-
assert.isObject(err.errors)
|
|
52
|
-
done()
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
testCase('check each required property of the model and validate that it is present', () => {
|
|
56
|
-
let requiredFields = rules.requiredFields
|
|
57
|
-
requiredFields.map((i) => {
|
|
58
|
-
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
59
|
-
// delete i from geofeatures' messageAction child
|
|
60
|
-
delete messageAction[i]
|
|
61
|
-
let MessageAction = new MessageActionModel(messageAction)
|
|
62
|
-
MessageAction.validate((err, res) => {
|
|
63
|
-
assert.notExists(res)
|
|
64
|
-
assert.exists(err, 'err object should exist')
|
|
65
|
-
assert.isObject(err.errors)
|
|
66
|
-
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
67
|
-
done()
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
})
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
let mongoose = require('mongoose')
|
|
2
|
-
|
|
3
|
-
mongoose.Promise = global.Promise
|
|
4
|
-
|
|
5
|
-
let UrlactionModel = require('../../../Models').UrlAction(mongoose)
|
|
6
|
-
let UrlactionModelBuiltInMongoose = require('../../../Models').UrlAction()
|
|
7
|
-
let testCase = require('mocha').describe
|
|
8
|
-
let assertions = require('mocha').it
|
|
9
|
-
let chai = require('chai')
|
|
10
|
-
|
|
11
|
-
let assert = chai.assert
|
|
12
|
-
let mocha = require('mocha')
|
|
13
|
-
let beforeEach = mocha.beforeEach
|
|
14
|
-
|
|
15
|
-
let rules = require('./urlAction.rules.json')
|
|
16
|
-
|
|
17
|
-
let urlaction
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
urlaction = JSON.parse(JSON.stringify(require('./urlAction.data.json')))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
testCase('Urlaction', () => {
|
|
24
|
-
testCase('Valid Urlaction', () => {
|
|
25
|
-
assertions('should validate a valid urlaction ', (done) => {
|
|
26
|
-
let Urlaction = new UrlactionModel(urlaction)
|
|
27
|
-
Urlaction.validate((err, res) => {
|
|
28
|
-
assert.notExists(res)
|
|
29
|
-
assert(err === null, 'err should equals null')
|
|
30
|
-
done()
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
testCase('Valid Urlaction (Built in mongoose)', () => {
|
|
36
|
-
assertions('should validate a valid urlaction ', (done) => {
|
|
37
|
-
let Urlaction = new UrlactionModelBuiltInMongoose(urlaction)
|
|
38
|
-
Urlaction.validate((err, res) => {
|
|
39
|
-
assert.notExists(res)
|
|
40
|
-
assert(err === null, 'err should equals null')
|
|
41
|
-
done()
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
testCase('Invalid Urlaction', () => {
|
|
47
|
-
assertions('should not validate a urlaction with invalid Urlaction', (done) => {
|
|
48
|
-
delete urlaction[rules.requiredFields[0]]
|
|
49
|
-
let Urlaction = new UrlactionModel(urlaction)
|
|
50
|
-
Urlaction.validate((err, res) => {
|
|
51
|
-
assert.exists(err, 'err object should exist')
|
|
52
|
-
assert.isObject(err.errors)
|
|
53
|
-
done()
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
testCase('check each required property of the model and validate that it is present', () => {
|
|
57
|
-
let requiredFields = rules.requiredFields
|
|
58
|
-
requiredFields.map((i) => {
|
|
59
|
-
assertions(`should throw an error with property '${i}' if '${i}' is not present`, (done) => {
|
|
60
|
-
// delete i from geofeatures' urlaction child
|
|
61
|
-
delete urlaction[i]
|
|
62
|
-
let Urlaction = new UrlactionModel(urlaction)
|
|
63
|
-
Urlaction.validate((err, res) => {
|
|
64
|
-
assert.notExists(res)
|
|
65
|
-
assert.exists(err, 'err object should exist')
|
|
66
|
-
assert.isObject(err.errors)
|
|
67
|
-
assert.nestedProperty(err, `errors.${i}`, `error should have a ${i} property`)
|
|
68
|
-
done()
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
})
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
let mongoose = require('mongoose')
|
|
2
|
-
|
|
3
|
-
mongoose.Promise = global.Promise
|
|
4
|
-
|
|
5
|
-
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
6
|
-
let testCase = require('mocha').describe
|
|
7
|
-
let assertions = require('mocha').it
|
|
8
|
-
let chai = require('chai')
|
|
9
|
-
let assert = chai.assert
|
|
10
|
-
let mocha = require('mocha')
|
|
11
|
-
let beforeEach = mocha.beforeEach
|
|
12
|
-
|
|
13
|
-
let zone
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
17
|
-
// remove conditions as it's not tested
|
|
18
|
-
delete zone.conditions
|
|
19
|
-
// remove all but 1 geofeatures as geofeatures are required
|
|
20
|
-
zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/circle/i))
|
|
21
|
-
// remove customData
|
|
22
|
-
delete zone.customData
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
testCase('Zone - Action', () => {
|
|
26
|
-
testCase('Valid Zone - Action', () => {
|
|
27
|
-
assertions('should not throw an error when a valid action is instantiated within a zone', (done) => {
|
|
28
|
-
let Zone = new ZoneModel(zone)
|
|
29
|
-
Zone.validate((err, res) => {
|
|
30
|
-
assert.notExists(res)
|
|
31
|
-
assert(err === null, 'err equals null')
|
|
32
|
-
done()
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
testCase('Invalid Zone - Action', () => {
|
|
38
|
-
assertions('should throw an error when an invalid action is instantiated within a zone', (done) => {
|
|
39
|
-
delete zone.actions[1].url
|
|
40
|
-
let Zone = new ZoneModel(zone)
|
|
41
|
-
Zone.validate((err, res) => {
|
|
42
|
-
assert.exists(err, 'err object should exist')
|
|
43
|
-
assert.isObject(err.errors)
|
|
44
|
-
assert('actions.1.url' in err.errors)
|
|
45
|
-
assert.notNestedProperty(err, `errors.geofeatures`, 'error should have a url property')
|
|
46
|
-
done()
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
})
|
package/models/MessageAction.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
let mongoose = require('mongoose')
|
|
2
|
-
|
|
3
|
-
let schema = {
|
|
4
|
-
title: {type: String, required: [true, 'title is required. ']},
|
|
5
|
-
message: {type: String, required: [true, 'message is required. ']}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
let MessageActionSchema = new mongoose.Schema(schema, {
|
|
9
|
-
_id: false,
|
|
10
|
-
versionKey: false
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
MessageActionSchema.add({
|
|
14
|
-
type: {type: String, required: true}
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
// optional mongoose
|
|
18
|
-
let model = (mongooseInstance) => {
|
|
19
|
-
let MessageAction
|
|
20
|
-
if (mongooseInstance) {
|
|
21
|
-
MessageAction = mongooseInstance.model('MessageAction', MessageActionSchema)
|
|
22
|
-
} else {
|
|
23
|
-
MessageAction = mongoose.model('MessageAction', MessageActionSchema)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return MessageAction
|
|
27
|
-
}
|
|
28
|
-
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
29
|
-
module.exports = { Model: model, Schema: MessageActionSchema, messageActionSchema: schema }
|
package/models/UrlAction.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
let mongoose = require('mongoose')
|
|
2
|
-
let validators = require('../utils/validators')
|
|
3
|
-
|
|
4
|
-
let schema = {
|
|
5
|
-
url: {
|
|
6
|
-
type: String,
|
|
7
|
-
required: [true, 'url is required. '],
|
|
8
|
-
validate: {
|
|
9
|
-
validator: validators.validateUrl
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let URLActionSchema = new mongoose.Schema(schema, {
|
|
15
|
-
_id: false,
|
|
16
|
-
__v: false
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
URLActionSchema.add({
|
|
20
|
-
type: {type: String, required: true}
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
// optional mongoose
|
|
24
|
-
const model = (mongooseInstance) => {
|
|
25
|
-
let Urlaction
|
|
26
|
-
if (mongooseInstance) {
|
|
27
|
-
Urlaction = mongooseInstance.model('Urlaction', URLActionSchema)
|
|
28
|
-
} else {
|
|
29
|
-
Urlaction = mongoose.model('Urlaction', URLActionSchema)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return Urlaction
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
36
|
-
module.exports = { Model: model, Schema: URLActionSchema, urlActionSchema: schema }
|