Skip to content

Commit

Permalink
Merge branch 'master' into UIPFIMP-66
Browse files Browse the repository at this point in the history
  • Loading branch information
mariia-aloshyna authored Jan 15, 2024
2 parents 7c5a1e8 + e511b25 commit 683f83c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## **7.1.0** (in progress)

### Features added:

* Jest/RTL: Increase test coverage for FindImportProfile component (UIPFIMP-65)
* Jest/RTL: Cover utils with unit tests (UIPFIMP-64)
* Jest/RTL: Increase test coverage for AbstractContainer component (UIPFIMP-66)

## [7.0.0](https://github.com/folio-org/ui-plugin-find-import-profile/tree/v7.0.0) (2023-10-13)
Expand Down
66 changes: 66 additions & 0 deletions src/FindImportProfile/utils/fetchAssociations.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import '../../../test/jest/__mock__';

import { fetchAssociations } from './fetchAssociations';

global.fetch = jest.fn();

const mockData = { name: 'test name' };
const profileId = 'testProfileId';
const okapi = {
url: 'https://test.com',
tenant: 'tenant',
token: 'token',
};
const path = `${okapi.url}/data-import-profiles/profileAssociations/${profileId}`;

describe('fetchAssociations function', () => {
beforeEach(() => {
global.fetch.mockClear();
});

describe('when masterType is equal to parentType', () => {
it('should fetch details for the entity', async () => {
global.fetch.mockResolvedValueOnce({
ok: true,
status: 200,
json: async () => mockData,
});

const expectedUrl = `${path}/masters?detailType=JOB_PROFILE`;
const data = await fetchAssociations(okapi, profileId, 'ACTION_PROFILE', 'ACTION_PROFILE', 'jobProfiles');

expect(global.fetch.mock.calls[0][0]).toBe(expectedUrl);
expect(data).toEqual(mockData);
});
});

describe('when masterType is not equal to parentType', () => {
it('should fetch details for the master type', async () => {
global.fetch.mockResolvedValueOnce({
ok: true,
status: 200,
json: async () => mockData,
});

const expectedUrl = `${path}/details?masterType=ACTION_PROFILE`;
const data = await fetchAssociations(okapi, profileId, 'JOB_PROFILE', 'ACTION_PROFILE', 'actionProfiles');

expect(global.fetch.mock.calls[0][0]).toBe(expectedUrl);
expect(data).toEqual(mockData);
});
});

describe('when there is no data', () => {
it('should return an empty object', async () => {
global.fetch.mockResolvedValueOnce({
ok: false,
status: 400,
json: async () => null,
});

const data = await fetchAssociations(okapi, profileId, 'test', 'test', 'jobProfiles');

expect(data).toEqual({});
});
});
});

0 comments on commit 683f83c

Please sign in to comment.