From 4bf566f247b00dff7709379a9420ce36fa8b12a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alvarez?= Date: Wed, 9 Oct 2024 11:29:33 +0200 Subject: [PATCH] feat(packages/sui-pde): update pde --- .../sui-pde/src/adapters/optimizely/index.js | 4 +++ .../sui-pde/test/common/useDecisionSpec.js | 28 +++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) 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} + ) } })