feat(#3): implement initial public API tests

This commit is contained in:
tiagosiebler
2021-06-24 00:26:52 +01:00
parent b4614a71bb
commit f8fcb83628
7 changed files with 3923 additions and 5 deletions

View File

@@ -0,0 +1,70 @@
import { InverseClient } from "../../src/inverse-client";
import { successResponseList, successResponseObject } from "../response.util";
describe('Public Inverse REST API Endpoints', () => {
const useLivenet = true;
const api = new InverseClient(undefined, undefined, useLivenet);
const symbol = 'BTCUSD';
const interval = '15';
const timestampOneHourAgo = (new Date().getTime() / 1000) - (1000 * 60 * 60);
const from = Number(timestampOneHourAgo.toFixed(0));
describe('Inverse only endpoints', () => {
it('should throw for unauthenticated private calls', async () => {
expect(() => api.getPosition()).rejects.toMatchObject(new Error('Private endpoints require api and private keys set'));
});
it('getKline()', async () => {
expect(
await api.getKline({ symbol, interval, from })
).toMatchObject(successResponseList());
});
it('getTrades()', async () => {
expect(await api.getTrades({ symbol })).toMatchObject(successResponseList());
});
it('getIndexPriceKline()', async () => {
expect(await api.getIndexPriceKline({ symbol, interval, from })).toMatchObject(successResponseList());
});
it('getPremiumIndexKline()', async () => {
expect(await api.getPremiumIndexKline({ symbol, interval, from })).toMatchObject(successResponseList());
});
it('getLastFundingRate()', async () => {
expect(await api.getLastFundingRate({ symbol })).toMatchObject(successResponseObject());
});
});
describe('Shared endpoints', () => {
it('should throw for unauthenticated private calls', async () => {
expect(() => api.getApiKeyInfo()).rejects.toMatchObject(new Error('Private endpoints require api and private keys set'));
});
it('getOrderBook()', async () => {
expect(await api.getOrderBook({ symbol })).toMatchObject(successResponseList());
});
it('getTickers()', async () => {
expect(await api.getTickers()).toMatchObject(successResponseList());
});
it('getSymbols()', async () => {
expect(await api.getSymbols()).toMatchObject(successResponseList());
});
it('getLiquidations()', async () => {
expect(await api.getLiquidations({ symbol })).toMatchObject(successResponseList());
});
it('getServerTime()', async () => {
expect(await api.getServerTime()).toMatchObject(successResponseObject());
});
it('getApiAnnouncements()', async () => {
expect(await api.getApiAnnouncements()).toMatchObject(successResponseList());
});
});
});

22
test/response.util.ts Normal file
View File

@@ -0,0 +1,22 @@
export function successResponseList() {
return {
"ext_code": "",
"ext_info": "",
"result": expect.any(Array),
"ret_code": 0,
"ret_msg": "OK",
"time_now": expect.any(String),
};
};
export function successResponseObject() {
return {
"ext_code": "",
"ext_info": "",
"result": expect.any(Object),
"ret_code": 0,
"ret_msg": "OK",
"time_now": expect.any(String),
};
};