Skip to content

Commit

Permalink
Merge pull request #26587 from guardian/ds/remove-AdFreeStrictExpiryE…
Browse files Browse the repository at this point in the history
…nforcement-switch

remove ad free cookie expiry switch
  • Loading branch information
dskamiotis authored Sep 21, 2023
2 parents f702017 + cc8af65 commit 6715b86
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 47 deletions.
10 changes: 0 additions & 10 deletions common/app/conf/switches/CommercialSwitches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ trait CommercialSwitches {
exposeClientSide = true,
)

val AdFreeStrictExpiryEnforcement = Switch(
Commercial,
"ad-free-strict-expiry-enforcement",
"When ON, the ad-free cookie is valid for max. 48 hours. OFF doesn't enforce expiry check.",
owners = Seq(Owner.withGithub("JustinPinner")),
safeState = Off,
sellByDate = never,
exposeClientSide = true,
)

val ImrWorldwideSwitch = Switch(
Commercial,
"imr-worldwide",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,6 @@ const setAllFeaturesData = (opts: { isExpired: boolean }) => {
addCookie(PERSISTENCE_KEYS.ACTION_REQUIRED_FOR_COOKIE, 'test');
};

const setExpiredAdFreeData = () => {
const currentTime = new Date().getTime();
const msInOneDay = 24 * 60 * 60 * 1000;
const expiryDate = new Date(currentTime - msInOneDay * 2);
addCookie(
PERSISTENCE_KEYS.AD_FREE_USER_COOKIE,
expiryDate.getTime().toString(),
);
};

const deleteAllFeaturesData = () => {
removeCookie(PERSISTENCE_KEYS.PAYING_MEMBER_COOKIE);
removeCookie(PERSISTENCE_KEYS.RECURRING_CONTRIBUTOR_COOKIE);
Expand All @@ -108,7 +98,6 @@ const deleteAllFeaturesData = () => {
};

beforeAll(() => {
window.guardian.config.switches.adFreeStrictExpiryEnforcement = true;
window.guardian.config.page.userAttributesApiUrl = '';
});

Expand Down Expand Up @@ -170,19 +159,6 @@ describe('Refreshing the features data', () => {
await refresh();
expect(fetchJsonSpy).toHaveBeenCalledTimes(1);
});

it('Performs an update if the ad-free state is stale and strict expiry enforcement is enabled', async () => {
// This is a slightly synthetic setup - the ad-free cookie is rewritten with every
// refresh that happens as a result of expired features data, but we want to check
// that a refresh could be triggered based on ad-free state alone if the strict
// expiry enforcement switch is ON.
// Set everything except the ad-free cookie
setAllFeaturesData({ isExpired: false });
setExpiredAdFreeData();

await refresh();
expect(fetchJsonSpy).toHaveBeenCalledTimes(1);
});
});

describe('If user signed out', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const AD_FREE_USER_COOKIE = 'GU_AF1';

// TODO: isn’t this duplicated from commercial features?
// https://github.com/guardian/frontend/blob/2a222cfb77748aa1140e19adca10bfc688fe6cad/static/src/javascripts/projects/common/modules/commercial/commercial-features.ts

const forcedAdFreeMode = !!/[#&]noadsaf(&.*)?$/.exec(window.location.hash);

const getAdFreeCookie = (): string | null =>
Expand All @@ -53,14 +54,6 @@ const adFreeDataIsPresent = (): boolean => {
return !Number.isNaN(parseInt(cookieVal, 10));
};

const adFreeDataIsOld = (): boolean => {
const { switches } = window.guardian.config;
return (
Boolean(switches.adFreeStrictExpiryEnforcement) &&
cookieIsExpiredOrMissing(AD_FREE_USER_COOKIE)
);
};

const setAdFreeCookie = (daysToLive = 1): void => {
const expires = new Date();
expires.setMonth(expires.getMonth() + 6);
Expand Down Expand Up @@ -142,7 +135,6 @@ const persistResponse = (JsonResponse: UserFeaturesResponse) => {
value: JsonResponse.alertAvailableFor,
});
}

if (JsonResponse.contentAccess.digitalPack) {
setAdFreeCookie(2);
} else if (adFreeDataIsPresent() && !forcedAdFreeMode) {
Expand Down Expand Up @@ -194,9 +186,7 @@ const featuresDataIsOld = () =>
cookieIsExpiredOrMissing(USER_FEATURES_EXPIRY_COOKIE);

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

const userHasDataAfterSignout = async (): Promise<boolean> =>
!(await isUserLoggedIn()) && userHasData();
Expand Down Expand Up @@ -369,7 +359,7 @@ const fakeOneOffContributor = (): void => {
};

const isAdFreeUser = (): boolean =>
isDigitalSubscriber() || (adFreeDataIsPresent() && !adFreeDataIsOld());
isDigitalSubscriber() || adFreeDataIsPresent();

// Extend the expiry of the contributions cookie by 1 year beyond the date of the contribution
const extendContribsCookieExpiry = (): void => {
Expand Down

0 comments on commit 6715b86

Please sign in to comment.