Skip to content
Snippets Groups Projects

feat: Add publications list modal download csv (MIN-242)

Merged Adrian Orłów requested to merge MIN-242-publications-list-modal-download-csv into development
7 files
+ 355
5
Compare changes
  • Side-by-side
  • Inline
Files
7
 
import { apiPath } from '@/redux/apiPath';
 
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
 
import { HttpStatusCode } from 'axios';
 
import { PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK } from '../../../../../../models/mocks/publicationsResponseMock';
 
import { showToast } from '../../../../../../utils/showToast';
 
import { getBasePublications } from './getBasePublications';
 
 
const mockedAxiosClient = mockNetworkResponse();
 
 
jest.mock('./../../../../../../utils/showToast');
 
 
describe('getBasePublications - util', () => {
 
const length = 10;
 
 
it('should return valid data if provided', async () => {
 
mockedAxiosClient
 
.onGet(apiPath.getPublications({ params: { length } }))
 
.reply(HttpStatusCode.Ok, PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK);
 
 
const result = await getBasePublications({ length });
 
 
expect(result).toStrictEqual(PUBLICATIONS_DEFAULT_SEARCH_FIRST_10_MOCK.data);
 
});
 
 
it('should return empty array if data structure is invalid', async () => {
 
mockedAxiosClient
 
.onGet(apiPath.getPublications({ params: { length } }))
 
.reply(HttpStatusCode.Ok, { randomObject: true });
 
 
const result = await getBasePublications({ length });
 
 
expect(result).toStrictEqual([]);
 
});
 
 
it('should return empty array and show toast error if http error', async () => {
 
mockedAxiosClient
 
.onGet(apiPath.getPublications({ params: { length } }))
 
.reply(HttpStatusCode.BadRequest);
 
 
const result = await getBasePublications({ length });
 
 
expect(result).toStrictEqual([]);
 
expect(showToast).toHaveBeenCalledWith({
 
message:
 
"Problem with fetching publications: The server couldn't understand your request. Please check your input and try again.",
 
type: 'error',
 
});
 
});
 
});
Loading