Skip to content

Commit

Permalink
feat(packages/sui-pde): update pde
Browse files Browse the repository at this point in the history
  • Loading branch information
andresz1 committed Oct 9, 2024
1 parent d770f2e commit 4bf566f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/sui-pde/src/adapters/optimizely/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 23 additions & 5 deletions packages/sui-pde/test/common/useDecisionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,26 @@ describe('useDecision hook', () => {
let decide

before(() => {
decide = sinon.stub().returns({
const decision = {
variationKey: 'variation',
enabled: true,
variables: {},
ruleKey: 'rule',
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}) => (
<PdeContext.Provider value={{features: [], pde: {decide}}}>{children}</PdeContext.Provider>
<PdeContext.Provider value={{features: [], pde: {decide, addDecideListener, removeNotificationListener}}}>
{children}
</PdeContext.Provider>
)
})

Expand Down Expand Up @@ -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}) => (
<PdeContext.Provider value={{features: [], pde: {decide}}}>{children}</PdeContext.Provider>
<PdeContext.Provider value={{features: [], pde: {decide, addDecideListener, removeNotificationListener}}}>
{children}
</PdeContext.Provider>
)
})

Expand All @@ -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}) => (
<PdeContext.Provider value={{features: [], pde: {decide}}}>{children}</PdeContext.Provider>
<PdeContext.Provider value={{features: [], pde: {decide, addDecideListener, removeNotificationListener}}}>
{children}
</PdeContext.Provider>
)
}
})
Expand Down

0 comments on commit 4bf566f

Please sign in to comment.