Skip to content
Snippets Groups Projects

Resolve "use new API endpoint for publication listing"

Merged Piotr Gawron requested to merge 340-new-api-endpoint-for-publication-listing into development
25 files
+ 346
418
Compare changes
  • Side-by-side
  • Inline
Files
25
import { apiPath } from '@/redux/apiPath';
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse';
import { HttpStatusCode } from 'axios';
import { showToast } from '@/utils/showToast';
import { PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK } from '../../../../../../models/mocks/publicationsResponseMock';
import { getBasePublications } from './getBasePublications';
const mockedAxiosClient = mockNetworkResponse();
const mockedAxiosNewClient = mockNetworkNewAPIResponse();
jest.mock('./../../../../../../utils/showToast');
@@ -13,17 +13,19 @@ describe('getBasePublications - util', () => {
const length = 10;
it('should return valid data if provided', async () => {
mockedAxiosClient
mockedAxiosNewClient
.onGet(apiPath.getPublications({ params: { length } }))
.reply(HttpStatusCode.Ok, PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK);
.reply(HttpStatusCode.Ok, JSON.stringify(PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK));
const result = await getBasePublications({ length });
expect(result).toStrictEqual(PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK.data);
expect(result).toStrictEqual(
JSON.parse(JSON.stringify(PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK.content)),
);
});
it('should return empty array if data structure is invalid', async () => {
mockedAxiosClient
mockedAxiosNewClient
.onGet(apiPath.getPublications({ params: { length } }))
.reply(HttpStatusCode.Ok, { randomObject: true });
@@ -33,7 +35,7 @@ describe('getBasePublications - util', () => {
});
it('should return empty array and show toast error if http error', async () => {
mockedAxiosClient
mockedAxiosNewClient
.onGet(apiPath.getPublications({ params: { length } }))
.reply(HttpStatusCode.BadRequest);
Loading