Skip to content

Commit

Permalink
Add Handle unexpected errors
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin committed Sep 1, 2023
1 parent bd550ee commit 0a3ea1e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/composable/ConditionalOrder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
})
})

0 comments on commit 0a3ea1e

Please sign in to comment.