Skip to content

Commit

Permalink
test(orderbook): add integration tests for stampOwnOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl Ranna committed Nov 13, 2018
1 parent 8540623 commit 51ae63e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/integration/OrderBook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,48 @@ describe('nomatching OrderBook', () => {
expect(() => orderBook['removeOwnOrder'](remainingOrder!.id, order.pairId, 1)).to.throw;
});

describe('stampOwnOrder', () => {
const ownOrder = () => {
return {
pairId: 'LTC/BTC',
price: 0.008,
quantity: 0.00001,
isBuy: false,
localId: '',
hold: 0,
};
};

it('has the same id and localId when localId not provided', async () => {
const stampedOrder = orderBook['stampOwnOrder'](ownOrder());
expect(stampedOrder.id).to.equal(stampedOrder.localId);
});

it('has the provided localId', async () => {
const ownOrderWithLocalId = {
...ownOrder(),
localId: uuidv1(),
};
const stampedOrder = orderBook['stampOwnOrder'](ownOrderWithLocalId);
expect(stampedOrder.id).to.not.equal(stampedOrder.localId);
expect(stampedOrder.localId).to.equal(ownOrderWithLocalId.localId);
});

it('throws an error when duplicate localId exists', async () => {
const ownOrderWithLocalId = {
...ownOrder(),
localId: uuidv1(),
};
orderBook['localIdMap'].set(ownOrderWithLocalId.localId, {
id: ownOrderWithLocalId.localId,
pairId: ownOrderWithLocalId.pairId,
});
expect(() => orderBook['stampOwnOrder'](ownOrderWithLocalId))
.to.throw(`order with local id ${ownOrderWithLocalId.localId} already exists`);
});

});

after(async () => {
await db.close();
});
Expand Down

0 comments on commit 51ae63e

Please sign in to comment.