mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-02 10:05:49 +00:00
feat: Add typescript types to subscribe (#1576)
feat: Add typescript types to subscribe (#1576)
This commit is contained in:
committed by
Mayukha Vadari
parent
a996fafe79
commit
c8a2a6690b
103
test/client/subscribe.ts
Normal file
103
test/client/subscribe.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import { assert } from 'chai'
|
||||
|
||||
import rippled from '../fixtures/rippled'
|
||||
import setupClient from '../setupClient'
|
||||
|
||||
describe('Subscription', function () {
|
||||
beforeEach(setupClient.setup)
|
||||
afterEach(setupClient.teardown)
|
||||
|
||||
it('Successfully Subscribes', async function () {
|
||||
this.mockRippled.addResponse('subscribe', rippled.subscribe.success)
|
||||
|
||||
const result = await this.client.request({
|
||||
command: 'subscribe',
|
||||
})
|
||||
|
||||
assert.equal(result.status, 'success')
|
||||
})
|
||||
|
||||
it('Successfully Unsubscribes', async function () {
|
||||
this.mockRippled.addResponse('unsubscribe', rippled.unsubscribe)
|
||||
|
||||
const result = await this.client.request({
|
||||
command: 'unsubscribe',
|
||||
})
|
||||
|
||||
assert.equal(result.status, 'success')
|
||||
})
|
||||
|
||||
it('Emits transaction', async function (done) {
|
||||
this.client.on('transaction', (tx) => {
|
||||
assert(tx.type === 'transaction')
|
||||
done()
|
||||
})
|
||||
|
||||
this.client.connection.onMessage(
|
||||
JSON.stringify(rippled.streams.transaction),
|
||||
)
|
||||
})
|
||||
|
||||
it('Emits ledger', async function (done) {
|
||||
this.client.on('ledgerClosed', (ledger) => {
|
||||
assert(ledger.type === 'ledgerClosed')
|
||||
done()
|
||||
})
|
||||
|
||||
this.client.connection.onMessage(JSON.stringify(rippled.streams.ledger))
|
||||
})
|
||||
|
||||
it('Emits peerStatusChange', async function (done) {
|
||||
this.client.on('peerStatusChange', (status) => {
|
||||
assert(status.type === 'peerStatusChange')
|
||||
done()
|
||||
})
|
||||
|
||||
this.client.connection.onMessage(JSON.stringify(rippled.streams.peerStatus))
|
||||
})
|
||||
|
||||
it('Emits consensusPhase', async function (done) {
|
||||
this.client.on('consensusPhase', (phase) => {
|
||||
assert(phase.type === 'consensusPhase')
|
||||
done()
|
||||
})
|
||||
|
||||
this.client.connection.onMessage(JSON.stringify(rippled.streams.consensus))
|
||||
})
|
||||
|
||||
it('Emits path_find', async function (done) {
|
||||
this.client.on('path_find', (path) => {
|
||||
assert(path.type === 'path_find')
|
||||
done()
|
||||
})
|
||||
|
||||
this.client.connection.onMessage(JSON.stringify(rippled.streams.pathFind))
|
||||
})
|
||||
|
||||
it('Emits peerStatusChange', async function (done) {
|
||||
this.client.on('peerStatusChange', (path) => {
|
||||
assert(path.type === 'peerStatusChange')
|
||||
done()
|
||||
})
|
||||
|
||||
this.client.connection.onMessage(JSON.stringify(rippled.streams.peerStatus))
|
||||
})
|
||||
|
||||
it('Emits validationReceived', async function (done) {
|
||||
this.client.on('validationReceived', (path) => {
|
||||
assert(path.type === 'validationReceived')
|
||||
done()
|
||||
})
|
||||
|
||||
this.client.connection.onMessage(JSON.stringify(rippled.streams.validation))
|
||||
})
|
||||
|
||||
it('Emits manifestReceived', async function (done) {
|
||||
this.client.on('manifestReceived', (path) => {
|
||||
assert(path.type === 'manifestReceived')
|
||||
done()
|
||||
})
|
||||
|
||||
this.client.connection.onMessage(JSON.stringify(rippled.streams.manifest))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user