@bluedot-innovation/models 8.2.2 → 8.2.3
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__/destination/destination.data.json +1 -2
- package/__tests__/destination/destination.spec.js +0 -58
- package/__tests__/project/project.data.json +2 -1
- package/__tests__/project/project.spec.js +56 -0
- package/helpers.js +1 -1
- package/models/Destination.js +1 -2
- package/package.json +1 -1
- package/schemas/ProjectHello.js +2 -0
- package/utils/DbInitialiser/indexInitialiser.js +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -58,16 +58,6 @@ 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
|
-
})
|
|
71
61
|
})
|
|
72
62
|
|
|
73
63
|
describe('Invalid Destination ', () => {
|
|
@@ -198,52 +188,4 @@ describe('Invalid Destination ', () => {
|
|
|
198
188
|
done()
|
|
199
189
|
})
|
|
200
190
|
})
|
|
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
|
-
})
|
|
249
191
|
})
|
|
@@ -113,6 +113,16 @@ describe('Project', () => {
|
|
|
113
113
|
done()
|
|
114
114
|
})
|
|
115
115
|
})
|
|
116
|
+
|
|
117
|
+
it('should validate a valid project without ssoLinkingCode', (done) => {
|
|
118
|
+
delete project.hello.ssoLinkingCode
|
|
119
|
+
let Project = new ProjectModel(project)
|
|
120
|
+
Project.validate((err, res) => {
|
|
121
|
+
assert.notExists(res)
|
|
122
|
+
assert(err === null, 'err equals null')
|
|
123
|
+
done()
|
|
124
|
+
})
|
|
125
|
+
})
|
|
116
126
|
})
|
|
117
127
|
testCase('Valid Project ', () => {
|
|
118
128
|
assertions('should validate a valid project ', (done) => {
|
|
@@ -643,6 +653,52 @@ describe('Project', () => {
|
|
|
643
653
|
})
|
|
644
654
|
})
|
|
645
655
|
|
|
656
|
+
describe("SSO linking code validation", () => {
|
|
657
|
+
it("should throw an error if ssoLinkingCode is shorter than 12 characters", (done) => {
|
|
658
|
+
project.hello.ssoLinkingCode = "HGDUS69SD"
|
|
659
|
+
let Project = new ProjectModel(project)
|
|
660
|
+
Project.validate((err, res) => {
|
|
661
|
+
assert.notExists(res)
|
|
662
|
+
assert.exists(err)
|
|
663
|
+
assert.match(err.message, /SSO linking code must be a 12 character capital alphanumeric text/)
|
|
664
|
+
done()
|
|
665
|
+
})
|
|
666
|
+
})
|
|
667
|
+
|
|
668
|
+
it("should throw an error if ssoLinkingCode is longer than 12 characters", (done) => {
|
|
669
|
+
project.hello.ssoLinkingCode = "HGDUS69SDASLDKJSFDHWUER7Y"
|
|
670
|
+
let Project = new ProjectModel(project)
|
|
671
|
+
Project.validate((err, res) => {
|
|
672
|
+
assert.notExists(res)
|
|
673
|
+
assert.exists(err)
|
|
674
|
+
assert.match(err.message, /SSO linking code must be a 12 character capital alphanumeric text/)
|
|
675
|
+
done()
|
|
676
|
+
})
|
|
677
|
+
})
|
|
678
|
+
|
|
679
|
+
it("should throw an error if ssoLinkingCode include lowercase characters", (done) => {
|
|
680
|
+
project.hello.ssoLinkingCode = "3HgDUs69SD95"
|
|
681
|
+
let Project = new ProjectModel(project)
|
|
682
|
+
Project.validate((err, res) => {
|
|
683
|
+
assert.notExists(res)
|
|
684
|
+
assert.exists(err)
|
|
685
|
+
assert.match(err.message, /SSO linking code must be a 12 character capital alphanumeric text/)
|
|
686
|
+
done()
|
|
687
|
+
})
|
|
688
|
+
})
|
|
689
|
+
|
|
690
|
+
it("should throw an error if ssoLinkingCode is empty", (done) => {
|
|
691
|
+
project.hello.ssoLinkingCode = ""
|
|
692
|
+
let Project = new ProjectModel(project)
|
|
693
|
+
Project.validate((err, res) => {
|
|
694
|
+
assert.notExists(res)
|
|
695
|
+
assert.exists(err)
|
|
696
|
+
assert.match(err.message, /SSO linking code must be a 12 character capital alphanumeric text/)
|
|
697
|
+
done()
|
|
698
|
+
})
|
|
699
|
+
})
|
|
700
|
+
})
|
|
701
|
+
|
|
646
702
|
})
|
|
647
703
|
|
|
648
704
|
describe('should throw an error when any of the values of the array contains a falsy value', () => {
|
package/helpers.js
CHANGED
|
@@ -247,7 +247,7 @@ helpers.validateLongitude = function(longitude){
|
|
|
247
247
|
return longitude >= -180 && longitude <= 180
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
helpers.
|
|
250
|
+
helpers.validateSsoLinkingCode = function(code){
|
|
251
251
|
const expression = '^[A-Z0-9]{12}$'
|
|
252
252
|
const regex = new RegExp(expression)
|
|
253
253
|
return regex.test(code)
|
package/models/Destination.js
CHANGED
|
@@ -17,8 +17,7 @@ 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 }
|
|
21
|
-
helloSsoCode: {type: String, validate: {validator: helpers.validateHelloSsoCode, msg: 'Hello SSO code must be a 12 character capital alphanumeric text'}}
|
|
20
|
+
waitTime: { type: WaitTime }
|
|
22
21
|
}, {collection: 'destination'})
|
|
23
22
|
|
|
24
23
|
DestinationSchema.plugin(patcher)
|
package/package.json
CHANGED
package/schemas/ProjectHello.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
|
+
const helpers = require('../helpers')
|
|
2
3
|
|
|
3
4
|
let ProjectHelloSchema = new mongoose.Schema({
|
|
4
5
|
registrationTtl: {type: Number, validate: { validator: Number.isInteger, msg: 'hello.registrationTtl should be an integer number' }},
|
|
6
|
+
ssoLinkingCode: {type: String, validate: {validator: helpers.validateSsoLinkingCode, msg: 'SSO linking code must be a 12 character capital alphanumeric text'}}
|
|
5
7
|
}, {
|
|
6
8
|
_id: false
|
|
7
9
|
})
|
|
@@ -53,16 +53,18 @@ const indexes = {
|
|
|
53
53
|
options: {
|
|
54
54
|
name: "geometry_index"
|
|
55
55
|
}
|
|
56
|
-
}
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
project: [
|
|
57
59
|
{
|
|
58
60
|
fields: {
|
|
59
|
-
|
|
61
|
+
ssoLinkingCode: 1
|
|
60
62
|
},
|
|
61
63
|
options: {
|
|
62
|
-
name: "
|
|
64
|
+
name: "ssoLinkingCode_index",
|
|
63
65
|
unique: true,
|
|
64
66
|
partialFilterExpression: {
|
|
65
|
-
|
|
67
|
+
ssoLinkingCode: { $type: "string" }
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
}
|