Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

Commit 0c15cac

Browse files
committed
Added type checking to tests
1 parent 7e6362b commit 0c15cac

16 files changed

+1755
-1395
lines changed

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"semi": false
3+
}

__tests__/capitalReducer.spec.ts

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '../lib/constants'
99

1010
test('return the initial state', () => {
11-
const actual = reducer(undefined, {})
11+
const actual = reducer(undefined, { type: 'whatever', payload: { timestamp: 0 } })
1212
const expected = {
1313
cash: new Decimal(0),
1414
commission: new Decimal(0),
@@ -77,7 +77,8 @@ test(`${ORDER_PLACED} of a sell-side order correctly edits reservedCash`, () =>
7777
identifier: 'MSFT',
7878
quantity: new Decimal(-50),
7979
price: new Decimal(110),
80-
commission: new Decimal(5.5)
80+
commission: new Decimal(5.5),
81+
timestamp: 0
8182
}
8283
const action = { type: ORDER_PLACED, payload: order }
8384

@@ -98,12 +99,13 @@ test(`${ORDER_PLACED} of a buy-side order correctly edits cash, commission and r
9899
identifier: 'MSFT',
99100
quantity: new Decimal(100),
100101
price: new Decimal(100),
101-
commission: new Decimal(10)
102+
commission: new Decimal(10),
103+
timestamp: 0
102104
}
103105
const action = { type: ORDER_PLACED, payload: order }
104106

105107
const actual = reducer(undefined, action)
106-
const expected = Object.assign(reducer(undefined, {}), {
108+
const expected = Object.assign(reducer(undefined, { type: 'whatever', payload: { timestamp: 0 } }), {
107109
reservedCash: new Decimal(10010),
108110
cash: new Decimal(-10010),
109111
commission: new Decimal(0),
@@ -119,40 +121,46 @@ test(`${ORDER_CANCELLED} of a sell-side order does not modify anything`, () => {
119121
identifier: 'MSFT',
120122
quantity: new Decimal(-50),
121123
price: new Decimal(110),
122-
commission: new Decimal(5.5)
124+
commission: new Decimal(5.5),
125+
timestamp: 0
123126
}
124127
const action = { type: ORDER_CANCELLED, payload: order }
125128

126129
const actual = reducer(undefined, action)
127-
const expected = reducer(undefined, {})
130+
const expected = reducer(undefined, { type: 'whatever', payload: { timestamp: 0 } })
128131

129132
expect(actual).toEqual(expected)
130133
})
131134

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+
}
147154

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+
})
153160

154-
expect(actual).toEqual(expected)
155-
})
161+
expect(actual).toEqual(expected)
162+
}
163+
)
156164

157165
test(`${ORDER_FILLED}, sell-side, should increase cash and commission, and decrease reservedCash`, () => {
158166
const placedOrder = {
@@ -164,7 +172,7 @@ test(`${ORDER_FILLED}, sell-side, should increase cash and commission, and decre
164172
timestamp: new Decimal(100)
165173
}
166174
const filledOrder = { ...placedOrder }
167-
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder } }
175+
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder, timestamp: 0 } }
168176
const initialState = {
169177
cash: new Decimal(-10),
170178
reservedCash: new Decimal(10),
@@ -193,7 +201,7 @@ test(`${ORDER_FILLED}, buy-side, should increase commission and decrease reserve
193201
timestamp: 100
194202
}
195203
const filledOrder = { ...placedOrder }
196-
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder } }
204+
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder, timestamp: 0 } }
197205
const initialState = {
198206
cash: new Decimal(0),
199207
reservedCash: new Decimal(10010),
@@ -226,7 +234,7 @@ test(`${ORDER_FILLED}, buy-side, partial fill, should increase commission and de
226234
quantity: new Decimal(50),
227235
commission: new Decimal(5)
228236
}
229-
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder } }
237+
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder, timestamp: 0 } }
230238
const initialState = {
231239
cash: new Decimal(0),
232240
reservedCash: new Decimal(10010),
@@ -259,7 +267,7 @@ test(`${ORDER_FILLED}, sell-side, partial fill, increase cash and commission, an
259267
quantity: new Decimal(-50),
260268
commission: new Decimal(5)
261269
}
262-
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder } }
270+
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder, timestamp: 0 } }
263271
const initialState = {
264272
cash: new Decimal(-10),
265273
reservedCash: new Decimal(10),
@@ -293,7 +301,7 @@ test(`${ORDER_FILLED}, buy-side, better price, should increase commission and de
293301
price: new Decimal(90),
294302
commission: new Decimal(9),
295303
}
296-
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder } }
304+
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder, timestamp: 0 } }
297305
const initialState = {
298306
cash: new Decimal(0),
299307
reservedCash: new Decimal(10010),
@@ -327,7 +335,7 @@ test(`${ORDER_FILLED}, sell-side, better price, increase cash and commission, an
327335
price: new Decimal(110),
328336
commission: new Decimal(11),
329337
}
330-
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder } }
338+
const action = { type: ORDER_FILLED, payload: { placedOrder, filledOrder, timestamp: 0 } }
331339
const initialState = {
332340
cash: new Decimal(-10),
333341
reservedCash: new Decimal(10),

__tests__/consumers.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test('createConsumer pushes errors', (done) => {
1717
const errors = []
1818
const items = []
1919

20-
const middleware = (store) => (next) => (action) => next({})
20+
const middleware = store => next => action => next({})
2121

2222
_.fromError(new Error('error')).concat([1, 2, 3])
2323
.consume(createConsumer(store)(middleware))
@@ -37,7 +37,7 @@ test('createConsumer pushes errors', (done) => {
3737

3838
test('createConsumer pushes the current item if next() is not supplied a new item', (done) => {
3939
const items = []
40-
const middleware = (store) => (next) => (action) => next()
40+
const middleware = store => next => action => next()
4141

4242
_([1, 2, 3])
4343
.consume(createConsumer(store)(middleware))

__tests__/createBrokerBacktest.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99

1010
import { createBrokerBacktest as createMiddleware } from '../lib/middleware/createBrokerBacktest'
1111

12-
const t = { context: {} }
12+
const t = { context: {} as any }
1313

1414
beforeEach(() => {
1515
const store = createMockStore({ orders: {} })

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy