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
sameersubudhi committed Jan 26, 2024
1 parent f652672 commit d63cd77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ module.exports = [
address: { optional: true, type: 'string', pattern: regex.ADDRESS_LISK32 },
publicKey: { optional: true, type: 'string', pattern: regex.PUBLIC_KEY },
name: { optional: true, type: 'string', pattern: regex.NAME },
tokenID: { optional: false, type: 'string', pattern: regex.TOKEN_ID },
// Set tokenID as optional in indexer because export microservice needs it to be optional. Should remain mandatory everywhere else.
tokenID: { optional: true, type: 'string', pattern: regex.TOKEN_ID },
},
},
{
Expand Down
40 changes: 23 additions & 17 deletions services/export/tests/unit/shared/transactionsExport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,9 @@ describe('Test getOpeningBalance method', () => {
tokenID: '0400000000000000',
};

jest.mock(mockedRequestFilePath, () => {
const actual = jest.requireActual(mockedRequestFilePath);
return {
...actual,
requestConnector() {
return mockUserSubstore;
},
};
});
jest.mock(mockedRequestFilePath);
const { requestConnector } = require(mockedRequestFilePath);
requestConnector.mockResolvedValueOnce(undefined).mockResolvedValueOnce(mockUserSubstore);

const { getOpeningBalance } = require('../../../shared/transactionsExport');

Expand All @@ -100,7 +94,7 @@ describe('Test getOpeningBalance method', () => {
expect(openingBalance).toEqual(expectedResponse);
});

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

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

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

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

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

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

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

0 comments on commit d63cd77

Please sign in to comment.