Skip to content

Commit 1472a2a

Browse files
authored
Json path fix scalars (#191)
Json path fix scalars
2 parents c858ec0 + 870a900 commit 1472a2a

4 files changed

Lines changed: 30 additions & 51 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#### 5.0.3 / 2020-01-26
2+
* Upgrade jsonpath-plus dependency, to fix inconsistent scalar results (#175)
3+
14
#### 5.0.2 / 2020-01-18
25
* BUGFIX: Add missing `DEBUG` log for almanac.addRuntimeFact()
36

package-lock.json

Lines changed: 3 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"clone": "^2.1.2",
7272
"events": "^3.0.0",
7373
"hash-it": "^4.0.4",
74-
"jsonpath-plus": "^1.1.0",
74+
"jsonpath-plus": "^3.0.0",
7575
"lodash.isobjectlike": "^4.0.0"
7676
}
7777
}

test/engine-fact.test.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ async function eligibilityData (params, engine) {
2727
occupantHistory: [
2828
{ name: 'Joe', year: 2011 },
2929
{ name: 'Jane', year: 2013 }
30+
],
31+
currentOccupants: [
32+
{ name: 'Larry', year: 2020 }
3033
]
3134
}
3235
if (params.eligibilityId === 1) {
@@ -168,14 +171,26 @@ describe('Engine: fact evaluation', () => {
168171
expect(successSpy).to.not.have.been.called()
169172
})
170173

171-
it('can extract an array, allowing it to be used in concert with array operators', async () => {
172-
const complexCondition = conditions()
173-
complexCondition.any[0].path = '$.address.occupantHistory[*].year'
174-
complexCondition.any[0].value = 2011
175-
complexCondition.any[0].operator = 'contains'
176-
setup(complexCondition)
177-
await engine.run()
178-
expect(successSpy).to.have.been.calledWith(event)
174+
describe('arrays', () => {
175+
it('can extract an array, allowing it to be used in concert with array operators', async () => {
176+
const complexCondition = conditions()
177+
complexCondition.any[0].path = '$.address.occupantHistory[*].year'
178+
complexCondition.any[0].value = 2011
179+
complexCondition.any[0].operator = 'contains'
180+
setup(complexCondition)
181+
await engine.run()
182+
expect(successSpy).to.have.been.calledWith(event)
183+
})
184+
185+
it('can extract an array with a single element', async () => {
186+
const complexCondition = conditions()
187+
complexCondition.any[0].path = '$.address.currentOccupants[*].year'
188+
complexCondition.any[0].value = 2020
189+
complexCondition.any[0].operator = 'contains'
190+
setup(complexCondition)
191+
await engine.run()
192+
expect(successSpy).to.have.been.calledWith(event)
193+
})
179194
})
180195

181196
context('complex paths', () => {

0 commit comments

Comments
 (0)