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

Commit

Permalink
✔️ Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Jan 25, 2024
1 parent 8fe0ba7 commit c2d00ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 46 deletions.
6 changes: 0 additions & 6 deletions services/export/tests/unit/shared/requestAll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
const { resolve } = require('path');

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

const requestAll = require('../../../shared/requestAll');

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

const getResponseOfLength = (n, singleRequestLimit) =>
new Array(n).fill().map((e, i) => ({
extra_param: 'extra_value',
Expand Down
56 changes: 16 additions & 40 deletions services/export/tests/unit/shared/transactionsExport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
*/
/* eslint-disable mocha/max-top-level-suites */

/* eslint-disable import/no-dynamic-require */
const { resolve } = require('path');
const moment = require('moment');

Expand Down Expand Up @@ -72,31 +72,19 @@ const partialFilenameExtension = '.json';

describe('Test getOpeningBalance method', () => {
it('should return opening balance when called with valid address', async () => {
const mockUserSubstore = [
{
address: 'lskyvvam5rxyvbvofxbdfcupxetzmqxu22phm4yuo',
availableBalance: '100000000000000',
lockedBalances: [],
tokenID: '0400000000000000',
},
];

jest.mock(mockedRequestAllFilePath, () => {
const actual = jest.requireActual(mockedRequestAllFilePath);
return {
...actual,
requestAllCustom() {
return { userSubstore: mockUserSubstore };
},
};
});
const mockUserSubstore = {
address: 'lskyvvam5rxyvbvofxbdfcupxetzmqxu22phm4yuo',
availableBalance: '100000000000000',
lockedBalances: [],
tokenID: '0400000000000000',
};

jest.mock(mockedRequestFilePath, () => {
const actual = jest.requireActual(mockedRequestFilePath);
return {
...actual,
requestConnector() {
return { token: { userSubstore: mockUserSubstore } };
return mockUserSubstore;
},
};
});
Expand All @@ -112,7 +100,7 @@ describe('Test getOpeningBalance method', () => {
expect(openingBalance).toEqual(expectedResponse);
});

it('should throw error when called with undefined', async () => {
it('should return null when called with undefined', async () => {
jest.mock(mockedRequestFilePath, () => {
const actual = jest.requireActual(mockedRequestFilePath);
return {
Expand All @@ -124,7 +112,7 @@ describe('Test getOpeningBalance method', () => {
});

const { getOpeningBalance } = require('../../../shared/transactionsExport');
expect(getOpeningBalance(undefined)).rejects.toThrow();
expect(async () => getOpeningBalance(undefined).toBeNull());
});
});

Expand Down Expand Up @@ -156,15 +144,9 @@ describe('Test getCrossChainTransferTransactionInfo method', () => {
},
];

jest.mock(mockedRequestAllFilePath, () => {
const actual = jest.requireActual(mockedRequestAllFilePath);
return {
...actual,
requestAllStandard() {
return mockEventData;
},
};
});
jest.mock(mockedRequestAllFilePath);
const requestAll = require(mockedRequestAllFilePath);
requestAll.mockReturnValueOnce(mockEventData);

jest.mock(mockedRequestFilePath, () => {
const actual = jest.requireActual(mockedRequestFilePath);
Expand Down Expand Up @@ -259,15 +241,9 @@ describe('Test getRewardAssignedInfo method', () => {
},
];

jest.mock(mockedRequestAllFilePath, () => {
const actual = jest.requireActual(mockedRequestAllFilePath);
return {
...actual,
requestAllStandard() {
return mockEventData;
},
};
});
jest.mock(mockedRequestAllFilePath);
const requestAll = require(mockedRequestAllFilePath);
requestAll.mockReturnValueOnce(mockEventData);

jest.mock(mockedRequestFilePath, () => {
const actual = jest.requireActual(mockedRequestFilePath);
Expand Down

0 comments on commit c2d00ed

Please sign in to comment.