8
8
} from '../lib/constants'
9
9
10
10
test ( 'return the initial state' , ( ) => {
11
- const actual = reducer ( undefined , { } )
11
+ const actual = reducer ( undefined , { type : 'whatever' , payload : { timestamp : 0 } } )
12
12
const expected = {
13
13
cash : new Decimal ( 0 ) ,
14
14
commission : new Decimal ( 0 ) ,
@@ -77,7 +77,8 @@ test(`${ORDER_PLACED} of a sell-side order correctly edits reservedCash`, () =>
77
77
identifier : 'MSFT' ,
78
78
quantity : new Decimal ( - 50 ) ,
79
79
price : new Decimal ( 110 ) ,
80
- commission : new Decimal ( 5.5 )
80
+ commission : new Decimal ( 5.5 ) ,
81
+ timestamp : 0
81
82
}
82
83
const action = { type : ORDER_PLACED , payload : order }
83
84
@@ -98,12 +99,13 @@ test(`${ORDER_PLACED} of a buy-side order correctly edits cash, commission and r
98
99
identifier : 'MSFT' ,
99
100
quantity : new Decimal ( 100 ) ,
100
101
price : new Decimal ( 100 ) ,
101
- commission : new Decimal ( 10 )
102
+ commission : new Decimal ( 10 ) ,
103
+ timestamp : 0
102
104
}
103
105
const action = { type : ORDER_PLACED , payload : order }
104
106
105
107
const actual = reducer ( undefined , action )
106
- const expected = Object . assign ( reducer ( undefined , { } ) , {
108
+ const expected = Object . assign ( reducer ( undefined , { type : 'whatever' , payload : { timestamp : 0 } } ) , {
107
109
reservedCash : new Decimal ( 10010 ) ,
108
110
cash : new Decimal ( - 10010 ) ,
109
111
commission : new Decimal ( 0 ) ,
@@ -119,40 +121,46 @@ test(`${ORDER_CANCELLED} of a sell-side order does not modify anything`, () => {
119
121
identifier : 'MSFT' ,
120
122
quantity : new Decimal ( - 50 ) ,
121
123
price : new Decimal ( 110 ) ,
122
- commission : new Decimal ( 5.5 )
124
+ commission : new Decimal ( 5.5 ) ,
125
+ timestamp : 0
123
126
}
124
127
const action = { type : ORDER_CANCELLED , payload : order }
125
128
126
129
const actual = reducer ( undefined , action )
127
- const expected = reducer ( undefined , { } )
130
+ const expected = reducer ( undefined , { type : 'whatever' , payload : { timestamp : 0 } } )
128
131
129
132
expect ( actual ) . toEqual ( expected )
130
133
} )
131
134
132
- test ( `${ ORDER_CANCELLED } of a buy-side order correctly reverts cash and reservedCash, also doesn't change commission or total` , ( ) => {
133
- const order = {
134
- id : '0' ,
135
- identifier : 'MSFT' ,
136
- quantity : new Decimal ( 100 ) ,
137
- price : new Decimal ( 100 ) ,
138
- commission : new Decimal ( 10 )
139
- }
140
- const action = { type : ORDER_CANCELLED , payload : order }
141
- const initialState = {
142
- cash : 0 ,
143
- reservedCash : 10010 ,
144
- commission : 0 ,
145
- total : 0
146
- }
135
+ test (
136
+ `${ ORDER_CANCELLED } of a buy-side order correctly reverts cash and reservedCash,
137
+ also doesn't change commission or total` ,
138
+ ( ) => {
139
+ const order = {
140
+ id : '0' ,
141
+ identifier : 'MSFT' ,
142
+ quantity : new Decimal ( 100 ) ,
143
+ price : new Decimal ( 100 ) ,
144
+ commission : new Decimal ( 10 ) ,
145
+ timestamp : 0
146
+ }
147
+ const action = { type : ORDER_CANCELLED , payload : order }
148
+ const initialState = {
149
+ cash : new Decimal ( 0 ) ,
150
+ reservedCash : new Decimal ( 10010 ) ,
151
+ commission : new Decimal ( 0 ) ,
152
+ total : new Decimal ( 0 )
153
+ }
147
154
148
- const actual = reducer ( initialState , action )
149
- const expected = Object . assign ( reducer ( initialState , { } ) , {
150
- cash : new Decimal ( 10010 ) ,
151
- reservedCash : new Decimal ( 0 )
152
- } )
155
+ const actual = reducer ( initialState , action )
156
+ const expected = Object . assign ( reducer ( initialState , { type : 'whatever' , payload : { timestamp : 0 } } ) , {
157
+ cash : new Decimal ( 10010 ) ,
158
+ reservedCash : new Decimal ( 0 )
159
+ } )
153
160
154
- expect ( actual ) . toEqual ( expected )
155
- } )
161
+ expect ( actual ) . toEqual ( expected )
162
+ }
163
+ )
156
164
157
165
test ( `${ ORDER_FILLED } , sell-side, should increase cash and commission, and decrease reservedCash` , ( ) => {
158
166
const placedOrder = {
@@ -164,7 +172,7 @@ test(`${ORDER_FILLED}, sell-side, should increase cash and commission, and decre
164
172
timestamp : new Decimal ( 100 )
165
173
}
166
174
const filledOrder = { ...placedOrder }
167
- const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder } }
175
+ const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder, timestamp : 0 } }
168
176
const initialState = {
169
177
cash : new Decimal ( - 10 ) ,
170
178
reservedCash : new Decimal ( 10 ) ,
@@ -193,7 +201,7 @@ test(`${ORDER_FILLED}, buy-side, should increase commission and decrease reserve
193
201
timestamp : 100
194
202
}
195
203
const filledOrder = { ...placedOrder }
196
- const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder } }
204
+ const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder, timestamp : 0 } }
197
205
const initialState = {
198
206
cash : new Decimal ( 0 ) ,
199
207
reservedCash : new Decimal ( 10010 ) ,
@@ -226,7 +234,7 @@ test(`${ORDER_FILLED}, buy-side, partial fill, should increase commission and de
226
234
quantity : new Decimal ( 50 ) ,
227
235
commission : new Decimal ( 5 )
228
236
}
229
- const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder } }
237
+ const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder, timestamp : 0 } }
230
238
const initialState = {
231
239
cash : new Decimal ( 0 ) ,
232
240
reservedCash : new Decimal ( 10010 ) ,
@@ -259,7 +267,7 @@ test(`${ORDER_FILLED}, sell-side, partial fill, increase cash and commission, an
259
267
quantity : new Decimal ( - 50 ) ,
260
268
commission : new Decimal ( 5 )
261
269
}
262
- const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder } }
270
+ const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder, timestamp : 0 } }
263
271
const initialState = {
264
272
cash : new Decimal ( - 10 ) ,
265
273
reservedCash : new Decimal ( 10 ) ,
@@ -293,7 +301,7 @@ test(`${ORDER_FILLED}, buy-side, better price, should increase commission and de
293
301
price : new Decimal ( 90 ) ,
294
302
commission : new Decimal ( 9 ) ,
295
303
}
296
- const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder } }
304
+ const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder, timestamp : 0 } }
297
305
const initialState = {
298
306
cash : new Decimal ( 0 ) ,
299
307
reservedCash : new Decimal ( 10010 ) ,
@@ -327,7 +335,7 @@ test(`${ORDER_FILLED}, sell-side, better price, increase cash and commission, an
327
335
price : new Decimal ( 110 ) ,
328
336
commission : new Decimal ( 11 ) ,
329
337
}
330
- const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder } }
338
+ const action = { type : ORDER_FILLED , payload : { placedOrder, filledOrder, timestamp : 0 } }
331
339
const initialState = {
332
340
cash : new Decimal ( - 10 ) ,
333
341
reservedCash : new Decimal ( 10 ) ,
0 commit comments