aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/test
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2017-12-20 06:22:38 +0800
committerBrandon Millman <brandon.millman@gmail.com>2017-12-25 10:01:28 +0800
commit8fe81c9d090ce50496f3150602f19433e7aedd1e (patch)
tree7e569cf16cd3a9ad9b09b5e64c5101d0c477f8fe /packages/connect/test
parent9f3acf8e2888b6105062e47664ecd5adaaf3c889 (diff)
downloaddexon-sol-tools-8fe81c9d090ce50496f3150602f19433e7aedd1e.tar
dexon-sol-tools-8fe81c9d090ce50496f3150602f19433e7aedd1e.tar.gz
dexon-sol-tools-8fe81c9d090ce50496f3150602f19433e7aedd1e.tar.bz2
dexon-sol-tools-8fe81c9d090ce50496f3150602f19433e7aedd1e.tar.lz
dexon-sol-tools-8fe81c9d090ce50496f3150602f19433e7aedd1e.tar.xz
dexon-sol-tools-8fe81c9d090ce50496f3150602f19433e7aedd1e.tar.zst
dexon-sol-tools-8fe81c9d090ce50496f3150602f19433e7aedd1e.zip
Refactor JSON parsing in HttpClient
Diffstat (limited to 'packages/connect/test')
-rw-r--r--packages/connect/test/orderbook_channel_message_parsers_test.ts20
1 files changed, 10 insertions, 10 deletions
diff --git a/packages/connect/test/orderbook_channel_message_parsers_test.ts b/packages/connect/test/orderbook_channel_message_parsers_test.ts
index 2c776b095..65286f87b 100644
--- a/packages/connect/test/orderbook_channel_message_parsers_test.ts
+++ b/packages/connect/test/orderbook_channel_message_parsers_test.ts
@@ -2,7 +2,7 @@ import * as chai from 'chai';
import * as dirtyChai from 'dirty-chai';
import 'mocha';
-import {orderbookChannelMessageParsers} from '../src/utils/orderbook_channel_message_parsers';
+import {orderbookChannelMessageParser} from '../src/utils/orderbook_channel_message_parser';
// tslint:disable-next-line:max-line-length
import {orderResponse} from './fixtures/standard_relayer_api/order/0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f';
@@ -21,20 +21,20 @@ chai.config.includeStack = true;
chai.use(dirtyChai);
const expect = chai.expect;
-describe('orderbookChannelMessageParsers', () => {
+describe('orderbookChannelMessageParser', () => {
describe('#parser', () => {
it('parses snapshot messages', () => {
- const snapshotMessage = orderbookChannelMessageParsers.parser(snapshotOrderbookChannelMessage);
+ const snapshotMessage = orderbookChannelMessageParser.parse(snapshotOrderbookChannelMessage);
expect(snapshotMessage.type).to.be.equal('snapshot');
expect(snapshotMessage.payload).to.be.deep.equal(orderbookResponse);
});
it('parses update messages', () => {
- const updateMessage = orderbookChannelMessageParsers.parser(updateOrderbookChannelMessage);
+ const updateMessage = orderbookChannelMessageParser.parse(updateOrderbookChannelMessage);
expect(updateMessage.type).to.be.equal('update');
expect(updateMessage.payload).to.be.deep.equal(orderResponse);
});
it('returns unknown message for messages with unsupported types', () => {
- const unknownMessage = orderbookChannelMessageParsers.parser(unknownOrderbookChannelMessage);
+ const unknownMessage = orderbookChannelMessageParser.parse(unknownOrderbookChannelMessage);
expect(unknownMessage.type).to.be.equal('unknown');
expect(unknownMessage.payload).to.be.undefined();
});
@@ -44,7 +44,7 @@ describe('orderbookChannelMessageParsers', () => {
"requestId": 1,
"payload": {}
}`;
- const badCall = () => orderbookChannelMessageParsers.parser(typelessMessage);
+ const badCall = () => orderbookChannelMessageParser.parse(typelessMessage);
expect(badCall).throws(`Message is missing a type parameter: ${typelessMessage}`);
});
it('throws when type is not a string', () => {
@@ -54,24 +54,24 @@ describe('orderbookChannelMessageParsers', () => {
"requestId": 1,
"payload": {}
}`;
- const badCall = () => orderbookChannelMessageParsers.parser(messageWithBadType);
+ const badCall = () => orderbookChannelMessageParser.parse(messageWithBadType);
expect(badCall).throws('Expected type to be of type string, encountered: 1');
});
it('throws when snapshot message has malformed payload', () => {
const badCall = () =>
- orderbookChannelMessageParsers.parser(malformedSnapshotOrderbookChannelMessage);
+ orderbookChannelMessageParser.parse(malformedSnapshotOrderbookChannelMessage);
// tslint:disable-next-line:max-line-length
const errMsg = 'Validation errors: instance.payload requires property "bids", instance.payload requires property "asks"';
expect(badCall).throws(errMsg);
});
it('throws when update message has malformed payload', () => {
const badCall = () =>
- orderbookChannelMessageParsers.parser(malformedUpdateOrderbookChannelMessage);
+ orderbookChannelMessageParser.parse(malformedUpdateOrderbookChannelMessage);
expect(badCall).throws(/^Expected message to conform to schema/);
});
it('throws when input message is not valid JSON', () => {
const nonJsonString = 'h93b{sdfs9fsd f';
- const badCall = () => orderbookChannelMessageParsers.parser(nonJsonString);
+ const badCall = () => orderbookChannelMessageParser.parse(nonJsonString);
expect(badCall).throws('Unexpected token h in JSON at position 0');
});
});