aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/test/orderbook_channel_factory_test.ts
blob: 2ce361bd244318def7f6af09ad014fc465e66337 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as chai from 'chai';
import * as dirtyChai from 'dirty-chai';
import * as _ from 'lodash';
import 'mocha';

import { orderbookChannelFactory } from '../src/orderbook_channel_factory';

chai.config.includeStack = true;
chai.use(dirtyChai);
const expect = chai.expect;
const emptyOrderbookChannelHandler = {
    onSnapshot: () => {
        _.noop();
    },
    onUpdate: () => {
        _.noop();
    },
    onError: () => {
        _.noop();
    },
    onClose: () => {
        _.noop();
    },
};

describe('orderbookChannelFactory', () => {
    const websocketUrl = 'ws://localhost:8080';
    describe('#createWebSocketOrderbookChannelAsync', () => {
        it('throws when input is not a url', () => {
            const badUrlInput = 54;
            expect(
                orderbookChannelFactory.createWebSocketOrderbookChannelAsync(
                    badUrlInput as any,
                    emptyOrderbookChannelHandler,
                ),
            ).to.be.rejected();
        });
        it('throws when handler has the incorrect members', () => {
            const badHandlerInput = {};
            expect(
                orderbookChannelFactory.createWebSocketOrderbookChannelAsync(websocketUrl, badHandlerInput as any),
            ).to.be.rejected();
        });
    });
});