Skip to content

Commit

Permalink
if disable is overridden, proxy correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Nov 17, 2023
1 parent ba4617e commit 9b6a432
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ describe(createWrapper, () => {
).toBe(false)
})

it('should be disabled if a user overrides disable with a true value, regardless of what we calculate', async () => {
it('should be disabled if if a user overrides disabled with boolean: true, and pass through a boolean', async () => {
disableSegmentMock.segmentShouldBeDisabled.mockReturnValue(false)
wrapTestAnalytics()
await analytics.load(
Expand All @@ -757,9 +757,7 @@ describe(createWrapper, () => {
)
expect(
// @ts-ignore
analyticsLoadSpy.mock.lastCall[1].disable!(
DEFAULT_LOAD_SETTINGS.cdnSettings
)
analyticsLoadSpy.mock.lastCall[1].disable
).toBe(true)
})

Expand Down Expand Up @@ -796,5 +794,23 @@ describe(createWrapper, () => {
)
).toBe(true)
})

it('should enable if user passes the wrong option to "load"', async () => {
disableSegmentMock.segmentShouldBeDisabled.mockReturnValue(false)
wrapTestAnalytics()
await analytics.load(
{
...DEFAULT_LOAD_SETTINGS,
},
// @ts-ignore
{ disable: 'foo' }
)
expect(
// @ts-ignore
analyticsLoadSpy.mock.lastCall[1].disable!(
DEFAULT_LOAD_SETTINGS.cdnSettings
)
).toBe(false)
})
})
})
19 changes: 8 additions & 11 deletions packages/consent/consent-tools/src/domain/create-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ export const createWrapper = <Analytics extends AnyAnalytics>(
updateCDNSettings,
options?.updateCDNSettings || ((id) => id)
),
disable: (cdnSettings) =>
isDisabled(cdnSettings, initialCategories, options?.disable),
disable:
options?.disable === true
? true
: (cdnSettings) =>
isDisabled(cdnSettings, initialCategories, options?.disable),
})
}
analyticsService.replaceLoadMethod(loadWithConsent)
Expand Down Expand Up @@ -187,16 +190,10 @@ const disableIntegrations = (
const isDisabled = (
cdnSettings: CDNSettings,
initialCategories: Categories,
disableOpt: InitOptions['disable'] | undefined
disable: InitOptions['disable']
): boolean => {
const shouldBeDisabled = segmentShouldBeDisabled(
initialCategories,
cdnSettings.consentSettings
)
return (
shouldBeDisabled ||
(typeof disableOpt === 'function'
? disableOpt(cdnSettings)
: disableOpt === true)
segmentShouldBeDisabled(initialCategories, cdnSettings.consentSettings) ||
(typeof disable === 'function' ? disable(cdnSettings) : disable === true)
)
}

0 comments on commit 9b6a432

Please sign in to comment.