Files
xahau.js/test/client/getBalances.ts
Mayukha Vadari 949cc031ee Lints top-level test files (#1594)
* lint broadcastClient

* lint client

* fix most of connection

* remove unused files

* lint mockRippled

* lint mockRippledTest

* lint runClientTests

* lint setupClient

* lint setupClientWeb

* lint shamap

* lint testUtils

* resolve tsc issues

* Fix tests

* lint rest of connection

* respond to comments
2021-10-04 14:10:12 -04:00

95 lines
3.3 KiB
TypeScript

import responses from '../fixtures/responses'
import rippled from '../fixtures/rippled'
import rippledAccountLines from '../fixtures/rippled/accountLines'
import { setupClient, teardownClient } from '../setupClient'
import { assertResultMatch, addressTests } from '../testUtils'
/**
* Every test suite exports their tests in the default object.
* - Check out the "TestSuite" type for documentation on the interface.
* - Check out "test/client/index.ts" for more information about the test runner.
*/
describe('getBalances', function () {
beforeEach(setupClient)
afterEach(teardownClient)
addressTests.forEach(function (test) {
describe(test.type, function () {
it('getBalances', async function () {
this.mockRippled.addResponse(
'account_info',
rippled.account_info.normal,
)
this.mockRippled.addResponse(
'account_lines',
rippledAccountLines.normal,
)
this.mockRippled.addResponse('ledger', rippled.ledger.normal)
const result = await this.client.getBalances(test.address)
assertResultMatch(result, responses.getBalances, 'getBalances')
})
it('getBalances - limit', async function () {
const options = { limit: 3, ledgerVersion: 123456 }
this.mockRippled.addResponse(
'account_info',
rippled.account_info.normal,
)
this.mockRippled.addResponse(
'account_lines',
rippledAccountLines.normal,
)
this.mockRippled.addResponse('ledger', rippled.ledger.normal)
const expectedResponse = responses.getBalances.slice(0, 3)
const result = await this.client.getBalances(test.address, options)
assertResultMatch(result, expectedResponse, 'getBalances')
})
it('getBalances - limit & currency', async function () {
const options = { currency: 'USD', limit: 3 }
this.mockRippled.addResponse(
'account_info',
rippled.account_info.normal,
)
this.mockRippled.addResponse(
'account_lines',
rippledAccountLines.normal,
)
this.mockRippled.addResponse('ledger', rippled.ledger.normal)
const expectedResponse = responses.getBalances
.filter((item) => item.currency === 'USD')
.slice(0, 3)
const result = await this.client.getBalances(test.address, options)
assertResultMatch(result, expectedResponse, 'getBalances')
})
it('getBalances - limit & currency & issuer', async function () {
const options = {
currency: 'USD',
counterparty: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
limit: 3,
}
this.mockRippled.addResponse(
'account_info',
rippled.account_info.normal,
)
this.mockRippled.addResponse(
'account_lines',
rippledAccountLines.normal,
)
this.mockRippled.addResponse('ledger', rippled.ledger.normal)
const expectedResponse = responses.getBalances
.filter(
(item) =>
item.currency === 'USD' &&
item.counterparty === 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
)
.slice(0, 3)
const result = await this.client.getBalances(test.address, options)
assertResultMatch(result, expectedResponse, 'getBalances')
})
})
})
})