Skip to content

Commit

Permalink
fix: adding api testing, removing unused apis (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiram15 authored Jan 19, 2023
1 parent ae56a33 commit a3461de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '@testing-library/jest-dom/extend-expect';
import userEvent from '@testing-library/user-event';
import DownloadCsvButton from './DownloadCsvButton';
import { renderWithRouter } from '../../../tests/testUtils';
import EnterpriseCatalogApiService from '../../../../data/services/EnterpriseCatalogAPIService';

// file-saver mocks
jest.mock('file-saver', () => ({ saveAs: jest.fn() }));
Expand All @@ -13,6 +14,11 @@ global.Blob = function (content, options) {
return { content, options };
};

const mockCatalogApiService = jest.spyOn(
EnterpriseCatalogApiService,
'generateCsvDownloadLink',
);

const facets = {
skill_names: ['Research'],
partners_names: ['Australian National University'],
Expand Down Expand Up @@ -42,6 +48,7 @@ describe('Download button', () => {
const input = screen.getByText('Download results');
userEvent.click(input);
});
expect(mockCatalogApiService).toBeCalledWith(facets, 'foo');
});
test('download button url encodes queries', async () => {
process.env.CATALOG_SERVICE_BASE_URL = 'foobar.com';
Expand Down
15 changes: 0 additions & 15 deletions src/data/services/EnterpriseCatalogAPIService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ class EnterpriseCatalogApiService {

static apiClient = getHttpClient;

static fetchIndexedContentMetadata(options, query) {
const facetQuery = query ? `&query=${query}` : '';
const enterpriseListUrl = `${
EnterpriseCatalogApiService.enterpriseCatalogServiceApiUrl
}/catalog_csv_data/?${qs.stringify(options)}${facetQuery}`;
return EnterpriseCatalogApiService.apiClient().get(enterpriseListUrl);
}

static generateCsvDownloadLink(options, query) {
const facetQuery = query ? `&query=${encodeURIComponent(query)}` : '';
const enterpriseListUrl = `${
Expand All @@ -23,13 +15,6 @@ class EnterpriseCatalogApiService {
return enterpriseListUrl;
}

static fetchContentMetadataWithFacets(facets, query) {
return this.fetchIndexedContentMetadata(facets, query).then((response) => {
const { data } = response;
return data;
});
}

static fetchDefaultCoursesInCatalog(options) {
const enterpriseListUrl = `${
EnterpriseCatalogApiService.enterpriseCatalogServiceApiUrl
Expand Down
16 changes: 7 additions & 9 deletions src/data/services/EnterpriseCatalogAPIService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@ const mockApiClient = {
};
getHttpClient.mockReturnValue(mockApiClient);

const mockDefaultCourses = jest.spyOn(
EnterpriseCatalogApiService,
'fetchDefaultCoursesInCatalog',
);

describe('fetchDefaultCoursesInCatalogWithFacets', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('requests the catalog API', () => {
it('requests the catalog API with fetchDefaultCoursesInCatalog', () => {
const facets = { content_type: 'course' };
EnterpriseCatalogApiService.fetchDefaultCoursesInCatalogWithFacets(facets);
expect(mockDefaultCourses).toBeCalledWith(facets);
// An issue with process.env is making it impossible to assert the value the method is called with
// So for now simply assert the method's been called
expect(mockApiClient.get).toBeCalled();
});
});
describe('fetchContentMetadataWithFacets', () => {
it('requests the catalog API', () => {
const facets = { content_type: 'course' };
const query = 'foobar';
EnterpriseCatalogApiService.fetchContentMetadataWithFacets(facets, query);
expect(mockApiClient.get).toBeCalled();
});
});

0 comments on commit a3461de

Please sign in to comment.