it('passes a debugger to the example', (done) => { runExample(getRunArgs(), async (args) => { assert.ok(_isObject(args), 'example not passed a tooling object') assert.ok(_isFunction(args.debug), 'example not passed a debug() instance') done() }) })
it('enableFlag: sends conf packet if open', async () => { ws = createTestWSv2Instance() wss = new MockWSv2Server() await ws.open() return new Promise((resolve) => { ws.send = (packet) => { assert(_isObject(packet)) assert.strictEqual(packet.event, 'conf') resolve() } ws.enableFlag(WSv2.flags.SEQ_ALL) }) })
describe('subscribeOrderBook', () => { it('calls subscribe with a valid filter and the provided symbol', (done) => { m = new WS2Manager() m.subscribe = (type, symbol, filter) => { assert.ok(_isObject(filter), 'filter not an object') assert.strictEqual(filter.symbol, 'tBTCUSD', 'symbol did not match') assert.strictEqual(filter.prec, 'P0', 'prec did not match') assert.strictEqual(filter.len, '25', 'len did not match') assert.strictEqual(filter.freq, 'F0', 'freq did not match') assert.strictEqual(symbol, 'tBTCUSD') done() } m.subscribeOrderBook('tBTCUSD', 'P0', '25', 'F0') }) })
it('notifyUI: sends the correct UCM broadcast notification', (done) => { ws = createTestWSv2Instance() ws._isOpen = true ws._isAuthenticated = true ws.send = (msg = []) => { assert.deepStrictEqual(msg[0], 0) assert.deepStrictEqual(msg[1], 'n') assert.deepStrictEqual(msg[2], null) const data = msg[3] assert(_isObject(data)) assert.deepStrictEqual(data.type, 'ucm-notify-ui') assert(_isObject(data.info)) assert.deepStrictEqual(data.info.type, 'success') assert.deepStrictEqual(data.info.message, '42') done() } ws.notifyUI({ type: 'success', message: '42' }) })
describe('getSocketInfo', () => { it('returns an array of objects reporting number of data channels per socket', () => { m = new WS2Manager() m._sockets.push({ pendingSubscriptions: [[], [], []], pendingUnsubscriptions: [[]], ws: { getDataChannelCount: () => 2 } }) m._sockets.push({ pendingSubscriptions: [[], [], []], pendingUnsubscriptions: [[]], ws: { getDataChannelCount: () => 3 } }) const info = m.getSocketInfo() assert.ok(_isArray(info), 'did not return array') info.forEach(i => assert.ok(_isObject(i), 'socket info not an object')) assert.strictEqual(info[0].nChannels, 4, 'socket info does not report correct number of channels') assert.strictEqual(info[1].nChannels, 5, 'socket info does not report correct number of channels') }) })
const initAuthArgs = ws.getAuthArgs() assert(_isObject(initAuthArgs) && _isEmpty(initAuthArgs)) })
assert.ok(_isObject(args), 'did not return an object') assert(_isUndefined(args.apiKey), 'api key parsed although not present on env') assert(_isUndefined(args.apiSecret), 'api secret parsed although not present on env') assert.ok(_isObject(args), 'did not return an object') assert.strictEqual(args.apiKey, '42', 'api key not pulled from env') assert.strictEqual(args.apiSecret, '9000', 'api secret not pull from env') assert.ok(_isObject(args), 'did not return an object') assert.ok(_isUndefined(args.agent), 'agent provided although no config on env') assert.ok(_isObject(args), 'did not return an object') assert.ok(args.agent instanceof SocksProxyAgent, 'did not provide a SocksProxyAgent instance') assert.ok(/localhost/.test(args.agent.proxy.host), 'provided agent does not use proxy url from env') assert.ok(_isObject(args), 'did not return an object') assert.ok(_isUndefined(args.url), 'url provided although no config on env') assert.ok(_isObject(args), 'did not return an object') assert.ok(_isString(args.url) && !_isEmpty(args.url), 'connection url not pulled from env') assert.strictEqual(args.url, url, 'provided url does not match env var')
describe('onOrderBook', () => { it('passes a valid OB filter to the first socket with a book channel', (done) => { const assertFilter = (filter) => { assert.ok(_isObject(filter), 'filter not an object') assert.strictEqual(filter.symbol, 'tBTCUSD', 'symbol did not match') assert.strictEqual(filter.prec, 'P0', 'prec did not match')
describe('getSocketWithSubRef', () => { it('returns the first socket found that has the requested subscription ref', () => { m = new WS2Manager() for (let i = 0; i < 3; i += 1) { m._sockets.push({ test: i, ws: { hasSubscriptionRef: (channel, identifier) => { assert.strictEqual(channel, 'a', 'did not pass channel through') assert.strictEqual(identifier, 'b', 'did not pass identifier through') return i === 1 } } }) } const s = m.getSocketWithSubRef('a', 'b') assert.ok(_isObject(s), 'did not return a socket') assert.strictEqual(s.test, 1, 'did not return correct socket') }) })
it('passes a specialized table logging function to the example', (done) => { runExample(getRunArgs(), async (args) => { assert.ok(_isObject(args), 'example not passed a tooling object') assert.ok(_isFunction(args.debugTable), 'example not passed a debugTable() instance') done() }) })