Skip to content

Commit c175eb6

Browse files
fix(audience): convert remaining setConsent comparisons + fix mock
Convert the 3 remaining raw consent string comparisons in sdk.ts setConsent() to use the capability functions: - level === 'none' (queue stop) → !canTrack(level) - level === 'none' (cookie delete) → !canTrack(level) - level === 'anonymous' && previous === 'full' (userId clear) → canIdentify(previous) && !canIdentify(level) These were left as raw comparisons in the initial refactor because they're state transitions, but they gate the same capabilities as the query functions. If a future consent level blocks tracking (like 'none' does), these would silently diverge without this change. Also fix canTrack mock in pixel.test.ts from a bare arrow to jest.fn().mockImplementation() so it can be overridden per-test. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b2c9562 commit c175eb6

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/audience/pixel/src/pixel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jest.mock('@imtbl/audience-core', () => ({
7272
};
7373
},
7474
),
75-
canTrack: (level: string) => level !== 'none',
75+
canTrack: jest.fn().mockImplementation((level: string) => level !== 'none'),
7676
}));
7777

7878
// Mock fetch globally

packages/audience/sdk/src/sdk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ export class Audience {
362362

363363
// Web-specific cleanup before core handles queue purge/transform and server sync.
364364
// session_end is intentionally not emitted — no events should be sent after opt-out.
365-
if (level === 'none') {
365+
if (!canTrack(level)) {
366366
this.queue.stop();
367367
}
368368

@@ -371,10 +371,10 @@ export class Audience {
371371
this.consent.setLevel(level);
372372

373373
// Web-specific cleanup after core's transition.
374-
if (level === 'none') {
374+
if (!canTrack(level)) {
375375
deleteCookie(COOKIE_NAME, this.cookieDomain);
376376
deleteCookie(SESSION_COOKIE, this.cookieDomain);
377-
} else if (level === 'anonymous' && previous === 'full') {
377+
} else if (canIdentify(previous) && !canIdentify(level)) {
378378
this.userId = undefined;
379379
}
380380

0 commit comments

Comments
 (0)