Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
tests: add getOrder error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-ho committed Feb 16, 2021
1 parent 440d092 commit 6936a63
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions __tests__/binance-oco.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { ErrorCodes } from "binance-api-node";

/* eslint-disable @typescript-eslint/no-var-requires */
jest.mock("binance-api-node");

Expand Down Expand Up @@ -638,6 +640,75 @@ describe("orders", () => {
expect(getOrderFilled).toBeCalledWith({ symbol: "BNBBTC", orderId: "1" });
});

const getOrderDoesNotExist = jest.fn(() => {
const error = new Error("Order does not exist");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(error as any).code = ErrorCodes.NO_SUCH_ORDER;
throw error;
});

test("order does not exist error is ignored", async () => {
binance.default.mockImplementation(() => ({
avgPrice: bnbbtcAvgPrice,
accountInfo: mockAccountInfo,
exchangeInfo: bnbbtcExchangeInfo,
order: mockOrder,
orderTest: jest.fn(),
getOrder: getOrderDoesNotExist,
prices: bnbbtcPrices,
ws: {
trades: jest.fn(),
user: jest.fn(cb => {
cb({
eventType: "executionReport",
orderId: "1",
commissionAsset: "BNB",
orderStatus: "FILLED"
});
})
}
}));

await expect(
binanceOco({
pair: "BNBBTC",
amount: 1,
buyPrice: 0.002
})
).resolves.not.toThrow();
});

const getOrderFilledError = jest.fn(() => {
const error = new Error("Anything other than order does not exist");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(error as any).code = ErrorCodes.UNKNOWN;
throw error;
});

test("get order status throws error", async () => {
binance.default.mockImplementation(() => ({
avgPrice: bnbbtcAvgPrice,
accountInfo: mockAccountInfo,
exchangeInfo: bnbbtcExchangeInfo,
order: mockOrder,
orderTest: jest.fn(),
getOrder: getOrderFilledError,
prices: bnbbtcPrices,
ws: {
trades: jest.fn(),
user: jest.fn()
}
}));

await expect(
binanceOco({
pair: "BNBBTC",
amount: 1,
buyPrice: 0.002
})
).rejects.toThrow();
});

test("buy order with cancel price", async () => {
await expect(
binanceOco({
Expand Down

0 comments on commit 6936a63

Please sign in to comment.