Files
xahau.js/test/broadcastClient.ts
Mayukha Vadari cab359cfbd refactor: move fixtures closer to tests (part 2) (#1561)
* move echo

* move fee

* move subscribe/unsubscribe

* move ledger_current

* move ledger_data

* move submit/submit_multisigned

* remove account_tx/account_offers/gateway_balances

* move account_info

* remove ledger_entry

* remove tx

* remove account_lines

* remove ripple_path_find

* remove ledger

* remove book_offers

* move ping

* remove global_config

* move test_command

* additional mock-rippled cleanup

* add explanatory comment to mock.addResponse
2021-09-14 16:56:39 -04:00

54 lines
1.5 KiB
TypeScript

import _ from 'lodash'
import assert from 'assert-diff'
import setupClient from './setupClient'
import responses from './fixtures/responses'
import rippled from './fixtures/rippled'
import {ignoreWebSocketDisconnect} from './testUtils'
const TIMEOUT = 20000
function checkResult(expected, response) {
if (expected.txJSON) {
assert(response.txJSON)
assert.deepEqual(JSON.parse(response.txJSON), JSON.parse(expected.txJSON))
}
assert.deepEqual(_.omit(response, 'txJSON'), _.omit(expected, 'txJSON'))
return response
}
describe('BroadcastClient', function () {
this.timeout(TIMEOUT)
beforeEach(setupClient.setupBroadcast)
afterEach(setupClient.teardown)
it('base', function () {
this.mocks.forEach((mock) => {
mock.addResponse({command: 'server_info'}, rippled.server_info.normal)
})
assert(this.client.isConnected())
return this.client
.request({command: "server_info"})
.then(response => {
return checkResult(responses.getServerInfo, response.result.info)
})
})
it('error propagation', function (done) {
const data = {error: 'type', error_message: 'info'}
this.mocks.forEach((mock) => {
mock.addResponse({command: 'echo'}, data)
})
this.client.once('error', (type, info) => {
assert.strictEqual(type, 'type')
assert.strictEqual(info, 'info')
done()
})
this.client._clients[1].connection
.request({
command: 'echo',
data
})
.catch(ignoreWebSocketDisconnect)
})
})