mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
* modify account_info mocks * move account_objects * move server_info * remove config (no longer needed) * switch to simple dictionary instead of handlers * fix rebase issues * refactor: addResponse method on mock server object (#1555) Co-authored-by: Elliot Lee <github.public@intelliot.com>
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import _ from 'lodash'
|
|
import assert from 'assert-diff'
|
|
import setupClient from './setup-client'
|
|
import responses from './fixtures/responses'
|
|
import rippled from './fixtures/rippled'
|
|
import {ignoreWebSocketDisconnect} from './utils'
|
|
|
|
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)
|
|
})
|
|
const expected = {request_server_info: 1}
|
|
this.mocks.forEach((mock) => mock.expect(Object.assign({}, expected)))
|
|
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) {
|
|
this.client.once('error', (type, info) => {
|
|
assert.strictEqual(type, 'type')
|
|
assert.strictEqual(info, 'info')
|
|
done()
|
|
})
|
|
this.client._clients[1].connection
|
|
.request({
|
|
command: 'echo',
|
|
data: {error: 'type', error_message: 'info'}
|
|
})
|
|
.catch(ignoreWebSocketDisconnect)
|
|
})
|
|
})
|