diff options
author | Fabio Berger <me@fabioberger.com> | 2018-08-23 06:46:45 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-08-23 06:46:45 +0800 |
commit | 61255309d2f7e2724d29f58f1c1493a1a87a182c (patch) | |
tree | 33eabfcf58f782fa2ccb070e05a6cd711af2ab29 /packages/connect/test/ws_orderbook_channel_test.ts | |
parent | 27d329ff2559c643b54489d0796bb2c2fcda264f (diff) | |
parent | cb19623a3aaf22a386bd4a7d6477048a604be9a2 (diff) | |
download | dexon-sol-tools-61255309d2f7e2724d29f58f1c1493a1a87a182c.tar dexon-sol-tools-61255309d2f7e2724d29f58f1c1493a1a87a182c.tar.gz dexon-sol-tools-61255309d2f7e2724d29f58f1c1493a1a87a182c.tar.bz2 dexon-sol-tools-61255309d2f7e2724d29f58f1c1493a1a87a182c.tar.lz dexon-sol-tools-61255309d2f7e2724d29f58f1c1493a1a87a182c.tar.xz dexon-sol-tools-61255309d2f7e2724d29f58f1c1493a1a87a182c.tar.zst dexon-sol-tools-61255309d2f7e2724d29f58f1c1493a1a87a182c.zip |
merge development
Diffstat (limited to 'packages/connect/test/ws_orderbook_channel_test.ts')
-rw-r--r-- | packages/connect/test/ws_orderbook_channel_test.ts | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/packages/connect/test/ws_orderbook_channel_test.ts b/packages/connect/test/ws_orderbook_channel_test.ts deleted file mode 100644 index 5a63cbdcc..000000000 --- a/packages/connect/test/ws_orderbook_channel_test.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as chai from 'chai'; -import * as dirtyChai from 'dirty-chai'; -import * as _ from 'lodash'; -import 'mocha'; -import * as Sinon from 'sinon'; -import * as WebSocket from 'websocket'; - -import { WebSocketOrderbookChannel } from '../src/ws_orderbook_channel'; - -chai.config.includeStack = true; -chai.use(dirtyChai); -const expect = chai.expect; -const emptyOrderbookChannelHandler = { - onSnapshot: () => { - _.noop(); - }, - onUpdate: () => { - _.noop(); - }, - onError: () => { - _.noop(); - }, - onClose: () => { - _.noop(); - }, -}; - -describe('WebSocketOrderbookChannel', () => { - const websocketUrl = 'ws://localhost:8080'; - const openClient = new WebSocket.w3cwebsocket(websocketUrl); - Sinon.stub(openClient, 'readyState').get(() => WebSocket.w3cwebsocket.OPEN); - Sinon.stub(openClient, 'send').callsFake(_.noop.bind(_)); - const openOrderbookChannel = new WebSocketOrderbookChannel(openClient, emptyOrderbookChannelHandler); - const subscriptionOpts = { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - snapshot: true, - limit: 100, - }; - describe('#subscribe', () => { - it('throws when subscriptionOpts does not conform to schema', () => { - const badSubscribeCall = openOrderbookChannel.subscribe.bind(openOrderbookChannel, {}); - expect(badSubscribeCall).throws( - 'Expected subscriptionOpts to conform to schema /RelayerApiOrderbookChannelSubscribePayload\nEncountered: {}\nValidation errors: instance requires property "baseTokenAddress", instance requires property "quoteTokenAddress"', - ); - }); - it('does not throw when inputs are of correct types', () => { - const goodSubscribeCall = openOrderbookChannel.subscribe.bind(openOrderbookChannel, subscriptionOpts); - expect(goodSubscribeCall).to.not.throw(); - }); - it('throws when client is closed', () => { - const closedClient = new WebSocket.w3cwebsocket(websocketUrl); - Sinon.stub(closedClient, 'readyState').get(() => WebSocket.w3cwebsocket.CLOSED); - const closedOrderbookChannel = new WebSocketOrderbookChannel(closedClient, emptyOrderbookChannelHandler); - const badSubscribeCall = closedOrderbookChannel.subscribe.bind(closedOrderbookChannel, subscriptionOpts); - expect(badSubscribeCall).throws('WebSocket connection is closed'); - }); - }); -}); |