Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
🔨 Fix broken unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sameersubudhi committed Jan 25, 2024
1 parent 4336100 commit 8fe0ba7
Showing 1 changed file with 7 additions and 31 deletions.
38 changes: 7 additions & 31 deletions services/export/tests/unit/shared/requestAll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { resolve } = require('path');

const { transactions } = require('../../constants/transaction');

const { requestAllStandard, requestAllCustom } = require('../../../shared/requestAll');
const requestAll = require('../../../shared/requestAll');

const mockedRequestFilePath = resolve(`${__dirname}/../../../shared/helpers/request`);

Expand All @@ -28,7 +28,7 @@ const getResponseOfLength = (n, singleRequestLimit) =>
limit: singleRequestLimit,
}));

describe('Test requestAllStandard method', () => {
describe('Test requestAll method', () => {
const func = async params => ({
data: [params],
meta: {
Expand All @@ -39,7 +39,7 @@ describe('Test requestAllStandard method', () => {
it('should call passed function multiple times when total limit > single response limit', async () => {
const singleRequestLimit = 5;
const expectedResponse = getResponseOfLength(4, singleRequestLimit);
const response = await requestAllStandard(
const response = await requestAll(
func,
{ limit: singleRequestLimit, extra_param: 'extra_value' },
20,
Expand All @@ -56,7 +56,7 @@ describe('Test requestAllStandard method', () => {
total: singleRequestLimit - 1,
},
});
const response = await requestAllStandard(
const response = await requestAll(
func2,
{ limit: singleRequestLimit, extra_param: 'extra_value' },
singleRequestLimit * 10,
Expand All @@ -67,7 +67,7 @@ describe('Test requestAllStandard method', () => {
it('should call passed function only once when total limit < single response limit', async () => {
const singleRequestLimit = 50;
const expectedResponse = getResponseOfLength(1, singleRequestLimit);
const response = await requestAllStandard(
const response = await requestAll(
func,
{ limit: singleRequestLimit, extra_param: 'extra_value' },
20,
Expand All @@ -77,37 +77,13 @@ describe('Test requestAllStandard method', () => {

it('should throw error if passed function is null', async () => {
expect(async () =>
requestAllStandard(null, { limit: 50, extra_param: 'extra_value' }, 20),
requestAll(null, { limit: 50, extra_param: 'extra_value' }, 20),
).rejects.toThrow();
});

it('should throw error if passed function is undefined', async () => {
expect(async () =>
requestAllStandard(undefined, { limit: 50, extra_param: 'extra_value' }, 20),
requestAll(undefined, { limit: 50, extra_param: 'extra_value' }, 20),
).rejects.toThrow();
});
});

describe('Test requestAllCustom method', () => {
it('should return proper response', async () => {
/* eslint-disable-next-line import/no-dynamic-require */
const { requestConnector } = require(mockedRequestFilePath);

jest.mock(mockedRequestFilePath, () => ({
requestConnector: jest.fn(),
}));

requestConnector.mockResolvedValue([
transactions.tokenTransfer,
transactions.tokenTransferCrossChain,
]);

const response = await requestAllCustom(requestConnector, 'transactions', { limit: 2 }, 2);
expect(response).toEqual([transactions.tokenTransfer, transactions.tokenTransferCrossChain]);
expect(response.length).toBe(2);
});

it('should throw error when called with invalid function', async () => {
expect(requestAllCustom('invalidFunc', 'transactions')).rejects.toThrow();
});
});

0 comments on commit 8fe0ba7

Please sign in to comment.