From 0a3ea1e25e2b1dddc7337bb054977f6f5d0199a2 Mon Sep 17 00:00:00 2001 From: Anxo Rodriguez Date: Fri, 1 Sep 2023 15:29:54 +0100 Subject: [PATCH] Add Handle unexpected errors --- src/composable/ConditionalOrder.spec.ts | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/composable/ConditionalOrder.spec.ts b/src/composable/ConditionalOrder.spec.ts index 6ad71711..904fd6b0 100644 --- a/src/composable/ConditionalOrder.spec.ts +++ b/src/composable/ConditionalOrder.spec.ts @@ -253,4 +253,30 @@ describe('Poll Single Orders', () => { reason: 'InvalidConditionalOrder. Reason: ' + validationError, }) }) + + test('[UNEXPECTED_ERROR] getTradeableOrderWithSignature throws an error', async () => { + // GIVEN: getTradeableOrderWithSignature throws + const error = new Error(`I'm sorry, but is not a good time to trade`) + mockGetTradeableOrderWithSignature.mockImplementation(() => { + throw error + }) + + // GIVEN: Every validation is OK (auth + contract returns an order + order is valid) + const order = createOrder() + const mockIsValid = jest.fn(order.isValid).mockReturnValue({ isValid: true }) + order.isValid = mockIsValid + mockSingleOrders.mockReturnValue(true) + + // WHEN: we poll + const pollResult = await order.poll(param) + + // THEN: we expect no CALLs to the + expect(mockGetTradeableOrderWithSignature).toBeCalledTimes(1) + + // THEN: We expect a SUCCESS result, which returns the order and the signature + expect(pollResult).toEqual({ + result: PollResultCode.UNEXPECTED_ERROR, + error, + }) + }) })