@bluedot-innovation/models 10.8.0 → 10.9.0

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 CHANGED
@@ -1,3 +1,6 @@
1
+ ## 10.8.0
2
+ - Add dashboardIdentityProvider to HelloSSO model
3
+
1
4
  ## 10.8.0
2
5
  - Add insightsConfiguration to Project model
3
6
 
@@ -39,7 +39,8 @@
39
39
  },
40
40
  "helloSso": {
41
41
  "enabled": true,
42
- "identityProvider": "coles-screens"
42
+ "identityProvider": "coles-screens",
43
+ "dashboardIdentityProvider": "coles-dashboard"
43
44
  },
44
45
  "canvasSso": {
45
46
  "enabled": true,
@@ -48,6 +48,14 @@ testCase('Account', () => {
48
48
  const res = await Account.validate()
49
49
  assert.notExists(res)
50
50
  })
51
+
52
+ it('Should valid the account when helloSso is undefined', async () => {
53
+ account = JSON.parse(JSON.stringify(account))
54
+ delete account.features.helloSso
55
+ const Account = new AccountModel(account)
56
+ const res = await Account.validate()
57
+ assert.notExists(res)
58
+ })
51
59
  })
52
60
 
53
61
  testCase('Invalid Account', () => {
@@ -69,6 +77,20 @@ testCase('Account', () => {
69
77
  })
70
78
  })
71
79
 
80
+ assertions('should throw an error when Account has helloSso enabled but none of providers is provided', async () => {
81
+ account = JSON.parse(JSON.stringify(account))
82
+ delete account.features.helloSso.identityProvider
83
+ delete account.features.helloSso.dashboardIdentityProvider
84
+ let Account = new AccountModel(account)
85
+ try {
86
+ await Account.validate()
87
+ } catch (err) {
88
+ assert.exists(err, 'err object should exist')
89
+ assert.isObject(err.errors)
90
+ assert.match(err.message, /When the feature is enbaled, at leat one of provider need to be provided./)
91
+ }
92
+ })
93
+
72
94
  assertions('should throw an error when Account has invalid type', async () => {
73
95
  let Account = new AccountModel(account)
74
96
  Account.type = "Invalid"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "10.8.0",
3
+ "version": "10.9.0",
4
4
  "main": "Models.js",
5
5
  "scripts": {
6
6
  "lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",
@@ -6,6 +6,14 @@ let AccountCemdPersistenceSchema = require('./AccountCemdPersistence')
6
6
  let HelloSsoSchema = require('./HelloSso')
7
7
  const CanvasSsoSchema = require('./CanvasSsoFeature')
8
8
 
9
+ function helloSsoValidator (value) {
10
+ const { enabled, identityProvider, dashboardIdentityProvider } = value
11
+ if (enabled && !identityProvider && !dashboardIdentityProvider) {
12
+ return false
13
+ }
14
+ return true
15
+ }
16
+
9
17
  let AccountFeaturesSchema = new mongoose.Schema({
10
18
  tempo: AccountTempoSchema,
11
19
  realTimeDashboard: AccountBasicFeatureSchema,
@@ -15,7 +23,7 @@ let AccountFeaturesSchema = new mongoose.Schema({
15
23
  hideStores: AccountBasicFeatureSchema,
16
24
  automaticDestinationCreation: AccountBasicFeatureSchema,
17
25
  nowReadyConfiguration: AccountBasicFeatureSchema,
18
- helloSso: HelloSsoSchema,
26
+ helloSso: { type: HelloSsoSchema, validate: { validator: helloSsoValidator, msg: 'When the feature is enbaled, at leat one of provider need to be provided.' } },
19
27
  canvasSso: CanvasSsoSchema,
20
28
  helloStateTemplates: AccountBasicFeatureSchema,
21
29
  }, {
@@ -2,7 +2,8 @@ let mongoose = require('mongoose')
2
2
 
3
3
  let HelloSsoSchema = new mongoose.Schema({
4
4
  enabled: {type: Boolean, default: true},
5
- identityProvider: {type: String, required: true}
5
+ identityProvider: {type: String, required: false},
6
+ dashboardIdentityProvider: {type: String, required: false}
6
7
  }, {
7
8
  _id: false
8
9
  })