Skip to content

Commit

Permalink
chore: Temporary remove Australia edition (#2363)
Browse files Browse the repository at this point in the history
* chore: Temporary remove Aus edition

* chore: Fix the build
  • Loading branch information
jimhunty authored Jan 17, 2024
1 parent fd66b84 commit 0232639
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 182 deletions.
14 changes: 0 additions & 14 deletions projects/Apps/common/src/editions-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,4 @@ morning by 6am (GMT)`,
notificationUTCOffset: 3,
locale: 'en_GB',
},
{
title: 'Australia Weekend',
subTitle: `Published from Sydney every
Saturday by 6 am (AEST)`,
edition: editions.ausWeekly,
header: {
title: 'Australia',
subTitle: 'Weekend',
},
editionType: 'Regional',
topic: 'au',
notificationUTCOffset: -5,
locale: 'en_AU',
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,6 @@ morning by 6am (GMT)",
"title": "UK Daily",
"topic": "uk",
},
{
"edition": "australian-edition",
"editionType": "Regional",
"header": {
"subTitle": "Weekend",
"title": "Australia",
},
"locale": "en_AU",
"notificationUTCOffset": -5,
"subTitle": "Published from Sydney every
Saturday by 6 am (AEST)",
"title": "Australia Weekend",
"topic": "au",
},
{
"buttonImageUri": "https://media.guim.co.uk/49cebb0db4a3e4d26d7d190da7be4a2e9bd7534f/0_0_103_158/103.png",
"buttonStyle": {
Expand Down Expand Up @@ -195,20 +181,6 @@ Monthly",
}
/>
</View>
<View
onFocusCapture={[Function]}
onLayout={[Function]}
style={null}
>
EditionButton
<View
style={
{
"height": 10,
}
}
/>
</View>
<View
onFocusCapture={[Function]}
onLayout={[Function]}
Expand Down Expand Up @@ -239,20 +211,6 @@ morning by 6am (GMT)",
"title": "UK Daily",
"topic": "uk",
},
{
"edition": "australian-edition",
"editionType": "Regional",
"header": {
"subTitle": "Weekend",
"title": "Australia",
},
"locale": "en_AU",
"notificationUTCOffset": -5,
"subTitle": "Published from Sydney every
Saturday by 6 am (AEST)",
"title": "Australia Weekend",
"topic": "au",
},
]
}
getItem={[Function]}
Expand All @@ -279,20 +237,6 @@ Saturday by 6 am (AEST)",
viewabilityConfigCallbackPairs={[]}
>
<View>
<View
onFocusCapture={[Function]}
onLayout={[Function]}
style={null}
>
EditionButton
<View
style={
{
"height": 10,
}
}
/>
</View>
<View
onFocusCapture={[Function]}
onLayout={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
editionsListCache,
selectedEditionCache,
} from 'src/helpers/storage';
import { defaultRegionalEditions } from '../../../../Apps/common/src/editions-defaults';
import { BASE_EDITION, defaultEditionDecider } from '../use-edition-provider';
import { DownloadBlockedStatus } from '../use-net-info-provider';

Expand All @@ -25,16 +24,10 @@ describe('useEditions', () => {
it('should set the BASE EDITION if locale is not in the list', async () => {
const defaultLocalState = jest.fn();
const selectedLocalState = jest.fn();
const editionsList = {
regionalEditions: defaultRegionalEditions,
specialEditions: [],
trainingEditions: [],
};

await defaultEditionDecider(
defaultLocalState,
selectedLocalState,
editionsList,
DownloadBlockedStatus.NotBlocked,
() => {},
);
Expand Down
69 changes: 2 additions & 67 deletions projects/Mallard/src/hooks/__tests__/use-edition-provider.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import { defaultRegionalEditions } from '../../../../Apps/common/src/editions-de
import {
BASE_EDITION,
DEFAULT_EDITIONS_LIST,
defaultEditionDecider,
fetchEditions,
getDefaultEdition,
getEditions,
getSelectedEditionSlug,
removeExpiredSpecialEditions,
} from '../use-edition-provider';
import { DownloadBlockedStatus } from '../use-net-info-provider';

const IS_CONNECTED = true;

Expand Down Expand Up @@ -137,12 +135,6 @@ describe('useEditions', () => {
const editionSlug = await getSelectedEditionSlug();
expect(editionSlug).toEqual(BASE_EDITION.edition);
});
it('should return "australian-edition" slug when the AU edition is set', async () => {
await selectedEditionCache.set(defaultRegionalEditions[1]);
await editionsListCache.set(DEFAULT_EDITIONS_LIST);
const editionSlug = await getSelectedEditionSlug();
expect(editionSlug).toEqual('australian-edition');
});
});

describe('fetchEditions', () => {
Expand Down Expand Up @@ -219,72 +211,15 @@ describe('useEditions', () => {
});
});

describe('defaultEditionDecider', () => {
beforeEach(async () => {
await defaultEditionCache.reset();
await selectedEditionCache.reset();
});
it('should set default and selected edition local state as well as selected storage if found in default storage', async () => {
const defaultLocalState = jest.fn();
const selectedLocalState = jest.fn();
defaultEditionCache.set(defaultRegionalEditions[1]);

await defaultEditionDecider(
defaultLocalState,
selectedLocalState,
DEFAULT_EDITIONS_LIST,
DownloadBlockedStatus.NotBlocked,
() => {},
);
expect(defaultLocalState).toBeCalledTimes(1);
expect(defaultLocalState).toBeCalledWith(
defaultRegionalEditions[1],
);
expect(selectedLocalState).toBeCalledTimes(1);
expect(selectedLocalState).toBeCalledWith(
defaultRegionalEditions[1],
);
const selectedEdition = await selectedEditionCache.get();
expect(selectedEdition).toEqual(defaultRegionalEditions[1]);
const defaultEdition = await defaultEditionCache.get();
expect(defaultEdition).toEqual(defaultRegionalEditions[1]);
});
it('should set a default based on locale if the feature flag is on and nothing in the default edition cache', async () => {
// defaultRegionalEditions[1] = AU and locale mock = AU
const defaultLocalState = jest.fn();
const selectedLocalState = jest.fn();

await defaultEditionDecider(
defaultLocalState,
selectedLocalState,
DEFAULT_EDITIONS_LIST,
DownloadBlockedStatus.NotBlocked,
() => {},
);
expect(defaultLocalState).toBeCalledTimes(1);
expect(defaultLocalState).toBeCalledWith(
defaultRegionalEditions[1],
);
expect(selectedLocalState).toBeCalledTimes(1);
expect(selectedLocalState).toBeCalledWith(
defaultRegionalEditions[1],
);
const selectedEdition = await selectedEditionCache.get();
expect(selectedEdition).toEqual(defaultRegionalEditions[1]);
const defaultEdition = await defaultEditionCache.get();
expect(defaultEdition).toEqual(defaultRegionalEditions[1]);
});
});

describe('getDefaultEdition', () => {
beforeEach(async () => {
await defaultEditionCache.reset();
});
it('should return the default edition from storage if its there', async () => {
await defaultEditionCache.set(defaultRegionalEditions[1]);
await defaultEditionCache.set(defaultRegionalEditions[0]);

const defaultEdition = await getDefaultEdition();
expect(defaultEdition).toEqual(defaultRegionalEditions[1]);
expect(defaultEdition).toEqual(defaultRegionalEditions[0]);
});
it('should return null if default edition is not in storage', async () => {
const defaultEdition = await getDefaultEdition();
Expand Down
75 changes: 37 additions & 38 deletions projects/Mallard/src/hooks/use-edition-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import type { Dispatch } from 'react';
import React, { createContext, useContext, useEffect, useState } from 'react';
import type {
EditionsList,
Locale,
RegionalEdition,
SpecialEdition,
SpecialEditionHeaderStyles,
} from 'src/common';
import { locale } from 'src/helpers/locale';
import {
defaultSettings,
editionsEndpoint,
Expand Down Expand Up @@ -60,17 +58,6 @@ export const DEFAULT_EDITIONS_LIST = {

export const BASE_EDITION = defaultRegionalEditions[0];

const localeToEdition = (
locale: Locale,
editionsList: EditionsList,
): RegionalEdition => {
return (
editionsList.regionalEditions.find(
(edition) => edition.locale === locale,
) ?? BASE_EDITION
);
};

const defaultState: EditionState = {
editionsList: DEFAULT_EDITIONS_LIST,
selectedEdition: BASE_EDITION, // the current chosen edition
Expand Down Expand Up @@ -208,7 +195,6 @@ const setEdition = async (
export const defaultEditionDecider = async (
setDefaultEdition: Dispatch<RegionalEdition>,
setSelectedEdition: Dispatch<RegionalEdition | SpecialEdition>,
editionsList: EditionsList,
downloadBlocked: NetInfoState['downloadBlocked'],
setIsWeatherShown: IsWeatherShown['setIsWeatherShown'],
): Promise<void> => {
Expand All @@ -225,30 +211,36 @@ export const defaultEditionDecider = async (
await selectedEditionCache.set(defaultEdition);
pushNotificationRegistration(downloadBlocked);
} else {
// Get the correct edition for the device locale
const autoDetectedEdition = localeToEdition(locale, editionsList);

if (autoDetectedEdition) {
await setEdition(
autoDetectedEdition,
setDefaultEdition,
setSelectedEdition,
downloadBlocked,
setIsWeatherShown,
);
} else {
// auto detected edition was not possible, set default edition
await setEdition(
BASE_EDITION,
setDefaultEdition,
setSelectedEdition,
downloadBlocked,
setIsWeatherShown,
);
}
// otherwise, set default edition
await setEdition(
BASE_EDITION,
setDefaultEdition,
setSelectedEdition,
downloadBlocked,
setIsWeatherShown,
);
}
};

/**
* This filter is a temporary solution to hide the Australian edition from the list
* Currentnly, the editions list is populated by the /editions endpoint, which in turn
* is populated by an S3 bucket. To remove the Australian edition, it should be removed from
* thge S3 bucket.
*/

const temporaryFilterEditionsList = (
editionsList: EditionsList,
): EditionsList => {
const filteredRegionalEditions = editionsList.regionalEditions.filter(
(e) => e.edition !== 'australian-edition',
);
return {
...editionsList,
regionalEditions: filteredRegionalEditions,
};
};

export const EditionProvider = ({
children,
}: {
Expand Down Expand Up @@ -282,7 +274,6 @@ export const EditionProvider = ({
defaultEditionDecider(
setDefaultEdition,
setSelectedEdition,
editionsList,
downloadBlocked,
setIsWeatherShown,
);
Expand All @@ -306,7 +297,9 @@ export const EditionProvider = ({
getEditions(isConnected, fullUrl)
.then((ed) => {
if (ed) {
setEditionsList(ed);
const removeAus =
temporaryFilterEditionsList(editionsList);
setEditionsList(removeAus);
}
})
.finally(() => setIsLoading(false));
Expand Down Expand Up @@ -336,7 +329,13 @@ export const EditionProvider = ({
setIsLoading(true);
const fullUrl = editionsEndpoint(apiUrl);
getEditions(isConnected, fullUrl)
.then((ed) => ed && setEditionsList(ed))
.then((ed) => {
if (ed) {
const removeAus =
temporaryFilterEditionsList(editionsList);
setEditionsList(removeAus);
}
})
.finally(() => setIsLoading(false));
}
}, [isConnected, isActive]);
Expand Down

0 comments on commit 0232639

Please sign in to comment.