Skip to content

Commit

Permalink
Merge pull request #128 from Financial-Times/CPREL-844
Browse files Browse the repository at this point in the history
CPREL-844: Bump privacy and ads dependencies
  • Loading branch information
philsegal authored Oct 30, 2023
2 parents 65abd7a + b57e209 commit 0dc13b4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 36 deletions.
17 changes: 11 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"npm": "7.x || 8.x || 9.x"
},
"dependencies": {
"@financial-times/ads-personalised-consent": "^5.2.3",
"@financial-times/ads-personalised-consent": "^5.2.8",
"@financial-times/o-grid": "^5.0.0",
"@financial-times/o-tracking": "^4.5.0",
"@financial-times/o-viewport": "^4.0.0",
"@financial-times/privacy-us-privacy": "1.0.0",
"@financial-times/privacy-us-privacy": "^2.1.0",
"ready-state": "^2.0.5",
"web-vitals": "^3.4.0"
},
Expand Down
14 changes: 7 additions & 7 deletions src/client/__test__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const appContext = {
describe('src/index', () => {
beforeAll(() => {
getConsentData.mockResolvedValue({});
window.console.warn = jest.fn()
})
window.console.warn = jest.fn();
});

afterEach(() => {
jest.clearAllMocks();
// Clean global instance left on the window after each init() call
delete window.oTracking
delete window.oTracking;
});

describe('.init()', () => {
Expand All @@ -55,17 +55,17 @@ describe('src/index', () => {
expect(window.oTracking).toBe(oTrackingInstance);
});

it("warns the user in case an instance of o-tracking is already attached to the window without overriding the value", () => {
window.oTracking = "initialValue";
it('warns the user in case an instance of o-tracking is already attached to the window without overriding the value', () => {
window.oTracking = 'initialValue';
const ourInstance = init({ appContext });
expect(window.console.warn).toHaveBeenCalledWith(
"An oTracking instance already exists on window, skipping",
'An oTracking instance already exists on window, skipping',
{
currentInstance: 'initialValue',
ourInstance,
}
);
expect(window.oTracking).toBe("initialValue");
expect(window.oTracking).toBe('initialValue');
});

it('configures o-tracking with context data', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function init ({ appContext, extraContext, pageViewContext }) {
})
.catch((err) => {
// eslint-disable-next-line no-console
console.warn("Could not get consent data", err);
console.warn('Could not get consent data', err);
oTracking.page(pageViewEventParams);
});
}
Expand All @@ -55,7 +55,7 @@ export function init ({ appContext, extraContext, pageViewContext }) {

if (window.oTracking) {
// eslint-disable-next-line no-console
console.warn("An oTracking instance already exists on window, skipping", { currentInstance: window.oTracking, ourInstance: oTracking });
console.warn('An oTracking instance already exists on window, skipping', { currentInstance: window.oTracking, ourInstance: oTracking });
} else {
window.oTracking = oTracking;
}
Expand Down
32 changes: 16 additions & 16 deletions src/client/utils/__test__/getConsentData.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
jest.mock("@financial-times/privacy-us-privacy", () => ({
jest.mock('@financial-times/privacy-us-privacy', () => ({
getUsPrivacyForTracking: jest.fn(),
}));

jest.mock("@financial-times/ads-personalised-consent", () => ({
jest.mock('@financial-times/ads-personalised-consent', () => ({
getPersonalisedConsent: jest.fn(),
}));

import { getUsPrivacyForTracking } from "@financial-times/privacy-us-privacy";
import { getPersonalisedConsent } from "@financial-times/ads-personalised-consent";
import { getUsPrivacyForTracking } from '@financial-times/privacy-us-privacy';
import { getPersonalisedConsent } from '@financial-times/ads-personalised-consent';

import getConsentData from "../getConsentData";
import getConsentData from '../getConsentData';

describe("getConsentData", () => {
describe('getConsentData', () => {

beforeEach(() => {
getPersonalisedConsent.mockResolvedValue({
Expand All @@ -20,34 +20,34 @@ describe("getConsentData", () => {
consent2: false,
}),
});
getUsPrivacyForTracking.mockReturnValue("usprivacy");
})
getUsPrivacyForTracking.mockReturnValue('usprivacy');
});
afterEach(() => {
jest.clearAllMocks();
});


it("returns the consent data and awaits for getPersonalisedConsent.isAllowed()", async () => {
it('returns the consent data and awaits for getPersonalisedConsent.isAllowed()', async () => {
const consentData = await getConsentData();

expect(consentData).toEqual({
consent1: true,
consent2: false,
usprivacy: "usprivacy",
usprivacy: 'usprivacy',
});
});

it("Errors if getPersonalisedConsent.isAllowed() rejects", async () => {
getPersonalisedConsent.mockRejectedValue(new Error("no consent"));
it('Errors if getPersonalisedConsent.isAllowed() rejects', async () => {
getPersonalisedConsent.mockRejectedValue(new Error('no consent'));

await expect(getConsentData()).rejects.toThrow("no consent");
await expect(getConsentData()).rejects.toThrow('no consent');
});

it("Errors if getUsPrivacyForTracking rejects", async () => {
it('Errors if getUsPrivacyForTracking rejects', async () => {
getUsPrivacyForTracking.mockImplementation(() => {
throw new Error("us privacy error");
throw new Error('us privacy error');
});

await expect(getConsentData()).rejects.toThrow("us privacy error");
await expect(getConsentData()).rejects.toThrow('us privacy error');
});
});
6 changes: 3 additions & 3 deletions src/client/utils/getConsentData.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getUsPrivacyForTracking } from "@financial-times/privacy-us-privacy";
import { getPersonalisedConsent } from "@financial-times/ads-personalised-consent";
import { getUsPrivacyForTracking } from '@financial-times/privacy-us-privacy';
import { getPersonalisedConsent } from '@financial-times/ads-personalised-consent';

export default async function getConsentData() {
export default async function getConsentData () {
const consentValues = (await getPersonalisedConsent()).isAllowed();
const usprivacy = getUsPrivacyForTracking();
return {
Expand Down

0 comments on commit 0dc13b4

Please sign in to comment.