Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Nov 7, 2024
1 parent 1e2a190 commit 8e3ce48
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions lib/utils/api/api.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import {
LIMIT_PARAMETER,
SEARCH_PARAMETER,
} from '../../AcqList/constants';
import {
LIMIT_MAX,
LINES_API,
ORDER_PIECES_API,
ORDERS_API,
RECEIVING_TITLES_API,
VENDORS_API,
} from '../../constants';

import { fetchOrderLines } from './fetchOrderLines';
import { fetchOrderLinesByIds } from './fetchOrderLinesByIds';
import { fetchOrders } from './fetchOrders';
import { fetchOrdersByIds } from './fetchOrdersByIds';
import { fetchOrganizations } from './fetchOrganizations';
import { fetchOrganizationsByIds } from './fetchOrganizationsByIds';
import { fetchPieces } from './fetchPieces';
import { fetchReceivingTitles } from './fetchReceivingTitles';
import { fetchReceivingTitlesByIds } from './fetchReceivingTitlesByIds';

const httpClient = {
get: jest.fn(() => ({
json: jest.fn(() => Promise.resolve({})),
})),
};

const ids = ['1', '2'];
const options = {};
const searchParams = {
[LIMIT_PARAMETER]: LIMIT_MAX,
[SEARCH_PARAMETER]: 'id==1 or id==2',
};

describe('API utils', () => {
beforeEach(() => {
jest.clearAllMocks();
});

describe('fetchOrderLines', () => {
it('should fetch order lines', async () => {
await fetchOrderLines(httpClient)(options);

expect(httpClient.get).toHaveBeenCalledWith(LINES_API, options);
});
});

describe('fetchOrderLinesByIds', () => {
it('should fetch order lines by ids', async () => {
await fetchOrderLinesByIds(httpClient)(ids, options);

expect(httpClient.get).toHaveBeenCalledWith(LINES_API, { searchParams });
});
});

describe('fetchOrders', () => {
it('should fetch orders', async () => {
await fetchOrders(httpClient)(options);

expect(httpClient.get).toHaveBeenCalledWith(ORDERS_API, options);
});
});

describe('fetchOrdersByIds', () => {
it('should fetch orders by ids', async () => {
await fetchOrdersByIds(httpClient)(ids, options);

expect(httpClient.get).toHaveBeenCalledWith(ORDERS_API, { searchParams });
});
});

describe('fetchOrganizations', () => {
it('should fetch organizations', async () => {
await fetchOrganizations(httpClient)(options);

expect(httpClient.get).toHaveBeenCalledWith(VENDORS_API, options);
});
});

describe('fetchOrganizationsByIds', () => {
it('should fetch organizations by ids', async () => {
await fetchOrganizationsByIds(httpClient)(ids, options);

expect(httpClient.get).toHaveBeenCalledWith(VENDORS_API, { searchParams });
});
});

describe('fetchPieces', () => {
it('should fetch pieces', async () => {
await fetchPieces(httpClient)(options);

expect(httpClient.get).toHaveBeenCalledWith(ORDER_PIECES_API, options);
});
});

describe('fetchReceivingTitles', () => {
it('should fetch receiving titles', async () => {
await fetchReceivingTitles(httpClient)(options);

expect(httpClient.get).toHaveBeenCalledWith(RECEIVING_TITLES_API, options);
});
});

describe('fetchReceivingTitlesByIds', () => {
it('should fetch receiving titles by ids', async () => {
await fetchReceivingTitlesByIds(httpClient)(ids, options);

expect(httpClient.get).toHaveBeenCalledWith(RECEIVING_TITLES_API, { searchParams });
});
});
});

0 comments on commit 8e3ce48

Please sign in to comment.