This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
generated from bennycode/ts-node-starter
-
Notifications
You must be signed in to change notification settings - Fork 63
/
AccountAPI.test.ts
102 lines (90 loc) · 3.96 KB
/
AccountAPI.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import getAccount from '../test/fixtures/rest/accounts/322dfa88-e10d-4678-856d-2930eac3e62d/GET-200.json' assert {type: 'json'};
import getAccountHistory from '../test/fixtures/rest/accounts/322dfa88-e10d-4678-856d-2930eac3e62d/ledger/GET-200.json' assert {type: 'json'};
import getHolds from '../test/fixtures/rest/accounts/322dfa88-e10d-4678-856d-2930eac3e62d/holds/GET-200.json' assert {type: 'json'};
import genAddress from '../test/fixtures/rest/accounts/322dfa88-e10d-4678-856d-2930eac3e62d/addresses/POST-200.json' assert {type: 'json'};
import listAccounts from '../test/fixtures/rest/accounts/GET-200.json' assert {type: 'json'};
import nock from 'nock';
import {AccountAPI, AccountType} from './AccountAPI.js';
describe('AccountAPI', () => {
afterAll(() => nock.cleanAll());
beforeAll(() => {
nock(global.REST_URL).persist().get(AccountAPI.URL.ACCOUNTS).query(true).reply(200, JSON.stringify(listAccounts));
nock(global.REST_URL)
.persist()
.get(`${AccountAPI.URL.ACCOUNTS}/322dfa88-e10d-4678-856d-2930eac3e62d`)
.query(true)
.reply(200, JSON.stringify(getAccount));
nock(global.REST_URL)
.persist()
.get(`${AccountAPI.URL.ACCOUNTS}/322dfa88-e10d-4678-856d-2930eac3e62d/ledger`)
.query(true)
.reply(200, JSON.stringify(getAccountHistory));
nock(global.REST_URL)
.persist()
.get(`${AccountAPI.URL.ACCOUNTS}/322dfa88-e10d-4678-856d-2930eac3e62d/holds`)
.query(true)
.reply(200, JSON.stringify(getHolds));
nock(global.REST_URL)
.persist()
.post(`${AccountAPI.URL.COINBASE_ACCOUNT}/322dfa88-e10d-4678-856d-2930eac3e62d/addresses`)
.query(true)
.reply(200, JSON.stringify(genAddress));
});
describe('listAccounts', () => {
it('gets a list of trading accounts', async () => {
const accounts = await global.client.rest.account.listAccounts();
expect(accounts.length).toBe(7);
});
});
describe('listCoinbaseAccounts', () => {
it('returns the list of the coinbase accounts for a given user', async () => {
const response = [
{
active: true,
balance: '0.00000000',
currency: 'ETH',
id: 'fc3a8a57-7142-542d-8436-95a3d82e1622',
name: 'ETH Wallet',
primary: false,
type: AccountType.WALLET,
},
];
nock(global.REST_URL).get(AccountAPI.URL.COINBASE_ACCOUNT).reply(200, response);
const coinbaseAccounts = await global.client.rest.account.listCoinbaseAccounts();
expect(coinbaseAccounts.length).toBeGreaterThanOrEqual(1);
expect(coinbaseAccounts[0]).toEqual(response[0]);
});
});
describe('getAccount', () => {
it('gets information for a single account', async () => {
const accounts = await global.client.rest.account.listAccounts();
const accountId = accounts[0].id;
const account = await global.client.rest.account.getAccount(accountId);
expect(account.id).toBe(accountId);
});
});
describe('getAccountHistory', () => {
it('lists the account activity', async () => {
const accounts = await global.client.rest.account.listAccounts();
const accountId = accounts[0].id;
const history = await global.client.rest.account.getAccountHistory(accountId, {limit: 100});
expect(history).toBeDefined();
});
});
describe('getHolds', () => {
it('lists active orders or pending withdraw requests', async () => {
const accounts = await global.client.rest.account.listAccounts();
const accountId = accounts[0].id;
const holds = await global.client.rest.account.getHolds(accountId);
expect(holds).toBeDefined();
});
});
describe('generateAddress', () => {
it('generates an address for an account', async () => {
const newDepositAddress = await global.client.rest.account.generateDepositAddress(
'322dfa88-e10d-4678-856d-2930eac3e62d'
);
expect(newDepositAddress.address).toBe('0xd518A6B23D8bCA15B9cC46a00Be8a818E34Ca79E');
});
});
});