diff --git a/pages/dashboards/[[...location]].js b/pages/dashboards/[[...location]].js index 573783f4e1..f9fa9cd0ee 100644 --- a/pages/dashboards/[[...location]].js +++ b/pages/dashboards/[[...location]].js @@ -108,7 +108,7 @@ export const getServerSideProps = async ({ params, query, req }) => { } let countryData = await getCategorisedCountries(true); - const notifications = await getPublishedNotifications({}); + const notifications = await getPublishedNotifications(); if (!type || type === 'global') { // get global data diff --git a/pages/grants-and-fellowships/[section].js b/pages/grants-and-fellowships/[section].js index 4be08a625c..1acd668243 100644 --- a/pages/grants-and-fellowships/[section].js +++ b/pages/grants-and-fellowships/[section].js @@ -28,7 +28,7 @@ export const getServerSideProps = async ({ query }) => { }; } - const notifications = await getPublishedNotifications({}); + const notifications = await getPublishedNotifications(); if (query?.section === 'projects') { const pageTexts = await getSGFPage(); diff --git a/pages/index.js b/pages/index.js index 759ce3004f..152912b3de 100644 --- a/pages/index.js +++ b/pages/index.js @@ -24,7 +24,7 @@ const HomePage = (props) => ( export const getStaticProps = async () => { const newsArticles = await getNewsArticles(); - const notifications = await getPublishedNotifications({}); + const notifications = await getPublishedNotifications(); return { props: { diff --git a/pages/map/[[...location]].js b/pages/map/[[...location]].js index 6daf9f1869..367b2590aa 100644 --- a/pages/map/[[...location]].js +++ b/pages/map/[[...location]].js @@ -32,7 +32,7 @@ const ALLOWED_TYPES = ['global', 'country', 'wdpa', 'use', 'geostore', 'aoi']; export const getServerSideProps = async ({ req, params }) => { const [type] = params?.location || []; let userToken = null; - const notifications = await getPublishedNotifications({}); + const notifications = await getPublishedNotifications(); try { userToken = parse(req.headers.cookie)['gfw-token']; diff --git a/pages/my-gfw.js b/pages/my-gfw.js index d48012ca74..3bb50a2481 100644 --- a/pages/my-gfw.js +++ b/pages/my-gfw.js @@ -17,7 +17,7 @@ const MyGfwPage = (props) => ( ); export const getStaticProps = async () => { - const notifications = await getPublishedNotifications({}); + const notifications = await getPublishedNotifications(); return { props: { diff --git a/services/__tests__/notifications.spec.js b/services/__tests__/notifications.spec.js index 6633b19485..4d4877b228 100644 --- a/services/__tests__/notifications.spec.js +++ b/services/__tests__/notifications.spec.js @@ -5,7 +5,7 @@ import { NOTIFICATIONS_RESPONSE } from '../../fixtures/notifications'; // eslint-disable-next-line no-undef jest.mock('axios'); -describe.skip('getPublishedNotifications', () => { +describe('getPublishedNotifications', () => { describe('when API call is successful', () => { it('should return a list of notifications', async () => { const response = NOTIFICATIONS_RESPONSE; @@ -34,8 +34,11 @@ describe.skip('getPublishedNotifications', () => { axios.get.mockResolvedValueOnce(response); - const result = await getPublishedNotifications({}); + const result = await getPublishedNotifications(); + expect(axios.get).toHaveBeenCalledWith( + `${process.env.NEXT_PUBLIC_WORDPRESS_URL}/wp/v2/notice?per_page=100&page=1&orderby=date&order=desc` + ); expect(result).toEqual(expectedResult); }); }); @@ -46,8 +49,11 @@ describe.skip('getPublishedNotifications', () => { axios.get.mockRejectedValueOnce(new Error(message)); - const result = await getPublishedNotifications({}); + const result = await getPublishedNotifications(); + expect(axios.get).toHaveBeenCalledWith( + `${process.env.NEXT_PUBLIC_WORDPRESS_URL}/wp/v2/notice?per_page=100&page=1&orderby=date&order=desc` + ); expect(result).toBe(null); }); }); diff --git a/services/notifications.js b/services/notifications.js index 2e15c86488..e5c74da356 100644 --- a/services/notifications.js +++ b/services/notifications.js @@ -1,4 +1,3 @@ -import apiFetch from '@wordpress/api-fetch'; import axios from 'axios'; const mapResponseToNotification = ({ @@ -20,28 +19,11 @@ const mapResponseToNotification = ({ }; }; -apiFetch.setFetchHandler(async (options) => { - const headers = { 'Content-Type': 'application/json' }; - const { url, path, data, method, params } = options; - - return axios({ - headers, - url: url || path, - method, - data, - params, - }); -}); - -export const getPublishedNotifications = async ({ cancelToken }) => { +export const getPublishedNotifications = async () => { try { - const notificationsData = await apiFetch({ - url: `${process.env.NEXT_PUBLIC_WORDPRESS_URL}/wp/v2/notice?per_page=100&page=1&orderby=date&order=desc`, - params: { - _embed: true, - }, - cancelToken, - }); + const notificationsData = await axios.get( + `${process.env.NEXT_PUBLIC_WORDPRESS_URL}/wp/v2/notice?per_page=100&page=1&orderby=date&order=desc` + ); return notificationsData?.data.map((item) => mapResponseToNotification(item)