Skip to content

Commit

Permalink
Add Failure Flow Massa Approve Test
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Nov 20, 2023
1 parent 1681b38 commit 5d61dfb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
55 changes: 51 additions & 4 deletions jest/__tests__/handleApproveMassa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('handleApproveMASSA', () => {
const decimals = 18;

const mockSetLoading = jest.fn().mockImplementation();
const handleErrorMessage = jest.fn();
// const handleErrorMessage = jest.fn();

const result = await handleApproveMASSA(
client as any,

Check warning on line 43 in jest/__tests__/handleApproveMassa.test.ts

View workflow job for this annotation

GitHub Actions / lint-frontend

Unexpected any. Specify a different type
Expand All @@ -56,7 +56,7 @@ describe('handleApproveMASSA', () => {

expect(mockSetLoading).toHaveBeenNthCalledWith(2, { approve: 'success' });

expect(handleErrorMessage).not.toHaveBeenCalled();
// expect(handleErrorMessage).not.toHaveBeenCalled();
expect(result).toBeTruthy();
});

Expand All @@ -79,7 +79,7 @@ describe('handleApproveMASSA', () => {
const amount = '13';
const decimals = 18;
const mockSetLoading = jest.fn().mockImplementation();
const handleErrorMessage = jest.fn();
// const handleErrorMessage = jest.fn();
const result = await handleApproveMASSA(
client as any,

Check warning on line 84 in jest/__tests__/handleApproveMassa.test.ts

View workflow job for this annotation

GitHub Actions / lint-frontend

Unexpected any. Specify a different type
mockSetLoading,
Expand All @@ -97,7 +97,54 @@ describe('handleApproveMASSA', () => {

expect(mockSetLoading).toHaveBeenNthCalledWith(2, { approve: 'success' });

expect(handleErrorMessage).not.toHaveBeenCalled();
// expect(handleErrorMessage).not.toHaveBeenCalled();
expect(result).toBeTruthy();
});

test('should throw', async () => {
const mockCallSmartContract = jest
.fn()
.mockImplementationOnce(() => Promise.reject(new Error('error')));

const mockGetOperationStatus = jest
.fn()
.mockResolvedValueOnce(EOperationStatus.FINAL_SUCCESS);

const client = {
smartContracts: () => ({
callSmartContract: mockCallSmartContract,
getOperationStatus: mockGetOperationStatus,
}),
};

const amount = '1313';
const decimals = 18;
const mockSetLoading = jest.fn().mockImplementation();
// const handleErrorMessage = jest.fn().mockImplementation();
const result = await handleApproveMASSA(
client as any,

Check warning on line 125 in jest/__tests__/handleApproveMassa.test.ts

View workflow job for this annotation

GitHub Actions / lint-frontend

Unexpected any. Specify a different type
mockSetLoading,
{} as any,

Check warning on line 127 in jest/__tests__/handleApproveMassa.test.ts

View workflow job for this annotation

GitHub Actions / lint-frontend

Unexpected any. Specify a different type
{} as any,

Check warning on line 128 in jest/__tests__/handleApproveMassa.test.ts

View workflow job for this annotation

GitHub Actions / lint-frontend

Unexpected any. Specify a different type
token,
amount,
decimals,
);

expect(mockSetLoading).toHaveBeenNthCalledWith(1, { approve: 'loading' });

expect(mockCallSmartContract).toHaveBeenCalled();
expect(mockGetOperationStatus).not.toHaveBeenCalled();

expect(mockSetLoading).toHaveBeenNthCalledWith(2, {
box: 'error',
approve: 'error',
burn: 'error',
redeem: 'error',
});

// expect(handleErrorMessage).toHaveBeenCalled();

expect(result).toBeFalsy();
});
});
1 change: 1 addition & 0 deletions src/custom/bridge/handlers/handleErrorMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function handleErrorMessage(
const cause = (error as ICustomError)?.cause;
const isTimeout = cause?.error === 'timeout';

// bridge side this fn only show timeout error
if (isTimeout) {
setLoading({
box: 'warning',
Expand Down

0 comments on commit 5d61dfb

Please sign in to comment.