@bluedot-innovation/models 8.2.0 → 8.2.2
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.data.json +4 -0
- package/__tests__/destination/destination.data.json +2 -1
- package/__tests__/destination/destination.spec.js +58 -0
- package/helpers.js +6 -0
- package/models/Destination.js +2 -1
- package/package.json +1 -1
- package/schemas/AccountFeatures.js +3 -1
- package/schemas/HelloSso.js +10 -0
- package/utils/DbInitialiser/indexInitialiser.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -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
|
})
|
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/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
|
})
|
|
@@ -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
|
}
|