Skip to content

Commit

Permalink
Merge pull request #13081 from guardian/remove-digisub-cookie
Browse files Browse the repository at this point in the history
Remove digital subscription cookie
  • Loading branch information
rupertbates authored Jan 6, 2025
2 parents f63c72c + 9c88878 commit 56c4c2d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 67 deletions.
53 changes: 1 addition & 52 deletions dotcom-rendering/src/client/userFeatures/user-features.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getAuthStatus as getAuthStatus_,
isUserLoggedInOktaRefactor as isUserLoggedInOktaRefactor_,
} from '../../lib/identity';
import { isDigitalSubscriber, refresh } from './user-features';
import { refresh } from './user-features';
import { fetchJson } from './user-features-lib';

jest.mock('./user-features-lib', () => {
Expand Down Expand Up @@ -37,7 +37,6 @@ const PERSISTENCE_KEYS = {
USER_FEATURES_EXPIRY_COOKIE: 'gu_user_features_expiry',
AD_FREE_USER_COOKIE: 'GU_AF1',
ACTION_REQUIRED_FOR_COOKIE: 'gu_action_required_for',
DIGITAL_SUBSCRIBER_COOKIE: 'gu_digital_subscriber',
SUPPORT_ONE_OFF_CONTRIBUTION_COOKIE: 'gu.contributions.contrib-timestamp',
HIDE_SUPPORT_MESSAGING_COOKIE: 'gu_hide_support_messaging',
};
Expand All @@ -51,10 +50,6 @@ const setAllFeaturesData = (opts: { isExpired: boolean }) => {
const adFreeExpiryDate = opts.isExpired
? new Date(currentTime - msInOneDay * 2)
: new Date(currentTime + msInOneDay * 2);
setCookie({
name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE,
value: 'true',
});
setCookie({
name: PERSISTENCE_KEYS.HIDE_SUPPORT_MESSAGING_COOKIE,
value: 'true',
Expand All @@ -74,7 +69,6 @@ const setAllFeaturesData = (opts: { isExpired: boolean }) => {
};

const deleteAllFeaturesData = () => {
removeCookie({ name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE });
removeCookie({ name: PERSISTENCE_KEYS.USER_FEATURES_EXPIRY_COOKIE });
removeCookie({ name: PERSISTENCE_KEYS.AD_FREE_USER_COOKIE });
removeCookie({ name: PERSISTENCE_KEYS.ACTION_REQUIRED_FOR_COOKIE });
Expand Down Expand Up @@ -147,9 +141,6 @@ describe('If user signed out', () => {
expect(
getCookie({ name: PERSISTENCE_KEYS.AD_FREE_USER_COOKIE }),
).toBeNull();
expect(
getCookie({ name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE }),
).toBeNull();
expect(
getCookie({
name: PERSISTENCE_KEYS.USER_FEATURES_EXPIRY_COOKIE,
Expand All @@ -158,42 +149,6 @@ describe('If user signed out', () => {
});
});

describe('The isDigitalSubscriber getter', () => {
it('Is false when the user is logged out', () => {
jest.resetAllMocks();
isUserLoggedInOktaRefactor.mockResolvedValue(false);
expect(isDigitalSubscriber()).toBe(false);
});

describe('When the user is logged in', () => {
beforeEach(() => {
jest.resetAllMocks();
isUserLoggedInOktaRefactor.mockResolvedValue(true);
});

it('Is true when the user has a `true` digital subscriber cookie', () => {
setCookie({
name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE,
value: 'true',
});
expect(isDigitalSubscriber()).toBe(true);
});

it('Is false when the user has a `false` digital subscriber cookie', () => {
setCookie({
name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE,
value: 'false',
});
expect(isDigitalSubscriber()).toBe(false);
});

it('Is false when the user has no digital subscriber cookie', () => {
removeCookie({ name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE });
expect(isDigitalSubscriber()).toBe(false);
});
});
});

describe('Storing new feature data', () => {
beforeEach(() => {
const mockResponse = {
Expand Down Expand Up @@ -231,9 +186,6 @@ describe('Storing new feature data', () => {
}),
);
return refresh().then(() => {
expect(
getCookie({ name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE }),
).toBe('false');
expect(
getCookie({ name: PERSISTENCE_KEYS.AD_FREE_USER_COOKIE }),
).toBeNull();
Expand All @@ -253,9 +205,6 @@ describe('Storing new feature data', () => {
}),
);
return refresh().then(() => {
expect(
getCookie({ name: PERSISTENCE_KEYS.DIGITAL_SUBSCRIBER_COOKIE }),
).toBe('true');
expect(
getCookie({ name: PERSISTENCE_KEYS.AD_FREE_USER_COOKIE }),
).toBeTruthy();
Expand Down
17 changes: 2 additions & 15 deletions dotcom-rendering/src/client/userFeatures/user-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import type { UserFeaturesResponse } from './user-features-lib';

const USER_FEATURES_EXPIRY_COOKIE = 'gu_user_features_expiry';
const ACTION_REQUIRED_FOR_COOKIE = 'gu_action_required_for';
const DIGITAL_SUBSCRIBER_COOKIE = 'gu_digital_subscriber';
const HIDE_SUPPORT_MESSAGING_COOKIE = 'gu_hide_support_messaging';
const AD_FREE_USER_COOKIE = 'GU_AF1';

Expand All @@ -39,7 +38,6 @@ const userHasData = () => {
getAdFreeCookie() ??
getCookie({ name: ACTION_REQUIRED_FOR_COOKIE }) ??
getCookie({ name: USER_FEATURES_EXPIRY_COOKIE }) ??
getCookie({ name: DIGITAL_SUBSCRIBER_COOKIE }) ??
getCookie({ name: HIDE_SUPPORT_MESSAGING_COOKIE });
return !!cookie;
};
Expand All @@ -62,10 +60,6 @@ const persistResponse = (JsonResponse: UserFeaturesResponse) => {
name: USER_FEATURES_EXPIRY_COOKIE,
value: timeInDaysFromNow(1),
});
setCookie({
name: DIGITAL_SUBSCRIBER_COOKIE,
value: String(JsonResponse.contentAccess.digitalPack),
});
setCookie({
name: HIDE_SUPPORT_MESSAGING_COOKIE,
value: String(!JsonResponse.showSupportMessaging),
Expand All @@ -90,7 +84,6 @@ const deleteOldData = (): void => {
removeCookie({ name: AD_FREE_USER_COOKIE });
removeCookie({ name: USER_FEATURES_EXPIRY_COOKIE });
removeCookie({ name: ACTION_REQUIRED_FOR_COOKIE });
removeCookie({ name: DIGITAL_SUBSCRIBER_COOKIE });
removeCookie({ name: HIDE_SUPPORT_MESSAGING_COOKIE });
};

Expand Down Expand Up @@ -130,22 +123,16 @@ const requestNewData = () => {
const featuresDataIsOld = () =>
cookieIsExpiredOrMissing(USER_FEATURES_EXPIRY_COOKIE);

const isDigitalSubscriber = (): boolean =>
getCookie({ name: DIGITAL_SUBSCRIBER_COOKIE }) === 'true';

const userNeedsNewFeatureData = (): boolean =>
featuresDataIsOld() || (isDigitalSubscriber() && !adFreeDataIsPresent());

const userHasDataAfterSignout = async (): Promise<boolean> =>
!(await isUserLoggedInOktaRefactor()) && userHasData();

const refresh = async (): Promise<void> => {
if ((await isUserLoggedInOktaRefactor()) && userNeedsNewFeatureData()) {
if ((await isUserLoggedInOktaRefactor()) && featuresDataIsOld()) {
return requestNewData();
} else if ((await userHasDataAfterSignout()) && !forcedAdFreeMode) {
deleteOldData();
}
return Promise.resolve();
};

export { refresh, isDigitalSubscriber };
export { refresh };

0 comments on commit 56c4c2d

Please sign in to comment.