Skip to content

Commit

Permalink
#633 Fix tests:
Browse files Browse the repository at this point in the history
 - change BID and ASK constants
  • Loading branch information
priecint committed Aug 8, 2016
1 parent 6a8abc5 commit d09742a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
5 changes: 2 additions & 3 deletions src/modules/bids-asks/actions/cancel-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { updateExistingTransaction } from '../../transactions/actions/update-exi
import { loadBidsAsks } from '../../bids-asks/actions/load-bids-asks';
import getOrder from '../../bids-asks/helpers/get-order';
import * as augurJS from '../../../services/augurjs';
import { BID } from "../constants/bids-asks-types";
import { CANCELLED, CANCELLING, CANCELLATION_FAILED } from '../../bids-asks/constants/order-status';
import { CANCELLING_ORDER, SUCCESS, FAILED } from '../../transactions/constants/statuses';

Expand All @@ -19,7 +18,7 @@ export const ABORT_CANCEL_ORDER_CONFIRMATION = 'ABORT_CANCEL_ORDER_CONFIRMATION'
export function cancelOrder(orderID, marketID, type) {
return (dispatch, getState) => {
const { marketOrderBooks, outcomesData, marketsData } = getState();
const order = getOrder(orderID, marketID, type === BID ? 'buy' : 'sell', marketOrderBooks);
const order = getOrder(orderID, marketID, type, marketOrderBooks);
const market = marketsData[marketID];

if (order == null || market == null || outcomesData[marketID] == null) {
Expand All @@ -31,7 +30,7 @@ export function cancelOrder(orderID, marketID, type) {
return;
}

dispatch(addCancelTransaction(order, { ...market, id:marketID }, outcome));
dispatch(addCancelTransaction(order, { ...market, id: marketID }, outcome));
};
}

Expand Down
7 changes: 3 additions & 4 deletions src/modules/bids-asks/actions/update-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Author: priecint
*/
import getOrder from '../../bids-asks/helpers/get-order';
import { BID } from '../../bids-asks/constants/bids-asks-types';
import store from '../../../store';

export const UPDATE_ORDER_STATUS = 'UPDATE_ORDER_STATUS';
Expand All @@ -24,14 +23,14 @@ export function updateOrderStatus(orderID, status, marketID, type) {
return;
}

dispatch ({
dispatch({
type: UPDATE_ORDER_STATUS,
orderID,
status,
marketID,
orderType: type === BID ? 'buy' : 'sell'
orderType: type
});
}
};
}

function warnNonExistingOrder(orderID, status, marketID, type) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/bids-asks/constants/bids-asks-types.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const BID = 'bid';
export const ASK = 'ask';
export const BID = 'buy';
export const ASK = 'sell';
10 changes: 5 additions & 5 deletions test/bids-asks/actions/cancel-order-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe('modules/bids-asks/actions/cancel-order.js', () => {
cancelTxn: {
type: CANCEL_ORDER,
data: {
order: { id: 'orderID', type: 'buy'},
market: {id: 'marketID'},
order: { id: '0xdbd851cc394595f9c50f32c1554059ec343471b49f84a4b72c44589a25f70ff3', type: BID },
market: { id: 'testMarketID' },
outcome: {}
}
}
Expand Down Expand Up @@ -74,12 +74,12 @@ describe('modules/bids-asks/actions/cancel-order.js', () => {
});

it('should call actions and then augurJS', () => {
store.dispatch(cancelOrderModule.processCancelOrder('cancelTxn', 'orderID'));
store.dispatch(cancelOrderModule.processCancelOrder('cancelTxn', '0xdbd851cc394595f9c50f32c1554059ec343471b49f84a4b72c44589a25f70ff3'));

assert.deepEqual(updateOrderStatus.args[0], ['orderID', CANCELLING, 'marketID', BID]);
assert.deepEqual(updateOrderStatus.args[0], ['0xdbd851cc394595f9c50f32c1554059ec343471b49f84a4b72c44589a25f70ff3', CANCELLING, 'testMarketID', BID]);
assert.deepEqual(updateExistingTransaction.args[0], ['cancelTxn', { status: CANCELLING_ORDER }]);
assert.lengthOf(cancel.args[0], 5);
assert.equal(cancel.args[0][0], 'orderID');
assert.equal(cancel.args[0][0], '0xdbd851cc394595f9c50f32c1554059ec343471b49f84a4b72c44589a25f70ff3');
});
});

Expand Down
20 changes: 8 additions & 12 deletions test/bids-asks/actions/update-order-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,39 @@
*/
import { assert } from 'chai';
import proxyquire from 'proxyquire';
import sinon from 'sinon';
import mocks from '../../mockStore';
import { CANCELLING } from '../../../src/modules/bids-asks/constants/order-status';
import { BID } from '../../../src/modules/bids-asks/constants/bids-asks-types';


describe('modules/bids-asks/actions/update-order.js', () => {
proxyquire.noPreserveCache().noCallThru();
const store = mocks.mockStore(mocks.state);
const dispatch = sinon.stub(store, 'dispatch');
const updateOrderModule = proxyquire('../../../src/modules/bids-asks/actions/update-order', {
'../../../store': store
});

afterEach(() => {
dispatch.reset();
store.clearActions();
});

describe('updateOrderStatus', () => {
it(`shouldn't dispatch if order cannot be found`, () => {
dispatch(updateOrderModule.updateOrderStatus('nonExistingOrderID', CANCELLING, 'marketID', BID));
assert.strictEqual(dispatch.callCount, 1);
store.dispatch(updateOrderModule.updateOrderStatus('nonExistingOrderID', CANCELLING, 'marketID', BID));
assert.lengthOf(store.getActions(), 0);

dispatch(updateOrderModule.updateOrderStatus('orderID', CANCELLING, 'nonExistingMarketID', BID));
assert.strictEqual(dispatch.callCount, 2);
store.dispatch(updateOrderModule.updateOrderStatus('orderID', CANCELLING, 'nonExistingMarketID', BID));
assert.lengthOf(store.getActions(), 0);
});

it(`should dispatch action`, () => {
dispatch(updateOrderModule.updateOrderStatus('0xdbd851cc394595f9c50f32c1554059ec343471b49f84a4b72c44589a25f70ff3', CANCELLING, 'testMarketID', BID));
assert.isTrue(dispatch.calledOnce);
assert.deepEqual(dispatch.args[0], [{
store.dispatch(updateOrderModule.updateOrderStatus('0xdbd851cc394595f9c50f32c1554059ec343471b49f84a4b72c44589a25f70ff3', CANCELLING, 'testMarketID', BID));

assert.deepEqual(store.getActions(), [{
type: updateOrderModule.UPDATE_ORDER_STATUS,
orderID: '0xdbd851cc394595f9c50f32c1554059ec343471b49f84a4b72c44589a25f70ff3',
status: CANCELLING,
marketID: 'testMarketID',
orderType: 'buy'
orderType: BID
}]);
});
});
Expand Down

0 comments on commit d09742a

Please sign in to comment.