From a4b6112a311332df2c00799857463a646df78e25 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 25 May 2018 16:08:15 -0700 Subject: Consolidate back to one channel and expose only the factory --- .../test/browser_ws_orderbook_channel_test.ts | 63 ---------------------- .../connect/test/node_ws_orderbook_channel_test.ts | 61 --------------------- .../connect/test/orderbook_channel_factory_test.ts | 26 +++++++++ packages/connect/test/ws_orderbook_channel_test.ts | 63 ++++++++++++++++++++++ 4 files changed, 89 insertions(+), 124 deletions(-) delete mode 100644 packages/connect/test/browser_ws_orderbook_channel_test.ts delete mode 100644 packages/connect/test/node_ws_orderbook_channel_test.ts create mode 100644 packages/connect/test/orderbook_channel_factory_test.ts create mode 100644 packages/connect/test/ws_orderbook_channel_test.ts (limited to 'packages/connect/test') diff --git a/packages/connect/test/browser_ws_orderbook_channel_test.ts b/packages/connect/test/browser_ws_orderbook_channel_test.ts deleted file mode 100644 index d6a7af5c0..000000000 --- a/packages/connect/test/browser_ws_orderbook_channel_test.ts +++ /dev/null @@ -1,63 +0,0 @@ -// import * as chai from 'chai'; -// import * as dirtyChai from 'dirty-chai'; -// import * as _ from 'lodash'; -// import 'mocha'; -// import * as WebSocket from 'websocket'; - -// import { BrowserWebSocketOrderbookChannel } from '../src/browser_ws_orderbook_channel'; - -// chai.config.includeStack = true; -// chai.use(dirtyChai); -// const expect = chai.expect; - -// describe('BrowserWebSocketOrderbookChannel', () => { -// const websocketUrl = 'ws://localhost:8080'; -// const client = new WebSocket.w3cwebsocket(websocketUrl); -// const orderbookChannel = new BrowserWebSocketOrderbookChannel(client); -// const subscriptionOpts = { -// baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', -// quoteTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', -// snapshot: true, -// limit: 100, -// }; -// const emptyOrderbookChannelHandler = { -// onSnapshot: () => { -// _.noop(); -// }, -// onUpdate: () => { -// _.noop(); -// }, -// onError: () => { -// _.noop(); -// }, -// onClose: () => { -// _.noop(); -// }, -// }; -// describe('#subscribe', () => { -// it('throws when subscriptionOpts does not conform to schema', () => { -// const badSubscribeCall = orderbookChannel.subscribe.bind( -// orderbookChannel, -// {}, -// emptyOrderbookChannelHandler, -// ); -// expect(badSubscribeCall).throws( -// 'Expected subscriptionOpts to conform to schema /RelayerApiOrderbookChannelSubscribePayload\nEncountered: {}\nValidation errors: instance requires property "baseTokenAddress", instance requires property "quoteTokenAddress"', -// ); -// }); -// it('throws when handler has the incorrect members', () => { -// const badSubscribeCall = orderbookChannel.subscribe.bind(orderbookChannel, subscriptionOpts, {}); -// expect(badSubscribeCall).throws( -// 'Expected handler.onSnapshot to be of type function, encountered: undefined', -// ); -// }); -// it('does not throw when inputs are of correct types', () => { -// const goodSubscribeCall = orderbookChannel.subscribe.bind( -// orderbookChannel, -// subscriptionOpts, -// emptyOrderbookChannelHandler, -// ); -// expect(goodSubscribeCall).to.not.throw(); -// }); -// }); -// }); diff --git a/packages/connect/test/node_ws_orderbook_channel_test.ts b/packages/connect/test/node_ws_orderbook_channel_test.ts deleted file mode 100644 index 5e5325e83..000000000 --- a/packages/connect/test/node_ws_orderbook_channel_test.ts +++ /dev/null @@ -1,61 +0,0 @@ -import * as chai from 'chai'; -import * as dirtyChai from 'dirty-chai'; -import * as _ from 'lodash'; -import 'mocha'; - -import { NodeWebSocketOrderbookChannel } from '../src/node_ws_orderbook_channel'; - -chai.config.includeStack = true; -chai.use(dirtyChai); -const expect = chai.expect; - -describe('NodeWebSocketOrderbookChannel', () => { - const websocketUrl = 'ws://localhost:8080'; - const orderbookChannel = new NodeWebSocketOrderbookChannel(websocketUrl); - const subscriptionOpts = { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - snapshot: true, - limit: 100, - }; - const emptyOrderbookChannelHandler = { - onSnapshot: () => { - _.noop(); - }, - onUpdate: () => { - _.noop(); - }, - onError: () => { - _.noop(); - }, - onClose: () => { - _.noop(); - }, - }; - describe('#subscribe', () => { - it('throws when subscriptionOpts does not conform to schema', () => { - const badSubscribeCall = orderbookChannel.subscribe.bind( - orderbookChannel, - {}, - emptyOrderbookChannelHandler, - ); - expect(badSubscribeCall).throws( - 'Expected subscriptionOpts to conform to schema /RelayerApiOrderbookChannelSubscribePayload\nEncountered: {}\nValidation errors: instance requires property "baseTokenAddress", instance requires property "quoteTokenAddress"', - ); - }); - it('throws when handler has the incorrect members', () => { - const badSubscribeCall = orderbookChannel.subscribe.bind(orderbookChannel, subscriptionOpts, {}); - expect(badSubscribeCall).throws( - 'Expected handler.onSnapshot to be of type function, encountered: undefined', - ); - }); - it('does not throw when inputs are of correct types', () => { - const goodSubscribeCall = orderbookChannel.subscribe.bind( - orderbookChannel, - subscriptionOpts, - emptyOrderbookChannelHandler, - ); - expect(goodSubscribeCall).to.not.throw(); - }); - }); -}); diff --git a/packages/connect/test/orderbook_channel_factory_test.ts b/packages/connect/test/orderbook_channel_factory_test.ts new file mode 100644 index 000000000..fd84332cc --- /dev/null +++ b/packages/connect/test/orderbook_channel_factory_test.ts @@ -0,0 +1,26 @@ +import * as chai from 'chai'; +import * as dirtyChai from 'dirty-chai'; +import * as _ from 'lodash'; +import 'mocha'; +import * as WebSocket from 'websocket'; + +import { orderbookChannelFactory } from '../src/orderbook_channel_factory'; + +chai.config.includeStack = true; +chai.use(dirtyChai); +const expect = chai.expect; + +describe('orderbookChannelFactory', () => { + const websocketUrl = 'ws://localhost:8080'; + + describe('#createWebSocketOrderbookChannelAsync', () => { + it('throws when input is not a url', () => { + const badInput = 54; + const badSubscribeCall = orderbookChannelFactory.createWebSocketOrderbookChannelAsync.bind( + orderbookChannelFactory, + badInput, + ); + expect(orderbookChannelFactory.createWebSocketOrderbookChannelAsync(badInput as any)).to.be.rejected(); + }); + }); +}); diff --git a/packages/connect/test/ws_orderbook_channel_test.ts b/packages/connect/test/ws_orderbook_channel_test.ts new file mode 100644 index 000000000..79100d0e2 --- /dev/null +++ b/packages/connect/test/ws_orderbook_channel_test.ts @@ -0,0 +1,63 @@ +import * as chai from 'chai'; +import * as dirtyChai from 'dirty-chai'; +import * as _ from 'lodash'; +import 'mocha'; +import * as WebSocket from 'websocket'; + +import { WebSocketOrderbookChannel } from '../src/ws_orderbook_channel'; + +chai.config.includeStack = true; +chai.use(dirtyChai); +const expect = chai.expect; + +describe('WebSocketOrderbookChannel', () => { + const websocketUrl = 'ws://localhost:8080'; + const client = new WebSocket.w3cwebsocket(websocketUrl); + const orderbookChannel = new WebSocketOrderbookChannel(client); + const subscriptionOpts = { + baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', + snapshot: true, + limit: 100, + }; + const emptyOrderbookChannelHandler = { + onSnapshot: () => { + _.noop(); + }, + onUpdate: () => { + _.noop(); + }, + onError: () => { + _.noop(); + }, + onClose: () => { + _.noop(); + }, + }; + describe('#subscribe', () => { + it('throws when subscriptionOpts does not conform to schema', () => { + const badSubscribeCall = orderbookChannel.subscribe.bind( + orderbookChannel, + {}, + emptyOrderbookChannelHandler, + ); + expect(badSubscribeCall).throws( + 'Expected subscriptionOpts to conform to schema /RelayerApiOrderbookChannelSubscribePayload\nEncountered: {}\nValidation errors: instance requires property "baseTokenAddress", instance requires property "quoteTokenAddress"', + ); + }); + it('throws when handler has the incorrect members', () => { + const badSubscribeCall = orderbookChannel.subscribe.bind(orderbookChannel, subscriptionOpts, {}); + expect(badSubscribeCall).throws( + 'Expected handler.onSnapshot to be of type function, encountered: undefined', + ); + }); + it('does not throw when inputs are of correct types', () => { + const goodSubscribeCall = orderbookChannel.subscribe.bind( + orderbookChannel, + subscriptionOpts, + emptyOrderbookChannelHandler, + ); + expect(goodSubscribeCall).to.not.throw(); + }); + }); +}); -- cgit v1.2.3