feat(): add comprehensive tests for Bitget Private and Public REST API endpoints

- Introduced new test files for private read and write endpoints, covering account, trade, funding, and futures functionalities.
- Added public API tests for server time, ticker, order book, and market trades - Enhanced error handling in tests with specific error codes and messages.
- Updated response utility functions to improve error response structure.
- Removed outdated broker tests to streamline the test suite.
This commit is contained in:
JJ-Cro
2025-03-17 13:38:04 +01:00
parent e31c5fa4af
commit 1e7987a400
12 changed files with 453 additions and 1744 deletions

View File

@@ -1,143 +0,0 @@
import { FuturesClient } from '../../src';
import { sucessEmptyResponseObject } from '../response.util';
describe('Public Spot REST API Endpoints', () => {
const api = new FuturesClient();
const symbol = 'BTCUSDT_UMCBL';
const timestampOneHourAgo = new Date().getTime() - 1000 * 60 * 60;
const from = Number(timestampOneHourAgo.toFixed(0));
const to = from + 1000 * 60 * 30; // 30 minutes
// it('should throw for unauthenticated private calls', async () => {
// expect(() => api.getOpenOrders()).rejects.toMatchObject(
// notAuthenticatedError()
// );
// expect(() => api.getBalances()).rejects.toMatchObject(
// notAuthenticatedError()
// );
// });
/**
*
* Market
*
*/
it('getSymbols()', async () => {
expect(await api.getSymbols('umcbl')).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
});
it('getDepth()', async () => {
expect(await api.getDepth(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
bids: expect.any(Array),
asks: expect.any(Array),
},
});
});
it('getTicker()', async () => {
expect(await api.getTicker(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
bestAsk: expect.any(String),
bestBid: expect.any(String),
},
});
});
it('getAllTickers()', async () => {
expect(await api.getAllTickers('umcbl')).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
});
it('getMarketTrades()', async () => {
expect(await api.getMarketTrades(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
});
it('getCandles()', async () => {
expect(
await api.getCandles(symbol, '1m', `${from}`, `${to}`),
).toMatchObject(expect.any(Array));
});
it('getIndexPrice()', async () => {
expect(await api.getIndexPrice(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
index: expect.any(String),
symbol: expect.any(String),
timestamp: expect.any(String),
},
});
});
it('getNextFundingTime()', async () => {
expect(await api.getNextFundingTime(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
fundingTime: expect.any(String),
symbol: expect.any(String),
},
});
});
it('getHistoricFundingRate()', async () => {
expect(await api.getHistoricFundingRate(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: expect.any(Array),
});
});
it('getCurrentFundingRate()', async () => {
expect(await api.getCurrentFundingRate(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
fundingRate: expect.any(String),
symbol: expect.any(String),
},
});
});
it('getOpenInterest()', async () => {
expect(await api.getOpenInterest(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
amount: expect.any(String),
symbol: expect.any(String),
timestamp: expect.any(String),
},
});
});
it('getMarkPrice()', async () => {
expect(await api.getMarkPrice(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
markPrice: expect.any(String),
symbol: expect.any(String),
timestamp: expect.any(String),
},
});
});
it('getLeverageMinMax()', async () => {
expect(await api.getLeverageMinMax(symbol)).toMatchObject({
...sucessEmptyResponseObject(),
data: {
maxLeverage: expect.any(String),
minLeverage: expect.any(String),
symbol: expect.any(String),
},
});
});
});