aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/test
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-05-17 02:15:02 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-07-12 01:17:45 +0800
commit16ddd1edfccdd7768447bfff9afec1f4a1ce014e (patch)
treeac4209c77775a1b7c326204c0f7d49b9fcab7bff /packages/connect/test
parent8fcc7aefa7651311c5a6348101eb023d28799934 (diff)
downloaddexon-sol-tools-16ddd1edfccdd7768447bfff9afec1f4a1ce014e.tar
dexon-sol-tools-16ddd1edfccdd7768447bfff9afec1f4a1ce014e.tar.gz
dexon-sol-tools-16ddd1edfccdd7768447bfff9afec1f4a1ce014e.tar.bz2
dexon-sol-tools-16ddd1edfccdd7768447bfff9afec1f4a1ce014e.tar.lz
dexon-sol-tools-16ddd1edfccdd7768447bfff9afec1f4a1ce014e.tar.xz
dexon-sol-tools-16ddd1edfccdd7768447bfff9afec1f4a1ce014e.tar.zst
dexon-sol-tools-16ddd1edfccdd7768447bfff9afec1f4a1ce014e.zip
Implement web browser socket
Diffstat (limited to 'packages/connect/test')
-rw-r--r--packages/connect/test/browser_ws_orderbook_channel_test.ts61
-rw-r--r--packages/connect/test/node_ws_orderbook_channel_test.ts (renamed from packages/connect/test/ws_orderbook_channel_test.ts)6
2 files changed, 64 insertions, 3 deletions
diff --git a/packages/connect/test/browser_ws_orderbook_channel_test.ts b/packages/connect/test/browser_ws_orderbook_channel_test.ts
new file mode 100644
index 000000000..2941f7086
--- /dev/null
+++ b/packages/connect/test/browser_ws_orderbook_channel_test.ts
@@ -0,0 +1,61 @@
+import * as chai from 'chai';
+import * as dirtyChai from 'dirty-chai';
+import * as _ from 'lodash';
+import 'mocha';
+
+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 orderbookChannel = new BrowserWebSocketOrderbookChannel(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/ws_orderbook_channel_test.ts b/packages/connect/test/node_ws_orderbook_channel_test.ts
index ce404d934..5e5325e83 100644
--- a/packages/connect/test/ws_orderbook_channel_test.ts
+++ b/packages/connect/test/node_ws_orderbook_channel_test.ts
@@ -3,15 +3,15 @@ import * as dirtyChai from 'dirty-chai';
import * as _ from 'lodash';
import 'mocha';
-import { WebSocketOrderbookChannel } from '../src/ws_orderbook_channel';
+import { NodeWebSocketOrderbookChannel } from '../src/node_ws_orderbook_channel';
chai.config.includeStack = true;
chai.use(dirtyChai);
const expect = chai.expect;
-describe('WebSocketOrderbookChannel', () => {
+describe('NodeWebSocketOrderbookChannel', () => {
const websocketUrl = 'ws://localhost:8080';
- const orderbookChannel = new WebSocketOrderbookChannel(websocketUrl);
+ const orderbookChannel = new NodeWebSocketOrderbookChannel(websocketUrl);
const subscriptionOpts = {
baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d',
quoteTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990',