From ab5ba5f82b915c05f153347d7ca40422d02cfcf6 Mon Sep 17 00:00:00 2001 From: Bilal Zahory Date: Wed, 21 Aug 2024 14:55:32 -0400 Subject: [PATCH] test: add testing case --- .../src/utils/swaps.test.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/packages/transaction-controller/src/utils/swaps.test.ts b/packages/transaction-controller/src/utils/swaps.test.ts index 6b0d0dd26e1..b562df9ec45 100644 --- a/packages/transaction-controller/src/utils/swaps.test.ts +++ b/packages/transaction-controller/src/utils/swaps.test.ts @@ -375,6 +375,60 @@ describe('updateSwapsTransaction', () => { swapAndSendRecipient, }); }); + + it('should update swap and send approval transaction and publish TransactionController:transactionNewSwapAndSendApproval', async () => { + const sourceTokenSymbol = 'ETH'; + const type = TransactionType.swapAndSendApproval; + + swaps.meta = { + sourceTokenSymbol, + type, + }; + transactionType = TransactionType.swapAndSendApproval; + + const transactionNewSwapAndSendApprovalEventListener = jest.fn(); + messenger.subscribe( + 'TransactionController:transactionNewSwapAndSendApproval', + transactionNewSwapAndSendApprovalEventListener, + ); + + updateSwapsTransaction(transactionMeta, transactionType, swaps, request); + expect( + transactionNewSwapAndSendApprovalEventListener, + ).toHaveBeenCalledTimes(1); + expect(transactionNewSwapAndSendApprovalEventListener).toHaveBeenCalledWith( + { + transactionMeta: { + ...transactionMeta, + sourceTokenSymbol, + type, + }, + }, + ); + }); + + it('should return the swap and send approval transaction updated with information', async () => { + const sourceTokenSymbol = 'ETH'; + const type = TransactionType.swapAndSendApproval; + + swaps.meta = { + sourceTokenSymbol, + type, + }; + transactionType = TransactionType.swapAndSendApproval; + + const updatedSwapsTransaction = updateSwapsTransaction( + transactionMeta, + transactionType, + swaps, + request, + ); + expect(updatedSwapsTransaction).toStrictEqual({ + ...transactionMeta, + sourceTokenSymbol, + type, + }); + }); }); describe('updatePostTransactionBalance', () => {