diff --git a/packages/sui-pde/src/adapters/optimizely/index.js b/packages/sui-pde/src/adapters/optimizely/index.js
index f5a5d9e34..3bee49244 100644
--- a/packages/sui-pde/src/adapters/optimizely/index.js
+++ b/packages/sui-pde/src/adapters/optimizely/index.js
@@ -126,6 +126,10 @@ export default class OptimizelyAdapter {
* @returns {object} decision
*/
decide({name, attributes}) {
+ if (!this._hasUserConsents) {
+ return {enabled: false, flagKey: name}
+ }
+
const user = this._optimizely.createUserContext(this._userId, {
...this._applicationAttributes,
...attributes
diff --git a/packages/sui-pde/test/common/useDecisionSpec.js b/packages/sui-pde/test/common/useDecisionSpec.js
index 7ab093891..a01aea215 100644
--- a/packages/sui-pde/test/common/useDecisionSpec.js
+++ b/packages/sui-pde/test/common/useDecisionSpec.js
@@ -30,7 +30,7 @@ describe('useDecision hook', () => {
let decide
before(() => {
- decide = sinon.stub().returns({
+ const decision = {
variationKey: 'variation',
enabled: true,
variables: {},
@@ -38,10 +38,18 @@ describe('useDecision hook', () => {
flagKey: 'flag',
userContext: {},
reasons: []
- })
+ }
+ decide = sinon.stub().returns(decision)
+
+ const addDecideListener = ({onDecide}) =>
+ onDecide({type: 'flag', decisionInfo: {...decision, decisionEventDispatched: true}})
+ const removeNotificationListener = sinon.stub()
+
// eslint-disable-next-line react/prop-types
wrapper = ({children}) => (
- {children}
+
+ {children}
+
)
})
@@ -226,9 +234,14 @@ describe('useDecision hook', () => {
let wrapper
beforeEach(() => {
decide = sinon.stub().throws(new Error('fake activation error'))
+ const addDecideListener = sinon.stub()
+ const removeNotificationListener = sinon.stub()
+
// eslint-disable-next-line react/prop-types
wrapper = ({children}) => (
- {children}
+
+ {children}
+
)
})
@@ -248,10 +261,15 @@ describe('useDecision hook', () => {
track: sinon.spy()
}
+ const addDecideListener = sinon.stub()
+ const removeNotificationListener = sinon.stub()
+
stubFactory = decide => {
// eslint-disable-next-line react/prop-types
wrapper = ({children}) => (
- {children}
+
+ {children}
+
)
}
})