Skip to content

Commit

Permalink
feat: isCrossSiteTrackingEnabled (#100)
Browse files Browse the repository at this point in the history
* isCrossSiteTrackingEnabled

* feat: isCrossSiteTrackingEnabled

* feat: isCrossSiteTrackingEnabled

* test: tracking test changes

Co-authored-by: Steve Mask <smask@paypal.com>
  • Loading branch information
mnicpt and Steve Mask authored May 24, 2022
1 parent ba30237 commit 2c9b08e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,7 @@ export function isApplePaySupported() : boolean {

return false;
}

export function isCrossSiteTrackingEnabled(expectedCookieKey : string) : boolean {
return document.cookie.indexOf(expectedCookieKey) !== -1;
}
23 changes: 23 additions & 0 deletions test/tests/device/isCrossSiteTrackingEnabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* @flow */

import { isCrossSiteTrackingEnabled } from '../../../src/device';

describe('isCrossSiteTrackingEnabled', () => {
it('should return false when expected cookies are present', () => {
document.cookie = 'enforce_policy=ccpa';

const bool = isCrossSiteTrackingEnabled('enforce_policy');
if (bool) {
throw new Error(`Expected false, got ${ JSON.stringify(bool) }`);
}
});

it('should return true when expected cookies are not present', () => {
document.cookie = '';

const bool = isCrossSiteTrackingEnabled('enforce_policy');
if (!bool) {
throw new Error(`Expected true, got ${ JSON.stringify(bool) }`);
}
});
});

0 comments on commit 2c9b08e

Please # to comment.