Skip to content

Commit

Permalink
feat(): added all client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ-Cro committed Sep 19, 2024
1 parent 7b7b77d commit bfb4331
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 2 deletions.
83 changes: 83 additions & 0 deletions test/CBExchangeClient/private.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { CBExchangeClient } from '../../src/index.js';

describe('CBExchangeClient PRIVATE', () => {
const account = {
key: process.env.API_KEY_NAME,
secret: process.env.API_PRIVATE_KEY,
passphrase: process.env.API_PASSPHRASE,
};

const rest = new CBExchangeClient({
apiKey: account.key,
apiSecret: account.secret,
apiPassphrase: account.passphrase,
});

it('should have credentials to test with', () => {
expect(account.key).toBeDefined();
expect(account.secret).toBeDefined();
});

describe('public endpoints', () => {
it('should succeed making a GET request', async () => {
const res = await rest.getProductBook({ product_id: 'BTC-USDT' });
//console.log(res);
expect(res).toMatchObject({
bids: expect.any(Array),
asks: expect.any(Array),
sequence: expect.any(Number),
auction_mode: expect.any(Boolean),
auction: expect.any(Object),
time: expect.any(String),
});
});
});

describe('private endpoints', () => {
describe('GET requests', () => {
test('without params', async () => {
const res = await rest.getFees();
expect(res).toMatchObject({
taker_fee_rate: expect.any(String),
maker_fee_rate: expect.any(String),
usd_volume: expect.any(String),
});
});

test('with params', async () => {
const res = await rest.getNewLoanPreview({
currency: 'USDC',
native_amount: '100',
});
//console.log('res with params', res);
expect(res).toMatchObject({
overview: expect.any(Object),
loans: expect.any(Array),
});
});
});

describe('POST requests', () => {
test('with params as request body', async () => {
try {
const res = await rest.createProfile({
name: 'testProfile',
});

console.log(`res "${expect.getState().currentTestName}"`, res);
expect(res).toMatchObject({
whatever: true,
});
} catch (e: any) {
// These are deliberatly restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// console.log(`err "${expect.getState().currentTestName}"`, e?.body);
console.log('Error, CBExchange, post req:', e);
const responseBody = e?.body;
expect(responseBody).toMatchObject({
message: 'Unauthorized.',
});
}
});
});
});
});
2 changes: 1 addition & 1 deletion test/CBExchangeClient/public.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('CBExchangeClient PUBLIC', () => {
describe('public endpoints', () => {
it('should succeed making a GET request', async () => {
const res = await rest.getProductBook({ product_id: 'BTC-USDT' });
console.log(res);
//console.log(res);
expect(res).toMatchObject({
bids: expect.any(Array),
asks: expect.any(Array),
Expand Down
78 changes: 78 additions & 0 deletions test/CBInternationalClient/private.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { CBInternationalClient } from '../../src/index.js';

describe('CBInternationalClient PRIVATE', () => {
const account = {
key: process.env.API_KEY_NAME,
secret: process.env.API_PRIVATE_KEY,
passphrase: process.env.API_PASSPHRASE,
};

const rest = new CBInternationalClient({
apiKey: account.key,
apiSecret: account.secret,
apiPassphrase: account.passphrase,
});

it('should have credentials to test with', () => {
expect(account.key).toBeDefined();
expect(account.secret).toBeDefined();
});

describe('public endpoints', () => {
it('should succeed making a GET request', async () => {
const res = await rest.getHistoricalFundingRates({
instrument: 'BTC-PERP',
});
//console.log(res);
expect(res).toMatchObject({
pagination: expect.any(Object),
results: expect.any(Array),
});
});
});

describe('private endpoints', () => {
describe('GET requests', () => {
test('without params', async () => {
const res = await rest.getOpenOrders({});
expect(res).toMatchObject({
pagination: expect.any(Object),
results: expect.any(Array),
});
});

test('with params', async () => {
const res = await rest.getRankings({ instrument_type: 'spot' });
expect(res).toMatchObject({
last_updated: expect.any(String),
statistics: expect.any(Object),
});
});
});

describe('POST requests', () => {
test('with params as request body', async () => {
try {
const res = await rest.createPortfolio({
name: 'testPorftolio',
});

console.log(`res "${expect.getState().currentTestName}"`, res);
expect(res).toMatchObject({
whatever: true,
});
} catch (e: any) {
// These are deliberatly restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// console.log(`err "${expect.getState().currentTestName}"`, e?.body);
console.log('Error, CBINTX, post req:', e);
const responseBody = e?.body;
expect(responseBody).toMatchObject({
title: 'Unauthorized',
status: 401,
error: 'UNAUTHORIZED',
});
}
});
});
});
});
2 changes: 1 addition & 1 deletion test/CBInternationalClient/public.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('CBInternationalClient PUBLIC', () => {
const res = await rest.getHistoricalFundingRates({
instrument: 'BTC-PERP',
});
console.log(res);
//console.log(res);
expect(res).toMatchObject({
pagination: expect.any(Object),
results: expect.any(Array),
Expand Down
70 changes: 70 additions & 0 deletions test/CBPrimeClient/private.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { CBPrimeClient } from '../../src/index.js';

describe('CBPrimeClient PRIVATE', () => {
const account = {
key: process.env.API_KEY_NAME,
secret: process.env.API_PRIVATE_KEY,
passphrase: process.env.API_PASSPHRASE,
};

const rest = new CBPrimeClient({
apiKey: account.key,
apiSecret: account.secret,
apiPassphrase: account.passphrase,
});

let portfolioId: string;

it('should have credentials to test with', () => {
expect(account.key).toBeDefined();
expect(account.secret).toBeDefined();
});

describe('private endpoints', () => {
describe('GET requests', () => {
test('without params', async () => {
const res = await rest.getPortfolios();
expect(res).toMatchObject({
portfolios: expect.any(Array),
});
portfolioId = res.portfolios[0].id;
});

test('with params', async () => {
const res = await rest.getPortfolioById({ portfolio_id: portfolioId });
expect(res).toMatchObject({
portfolio: expect.any(Object),
});
});
});

describe('POST requests', () => {
test('with params as request body', async () => {
try {
const res = await rest.getOrderPreview({
portfolio_id: portfolioId,
side: 'BUY',
product_id: 'BTC-USDT',
type: 'MARKET',
quote_value: '1',
});

console.log(`res "${expect.getState().currentTestName}"`, res);
expect(res).toMatchObject({
whatever: true,
});
} catch (e: any) {
// These are deliberatly restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// console.log(`err "${expect.getState().currentTestName}"`, e?.body);
console.log('Error, CBPrime, post req:', e);
const responseBody = e?.body;
expect(responseBody).toMatchObject({
title: 'Unauthorized',
status: 401,
error: 'UNAUTHORIZED',
});
}
});
});
});
});

0 comments on commit bfb4331

Please sign in to comment.