Skip to content

Commit 219e59e

Browse files
committed
fix($tests): fix tests after disallowing default imports
1 parent 9442dab commit 219e59e

20 files changed

Lines changed: 197 additions & 189 deletions

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"jest": "^22.0.2",
6363
"lint-staged": "^7.0.0",
6464
"lodash.camelcase": "^4.3.0",
65-
"perfy": "^1.1.2",
6665
"prettier": "^1.4.4",
6766
"prompt": "^1.0.0",
6867
"replace-in-file": "^3.0.0-beta.2",

test/engine-cache.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import engineFactory from '../src/index'
2-
import { ruleFactory } from './support/rule-factory'
1+
import {engineFactory} from '../src/truegin'
2+
import {ruleFactory} from './support/rule-factory'
33
import {Engine} from '../src/engine'
44
import {FactOptions} from '../src/fact'
55

66
describe('Engine: cache', () => {
77
let engine: Engine
88

9-
let event = { type: 'setDrinkingFlag' }
10-
let collegeSeniorEvent = { type: 'isCollegeSenior' }
9+
let event = {type: 'setDrinkingFlag'}
10+
let collegeSeniorEvent = {type: 'isCollegeSenior'}
1111
let conditions = {
1212
any: [{
1313
fact: 'age',
@@ -22,15 +22,16 @@ describe('Engine: cache', () => {
2222
factSpy()
2323
return 22
2424
}
25+
2526
function setup (factOptions: FactOptions) {
2627
factSpy = jest.fn()
2728
eventSpy = jest.fn()
2829
engine = engineFactory()
29-
let determineDrinkingAge = ruleFactory({ conditions, event, priority: 100 })
30+
let determineDrinkingAge = ruleFactory({conditions, event, priority: 100})
3031
engine.addRule(determineDrinkingAge)
31-
let determineCollegeSenior = ruleFactory({ conditions, event: collegeSeniorEvent, priority: 1 })
32+
let determineCollegeSenior = ruleFactory({conditions, event: collegeSeniorEvent, priority: 1})
3233
engine.addRule(determineCollegeSenior)
33-
let over20 = ruleFactory({ conditions, event: collegeSeniorEvent, priority: 50 })
34+
let over20 = ruleFactory({conditions, event: collegeSeniorEvent, priority: 50})
3435
engine.addRule(over20)
3536
engine.addFact('age', ageFact, factOptions)
3637
engine.on('success', eventSpy)

test/engine-controls.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import engineFactory from '../src/index'
2-
3-
import { ruleFactory } from './support/rule-factory'
4-
import Engine from '../src/engine'
1+
import {engineFactory} from '../src/truegin'
2+
import {ruleFactory} from './support/rule-factory'
3+
import {Engine} from '../src/engine'
54
import {ConditionConstructorOptions} from '../src/condition'
65

76
describe('Engine: fact priority', () => {
87
let engine: Engine
9-
let event = { type: 'adult-human-admins' }
8+
let event = {type: 'adult-human-admins'}
109

1110
let eventSpy = jest.fn()
1211
let ageStub = jest.fn()
@@ -25,7 +24,7 @@ describe('Engine: fact priority', () => {
2524
value: 18,
2625
}],
2726
}
28-
let rule = ruleFactory({ conditions, event, priority: 100 })
27+
let rule = ruleFactory({conditions, event, priority: 100})
2928
engine.addRule(rule)
3029

3130
conditions = {
@@ -35,11 +34,11 @@ describe('Engine: fact priority', () => {
3534
value: 'human',
3635
}],
3736
}
38-
rule = ruleFactory({ conditions, event })
37+
rule = ruleFactory({conditions, event})
3938
engine.addRule(rule)
4039

41-
engine.addFact('age', ageStub, { priority: 100 })
42-
engine.addFact('segment', segmentStub, { priority: 50 })
40+
engine.addFact('age', ageStub, {priority: 100})
41+
engine.addFact('segment', segmentStub, {priority: 50})
4342
}
4443

4544
describe('stop()', () => {

test/engine-custom-properties.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import engineFactory, { Fact, Rule } from '../src/index'
1+
import {Engine, engineFactory, Fact, Rule} from '../src/truegin'
22
import { ruleFactory } from './support/rule-factory'
33

44
describe('Engine: custom properties', () => {
@@ -43,8 +43,8 @@ describe('Engine: custom properties', () => {
4343
}
4444
let rule = ruleFactory({ conditions, event })
4545
engine.addRule(rule)
46-
expect(engine.rules[0].conditions!['all'][0]).toHaveProperty('customId')
47-
expect(engine.rules[0].conditions!['all'][0].customId).toBe('uuid')
46+
expect(engine.rules[0].conditions!['all']![0]).toHaveProperty('customId')
47+
expect((engine.rules[0].conditions!['all']![0] as any).customId).toBe('uuid')
4848
})
4949
})
5050

test/engine-error-handling.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import engineFactory from '../src/index'
2-
import { ruleFactory } from './support/rule-factory'
3-
import Engine from '../src/engine'
1+
import {engineFactory} from '../src/truegin'
2+
import {ruleFactory} from './support/rule-factory'
3+
import {Engine} from '../src/engine'
44

55
describe('Engine: failure', () => {
66
let engine: Engine
77

8-
let event = { type: 'generic' }
8+
let event = {type: 'generic'}
99
let conditions = {
1010
any: [{
1111
fact: 'age',
@@ -15,7 +15,7 @@ describe('Engine: failure', () => {
1515
}
1616
beforeEach(() => {
1717
engine = engineFactory()
18-
let determineDrinkingAgeRule = ruleFactory({ conditions, event })
18+
let determineDrinkingAgeRule = ruleFactory({conditions, event})
1919
engine.addRule(determineDrinkingAgeRule)
2020
engine.addFact('age', function () {
2121
throw new Error('problem occurred')

test/engine-fact-comparison.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import engineFactory from '../src/index'
1+
import {engineFactory} from '../src/truegin'
22

3-
import { ruleFactory } from './support/rule-factory'
4-
import Engine from '../src/engine'
3+
import {ruleFactory} from './support/rule-factory'
4+
import {Engine} from '../src/engine'
55
import {ConditionConstructorOptions} from '../src/condition'
66

77
describe('Engine: fact to fact comparison', () => {
88
let engine: Engine
99
let eventSpy = jest.fn()
1010

1111
function setup (conditions: ConditionConstructorOptions) {
12-
let event = { type: 'success-event' }
12+
let event = {type: 'success-event'}
1313
eventSpy = jest.fn()
1414
engine = engineFactory()
15-
let rule = ruleFactory({ conditions, event })
15+
let rule = ruleFactory({conditions, event})
1616
engine.addRule(rule)
1717
engine.on('success', eventSpy)
1818
}
@@ -29,12 +29,12 @@ describe('Engine: fact to fact comparison', () => {
2929
}
3030
test('allows a fact to retrieve other fact values', async () => {
3131
setup(constantCondition)
32-
await engine.run({ height: 1, width: 2 })
32+
await engine.run({height: 1, width: 2})
3333
expect(eventSpy).toHaveBeenCalledTimes(1)
3434

3535
eventSpy = jest.fn()
3636

37-
await engine.run({ height: 2, width: 1 }) // negative case
37+
await engine.run({height: 2, width: 1}) // negative case
3838
expect(eventSpy.mock.calls.length).toBe(0)
3939
})
4040
})
@@ -65,12 +65,12 @@ describe('Engine: fact to fact comparison', () => {
6565
let width = await almanac.factValue('width')
6666
return params.multiplier * width
6767
})
68-
await engine.run({ height: 5, width: 10 })
68+
await engine.run({height: 5, width: 10})
6969
expect(eventSpy).toHaveBeenCalledTimes(1)
7070

7171
eventSpy = jest.fn()
7272

73-
await engine.run({ height: 5, width: 9 }) // negative case
73+
await engine.run({height: 5, width: 9}) // negative case
7474
expect(eventSpy.mock.calls.length).toBe(0)
7575
})
7676
})
@@ -97,18 +97,18 @@ describe('Engine: fact to fact comparison', () => {
9797
setup(pathCondition)
9898
engine.addFact('heightMultiplier', async (params: any, almanac: any) => {
9999
let height = await almanac.factValue('height')
100-
return { meters: params.multiplier * height }
100+
return {meters: params.multiplier * height}
101101
})
102102
engine.addFact('widthMultiplier', async (params: any, almanac: any) => {
103103
let width = await almanac.factValue('width')
104-
return { feet: params.multiplier * width }
104+
return {feet: params.multiplier * width}
105105
})
106-
await engine.run({ height: 5, width: 10 })
106+
await engine.run({height: 5, width: 10})
107107
expect(eventSpy).toHaveBeenCalledTimes(1)
108108

109109
eventSpy = jest.fn()
110110

111-
await engine.run({ height: 5, width: 9 }) // negative case
111+
await engine.run({height: 5, width: 9}) // negative case
112112
expect(eventSpy.mock.calls.length).toBe(0)
113113
})
114114
})

test/engine-fact-priority.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import engineFactory from '../src/index'
1+
import {engineFactory} from '../src/truegin'
22

33
import { ruleFactory } from './support/rule-factory'
4-
import Engine from '../src/engine'
4+
import {Engine} from '../src/engine'
55
import {ConditionConstructorOptions} from '../src/condition'
66

77
describe('Engine: fact priority', () => {

test/engine-fact.test.ts

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import engineFactory from '../src/index'
2-
import { ruleFactory } from './support/rule-factory'
3-
import Engine from '../src/engine'
1+
import {engineFactory} from '../src/truegin'
2+
import {ruleFactory} from './support/rule-factory'
3+
import {Engine} from '../src/engine'
44
import {ConditionConstructorOptions} from '../src/condition'
55

66
const CHILD = 14
@@ -25,14 +25,14 @@ async function eligibilityData (params: any) {
2525
zip: '80403',
2626
'dot.property': 'dot-property-value',
2727
occupantHistory: [
28-
{ name: 'Joe', year: 2011 },
29-
{ name: 'Jane', year: 2013 },
28+
{name: 'Joe', year: 2011},
29+
{name: 'Jane', year: 2013},
3030
],
3131
}
3232
if (params.eligibilityId === 1) {
33-
return { age: CHILD, address }
33+
return {age: CHILD, address}
3434
}
35-
return { age: ADULT, address }
35+
return {age: ADULT, address}
3636
}
3737

3838
describe('Engine: fact evaluation', () => {
@@ -43,6 +43,7 @@ describe('Engine: fact evaluation', () => {
4343
demographic: 'under50',
4444
},
4545
}
46+
4647
function baseConditions (): any {
4748
return {
4849
any: [{
@@ -56,6 +57,7 @@ describe('Engine: fact evaluation', () => {
5657
}],
5758
}
5859
}
60+
5961
let successSpy = jest.fn()
6062
let failureSpy = jest.fn()
6163
beforeEach(() => {
@@ -65,7 +67,7 @@ describe('Engine: fact evaluation', () => {
6567

6668
function setup (conditions = baseConditions(), engineOptions = {}) {
6769
engine = engineFactory([], engineOptions)
68-
let rule = ruleFactory({ conditions, event })
70+
let rule = ruleFactory({conditions, event})
6971
engine.addRule(rule)
7072
engine.addFact('eligibilityField', eligibilityField)
7173
engine.addFact('eligibilityData', eligibilityData)
@@ -87,36 +89,36 @@ describe('Engine: fact evaluation', () => {
8789
})
8890

8991
describe(
90-
'treats undefined facts as falsey when allowUndefinedFacts is set',
91-
() => {
92-
test('emits "success" when the condition succeeds', async () => {
93-
let conditions = Object.assign({}, baseConditions())
94-
conditions.any.push({
95-
fact: 'undefined-fact',
96-
operator: 'equal',
97-
value: true,
98-
})
99-
setup(conditions, { allowUndefinedFacts: true })
100-
await engine.run()
101-
expect(successSpy.mock.calls.length)
102-
expect(!successSpy.mock.calls.length)
103-
})
92+
'treats undefined facts as falsey when allowUndefinedFacts is set',
93+
() => {
94+
test('emits "success" when the condition succeeds', async () => {
95+
let conditions = Object.assign({}, baseConditions())
96+
conditions.any.push({
97+
fact: 'undefined-fact',
98+
operator: 'equal',
99+
value: true,
100+
})
101+
setup(conditions, {allowUndefinedFacts: true})
102+
await engine.run()
103+
expect(successSpy.mock.calls.length)
104+
expect(!successSpy.mock.calls.length)
105+
})
104106

105-
test('emits "failure" when the condition fails', async () => {
106-
let conditions = Object.assign({}, baseConditions())
107-
conditions.any.push({
108-
fact: 'undefined-fact',
109-
operator: 'equal',
110-
value: true,
111-
})
112-
conditions.any[0].params.eligibilityId = 2
113-
setup(conditions, { allowUndefinedFacts: true })
114-
await engine.run()
115-
expect(!successSpy.mock.calls.length)
116-
expect(failureSpy.mock.calls.length)
117-
})
118-
},
119-
)
107+
test('emits "failure" when the condition fails', async () => {
108+
let conditions = Object.assign({}, baseConditions())
109+
conditions.any.push({
110+
fact: 'undefined-fact',
111+
operator: 'equal',
112+
value: true,
113+
})
114+
conditions.any[0].params.eligibilityId = 2
115+
setup(conditions, {allowUndefinedFacts: true})
116+
await engine.run()
117+
expect(!successSpy.mock.calls.length)
118+
expect(failureSpy.mock.calls.length)
119+
})
120+
},
121+
)
120122
})
121123
})
122124

@@ -150,6 +152,7 @@ describe('Engine: fact evaluation', () => {
150152
}],
151153
}
152154
}
155+
153156
test('emits when the condition is met', async () => {
154157
setup(conditions())
155158
await engine.run()
@@ -166,17 +169,17 @@ describe('Engine: fact evaluation', () => {
166169

167170
describe('complex paths', () => {
168171
test(
169-
'correctly interprets "path" when dynamic facts return objects',
170-
async () => {
171-
let complexCondition = conditions()
172-
;(complexCondition as any).any[0].path = '.address.occupantHistory[0].year'
173-
;(complexCondition as any).any[0].value = 2011
174-
;(complexCondition as any).any[0].operator = 'equal'
175-
setup(complexCondition)
176-
await engine.run()
177-
expect(successSpy.mock.calls[0][0]).toEqual(event)
178-
},
179-
)
172+
'correctly interprets "path" when dynamic facts return objects',
173+
async () => {
174+
let complexCondition = conditions()
175+
;(complexCondition as any).any[0].path = '.address.occupantHistory[0].year'
176+
;(complexCondition as any).any[0].value = 2011
177+
;(complexCondition as any).any[0].operator = 'equal'
178+
setup(complexCondition)
179+
await engine.run()
180+
expect(successSpy.mock.calls[0][0]).toEqual(event)
181+
},
182+
)
180183

181184
test(
182185
'correctly interprets "path" when target object properties have dots',
@@ -192,7 +195,7 @@ describe('Engine: fact evaluation', () => {
192195
)
193196

194197
test('correctly interprets "path" with runtime fact objects', async () => {
195-
let fact = { x: { y: 1 }, a: 2 }
198+
let fact = {x: {y: 1}, a: 2}
196199
let conditions = {
197200
all: [{
198201
fact: 'x',
@@ -206,7 +209,7 @@ describe('Engine: fact evaluation', () => {
206209
}
207210

208211
engine = engineFactory([])
209-
let rule = ruleFactory({ conditions, event })
212+
let rule = ruleFactory({conditions, event})
210213
engine.addRule(rule)
211214
engine.on('success', successSpy)
212215
engine.on('failure', failureSpy)

0 commit comments

Comments
 (0)