diff --git a/common/app/conf/switches/CommercialSwitches.scala b/common/app/conf/switches/CommercialSwitches.scala index 484d3e82c302..f1047d1ad559 100644 --- a/common/app/conf/switches/CommercialSwitches.scala +++ b/common/app/conf/switches/CommercialSwitches.scala @@ -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", diff --git a/static/src/javascripts/projects/common/modules/commercial/user-features.spec.ts b/static/src/javascripts/projects/common/modules/commercial/user-features.spec.ts index 705721e40850..33c1282fc81c 100644 --- a/static/src/javascripts/projects/common/modules/commercial/user-features.spec.ts +++ b/static/src/javascripts/projects/common/modules/commercial/user-features.spec.ts @@ -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); @@ -108,7 +98,6 @@ const deleteAllFeaturesData = () => { }; beforeAll(() => { - window.guardian.config.switches.adFreeStrictExpiryEnforcement = true; window.guardian.config.page.userAttributesApiUrl = ''; }); @@ -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', () => { diff --git a/static/src/javascripts/projects/common/modules/commercial/user-features.ts b/static/src/javascripts/projects/common/modules/commercial/user-features.ts index 49e0b18cc567..b1b5f29d6e6a 100644 --- a/static/src/javascripts/projects/common/modules/commercial/user-features.ts +++ b/static/src/javascripts/projects/common/modules/commercial/user-features.ts @@ -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 => @@ -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); @@ -142,7 +135,6 @@ const persistResponse = (JsonResponse: UserFeaturesResponse) => { value: JsonResponse.alertAvailableFor, }); } - if (JsonResponse.contentAccess.digitalPack) { setAdFreeCookie(2); } else if (adFreeDataIsPresent() && !forcedAdFreeMode) { @@ -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 => !(await isUserLoggedIn()) && userHasData(); @@ -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 => {