Skip to content

Commit 50920ab

Browse files
author
Christopher Pardy
committed
Add factPriority to almanac
This brings getting the priority of a fact into line with getting the value of a fact.
1 parent 0de797c commit 50920ab

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/almanac.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ export default class Almanac {
163163
return factValuePromise
164164
}
165165

166+
/**
167+
* Returns the priority of the fact if one exists.
168+
* @param {string} factId - fact identifier
169+
*/
170+
factPriority (factId) {
171+
const fact = this._getFact(factId)
172+
if (fact === undefined) {
173+
return undefined
174+
}
175+
return fact.priority
176+
}
177+
166178
/**
167179
* Interprets value as either a primitive, or if a fact, retrieves the fact value
168180
*/

test/almanac.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Fact } from '../src/index'
22
import Almanac from '../src/almanac'
33
import sinon from 'sinon'
4+
import { expect } from 'chai'
45

56
describe('Almanac', () => {
67
let almanac
@@ -189,4 +190,22 @@ describe('Almanac', () => {
189190
})
190191
})
191192
})
193+
194+
describe('factPriority()', () => {
195+
function setup (priority) {
196+
const fact = new Fact('foo', 5, { priority })
197+
const factMap = new Map([[fact.id, fact]])
198+
return new Almanac(factMap)
199+
}
200+
201+
it('returns the priority if the fact exists', () => {
202+
const almanac = setup(3)
203+
expect(almanac.factPriority('foo')).to.equal(3)
204+
})
205+
206+
it("returns undefined if the fact doesn't exist", () => {
207+
const almanac = setup(6)
208+
expect(almanac.factPriority('bar')).to.equal(undefined)
209+
})
210+
})
192211
})

0 commit comments

Comments
 (0)