-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from tiagosiebler/jerko
feat(): added all client tests
- Loading branch information
Showing
5 changed files
with
233 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.', | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |