chore(): update tests for compatibility with new testing sub account

This commit is contained in:
tiagosiebler
2023-05-16 14:48:20 +01:00
parent 065f72472e
commit a5aa7f6cf2
10 changed files with 59 additions and 38 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "3.5.1", "version": "3.5.8",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "bybit-api", "name": "bybit-api",
"version": "3.5.1", "version": "3.5.8",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"axios": "^0.21.0", "axios": "^0.21.0",

View File

@@ -58,6 +58,7 @@ export const API_ERROR_CODE = {
V5_RISK_ID_NOT_CHANGED: 10001, V5_RISK_ID_NOT_CHANGED: 10001,
V5_AUTO_ADD_MARGIN_NOT_CHANGED: 10001, V5_AUTO_ADD_MARGIN_NOT_CHANGED: 10001,
V5_TPSL_ERROR_NO_POSITION: 10001, V5_TPSL_ERROR_NO_POSITION: 10001,
V5_RISK_ID_NOT_MODIFIED: 110075,
QTY_EXCEEDS_MAX_LIMIT: 130006, QTY_EXCEEDS_MAX_LIMIT: 130006,
ORDER_NOT_FOUND_OR_TOO_LATE_LINEAR: 130010, ORDER_NOT_FOUND_OR_TOO_LATE_LINEAR: 130010,
ORDER_COST_NOT_AVAILABLE: 130021, ORDER_COST_NOT_AVAILABLE: 130021,
@@ -67,6 +68,7 @@ export const API_ERROR_CODE = {
AUTO_ADD_MARGIN_NOT_MODIFIED: 130060, AUTO_ADD_MARGIN_NOT_MODIFIED: 130060,
INSUFFICIENT_BALANCE_FOR_ORDER_COST_LINEAR: 130080, INSUFFICIENT_BALANCE_FOR_ORDER_COST_LINEAR: 130080,
SAME_SLTP_MODE_LINEAR: 130150, SAME_SLTP_MODE_LINEAR: 130150,
NOT_SUPPORTED_FOR_SUBACCOUNTS: 131003,
TRANSFER_ID_EXISTS: 131214, TRANSFER_ID_EXISTS: 131214,
RISK_ID_NOT_MODIFIED: 134026, RISK_ID_NOT_MODIFIED: 134026,
CONTRACT_ORDER_NOT_EXISTS: 140001, CONTRACT_ORDER_NOT_EXISTS: 140001,

View File

@@ -1,4 +1,4 @@
import { AccountAssetClient } from '../../src/'; import { API_ERROR_CODE, AccountAssetClient } from '../../src/';
import { successResponseObject } from '../response.util'; import { successResponseObject } from '../response.util';
describe('Private Account Asset REST API GET Endpoints', () => { describe('Private Account Asset REST API GET Endpoints', () => {
@@ -18,53 +18,58 @@ describe('Private Account Asset REST API GET Endpoints', () => {
it('getInternalTransfers()', async () => { it('getInternalTransfers()', async () => {
expect(await api.getInternalTransfers()).toMatchObject( expect(await api.getInternalTransfers()).toMatchObject(
successResponseObject() successResponseObject(),
); );
}); });
it('getSubAccountTransfers()', async () => { it('getSubAccountTransfers()', async () => {
expect(await api.getSubAccountTransfers()).toMatchObject( expect(await api.getSubAccountTransfers()).toMatchObject({
successResponseObject() ...successResponseObject(),
); ret_code: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
});
}); });
it('getSubAccounts()', async () => { it('getSubAccounts()', async () => {
expect(await api.getSubAccounts()).toMatchObject(successResponseObject()); expect(await api.getSubAccounts()).toMatchObject({
...successResponseObject(),
ret_code: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
});
}); });
it('getUniversalTransfers()', async () => { it('getUniversalTransfers()', async () => {
expect(await api.getInternalTransfers()).toMatchObject( expect(await api.getInternalTransfers()).toMatchObject(
successResponseObject() successResponseObject(),
); );
}); });
it('getDepositRecords()', async () => { it('getDepositRecords()', async () => {
expect(await api.getDepositRecords()).toMatchObject( expect(await api.getDepositRecords()).toMatchObject(
successResponseObject() successResponseObject(),
); );
}); });
it('getWithdrawRecords()', async () => { it('getWithdrawRecords()', async () => {
expect(await api.getWithdrawRecords()).toMatchObject( expect(await api.getWithdrawRecords()).toMatchObject(
successResponseObject() successResponseObject(),
); );
}); });
it('getCoinInformation()', async () => { it('getCoinInformation()', async () => {
expect(await api.getCoinInformation()).toMatchObject( expect(await api.getCoinInformation()).toMatchObject(
successResponseObject() successResponseObject(),
); );
}); });
it('getAssetInformation()', async () => { it('getAssetInformation()', async () => {
expect(await api.getAssetInformation()).toMatchObject( expect(await api.getAssetInformation()).toMatchObject(
successResponseObject() successResponseObject(),
); );
}); });
it('getDepositAddress()', async () => { it('getDepositAddress()', async () => {
expect(await api.getDepositAddress('BTC')).toMatchObject( expect(await api.getDepositAddress('BTC')).toMatchObject({
successResponseObject() ...successResponseObject(),
); ret_code: API_ERROR_CODE.NOT_SUPPORTED_FOR_SUBACCOUNTS,
});
}); });
}); });

View File

@@ -1,4 +1,4 @@
import { AccountAssetClientV3 } from '../../src'; import { API_ERROR_CODE, AccountAssetClientV3 } from '../../src';
import { successResponseObjectV3 } from '../response.util'; import { successResponseObjectV3 } from '../response.util';
// Only some minimal coverage for v3 apis, since v5 apis are already available // Only some minimal coverage for v3 apis, since v5 apis are already available
@@ -27,24 +27,29 @@ describe('Private Account Asset V3 REST API Endpoints', () => {
expect( expect(
await api.getInternalTransfers({ await api.getInternalTransfers({
coin: coin, coin: coin,
}) }),
).toMatchObject(successResponseObjectV3()); ).toMatchObject(successResponseObjectV3());
}); });
it('getSubAccountTransfers()', async () => { it('getSubAccountTransfers()', async () => {
expect(await api.getSubAccountTransfers()).toMatchObject( expect(await api.getSubAccountTransfers()).toMatchObject({
successResponseObjectV3() ...successResponseObjectV3(),
); retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
});
}); });
it('getSubAccounts()', async () => { it('getSubAccounts()', async () => {
expect(await api.getSubAccounts()).toMatchObject(successResponseObjectV3()); expect(await api.getSubAccounts()).toMatchObject({
...successResponseObjectV3(),
retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
});
}); });
it('getUniversalTransfers()', async () => { it('getUniversalTransfers()', async () => {
expect(await api.getUniversalTransfers({ coin: coin })).toMatchObject( expect(await api.getUniversalTransfers({ coin: coin })).toMatchObject({
successResponseObjectV3() ...successResponseObjectV3(),
); retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
});
}); });
it('getTransferableCoinList()', async () => { it('getTransferableCoinList()', async () => {
@@ -52,7 +57,7 @@ describe('Private Account Asset V3 REST API Endpoints', () => {
await api.getTransferableCoinList({ await api.getTransferableCoinList({
fromAccountType: 'SPOT', fromAccountType: 'SPOT',
toAccountType: 'CONTRACT', toAccountType: 'CONTRACT',
}) }),
).toMatchObject(successResponseObjectV3()); ).toMatchObject(successResponseObjectV3());
}); });
}); });

View File

@@ -76,7 +76,7 @@ describe('Private Contract REST API GET Endpoints', () => {
}); });
// Doesn't work on e2e test account. This endpoint throws this error if the account never opened a position before. // Doesn't work on e2e test account. This endpoint throws this error if the account never opened a position before.
it('getOpenInterestLimitInfo()', async () => { it.skip('getOpenInterestLimitInfo()', async () => {
expect(await api.getOpenInterestLimitInfo('ETHUSDT')).toMatchObject({ expect(await api.getOpenInterestLimitInfo('ETHUSDT')).toMatchObject({
retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG, retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG,
retMsg: expect.stringMatching(/OI group don't exist/gim), retMsg: expect.stringMatching(/OI group don't exist/gim),

View File

@@ -20,22 +20,26 @@ describe('Private Copy Trading REST API GET Endpoints', () => {
// (just make sure auth works and endpoint doesn't throw) // (just make sure auth works and endpoint doesn't throw)
it('getActiveOrders()', async () => { it('getActiveOrders()', async () => {
expect(await api.getActiveOrders()).toMatchObject( expect(await api.getActiveOrders()).toMatchObject({
successResponseObjectV3() retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
); });
}); });
it('getPositions()', async () => { it('getPositions()', async () => {
expect(await api.getPositions()).toMatchObject(successResponseObjectV3()); expect(await api.getPositions()).toMatchObject({
retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
});
}); });
it('getBalances()', async () => { it('getBalances()', async () => {
expect(await api.getBalances()).toMatchObject(successResponseObjectV3()); expect(await api.getBalances()).toMatchObject({
retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
});
}); });
it('closePosition()', async () => { it('closePosition()', async () => {
expect(await api.closePosition('SOLUSDT', '1')).toMatchObject({ expect(await api.closePosition('SOLUSDT', '1')).toMatchObject({
retCode: API_ERROR_CODE.COPY_TRADE_NOT_OPEN_ORDER, retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
}); });
}); });
}); });

View File

@@ -185,12 +185,14 @@ describe('Private READ V5 REST API Endpoints', () => {
it('getSubUID()', async () => { it('getSubUID()', async () => {
expect(await api.getSubUID()).toMatchObject({ expect(await api.getSubUID()).toMatchObject({
...successResponseObjectV3(), ...successResponseObjectV3(),
retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
}); });
}); });
it('getUniversalTransferRecords()', async () => { it('getUniversalTransferRecords()', async () => {
expect(await api.getUniversalTransferRecords()).toMatchObject({ expect(await api.getUniversalTransferRecords()).toMatchObject({
...successResponseObjectV3(), ...successResponseObjectV3(),
retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
}); });
}); });
@@ -216,7 +218,8 @@ describe('Private READ V5 REST API Endpoints', () => {
}); });
}); });
it('getMasterDepositAddress()', async () => { // Not available for sub accounts
it.skip('getMasterDepositAddress()', async () => {
expect(await api.getMasterDepositAddress(settleCoin)).toMatchObject({ expect(await api.getMasterDepositAddress(settleCoin)).toMatchObject({
...successResponseObjectV3(), ...successResponseObjectV3(),
}); });

View File

@@ -247,7 +247,7 @@ describe('Private WRITE V5 REST API Endpoints', () => {
).toMatchObject({ ).toMatchObject({
// ...successResponseObjectV3(), // ...successResponseObjectV3(),
// retMsg: '', // retMsg: '',
retCode: API_ERROR_CODE.V5_RISK_ID_NOT_CHANGED, retCode: API_ERROR_CODE.V5_RISK_ID_NOT_MODIFIED,
}); });
}); });
@@ -338,6 +338,7 @@ describe('Private WRITE V5 REST API Endpoints', () => {
it('enableUniversalTransferForSubUIDs()', async () => { it('enableUniversalTransferForSubUIDs()', async () => {
expect(await api.enableUniversalTransferForSubUIDs([])).toMatchObject({ expect(await api.enableUniversalTransferForSubUIDs([])).toMatchObject({
...successResponseObjectV3(), ...successResponseObjectV3(),
retCode: API_ERROR_CODE.INCORRECT_API_KEY_PERMISSIONS,
}); });
}); });
@@ -385,7 +386,8 @@ describe('Private WRITE V5 REST API Endpoints', () => {
}); });
describe('User APIs', () => { describe('User APIs', () => {
it('createSubMember()', async () => { // Not available on sub account
it.skip('createSubMember()', async () => {
expect( expect(
await api.createSubMember({ await api.createSubMember({
memberType: 1, memberType: 1,

View File

@@ -14,7 +14,7 @@
"sourceMap": true, "sourceMap": true,
"esModuleInterop": true, "esModuleInterop": true,
"lib": ["es2017", "dom"], "lib": ["es2017", "dom"],
"outDir": "lib" "outDir": "./lib"
}, },
"include": ["src/**/*"], "include": ["src/**/*"],
"exclude": ["node_modules", "**/node_modules/*", "coverage", "doc"] "exclude": ["node_modules", "**/node_modules/*", "coverage", "doc"]

View File

@@ -1,7 +1,7 @@
{ {
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "distTest", "outDir": "./distTest",
"allowJs": true "allowJs": true
}, },
"include": ["test/**/*.ts", "test/**/*.js"] "include": ["test/**/*.ts", "test/**/*.js"]