Skip to content

Commit cb6de88

Browse files
author
Karl Ranna
committed
test(orderbook): add integration tests for stampOwnOrder
1 parent d59d3d2 commit cb6de88

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Diff for: test/integration/OrderBook.spec.ts

+41
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,47 @@ describe('nomatching OrderBook', () => {
210210
expect(() => orderBook['removeOwnOrder'](remainingOrder!.id, order.pairId, 1)).to.throw;
211211
});
212212

213+
describe('stampOwnOrder', () => {
214+
const ownOrder = () => {
215+
return {
216+
pairId: 'LTC/BTC',
217+
price: 0.008,
218+
quantity: 0.00001,
219+
isBuy: false,
220+
localId: '',
221+
hold: 0,
222+
};
223+
};
224+
225+
it('has the same id and localId when localId not provided', async () => {
226+
const stampedOrder = orderBook['stampOwnOrder'](ownOrder());
227+
expect(stampedOrder.id).to.equal(stampedOrder.localId);
228+
});
229+
230+
it('does not have the same id and localId when localId provided', async () => {
231+
const ownOrderWithLocalId = {
232+
...ownOrder(),
233+
localId: uuidv1(),
234+
};
235+
const stampedOrder = orderBook['stampOwnOrder'](ownOrderWithLocalId);
236+
expect(stampedOrder.id).to.not.equal(stampedOrder.localId);
237+
});
238+
239+
it('throws an error when duplicate localId exists', async () => {
240+
const ownOrderWithLocalId = {
241+
...ownOrder(),
242+
localId: uuidv1(),
243+
};
244+
orderBook['localIdMap'].set(ownOrderWithLocalId.localId, {
245+
id: ownOrderWithLocalId.localId,
246+
pairId: ownOrderWithLocalId.pairId,
247+
});
248+
expect(() => orderBook['stampOwnOrder'](ownOrderWithLocalId))
249+
.to.throw(`order with local id ${ownOrderWithLocalId.localId} already exists`);
250+
});
251+
252+
});
253+
213254
after(async () => {
214255
await db.close();
215256
});

0 commit comments

Comments
 (0)