File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,18 @@ export default class Almanac {
163
163
return factValuePromise
164
164
}
165
165
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
+
166
178
/**
167
179
* Interprets value as either a primitive, or if a fact, retrieves the fact value
168
180
*/
Original file line number Diff line number Diff line change 1
1
import { Fact } from '../src/index'
2
2
import Almanac from '../src/almanac'
3
3
import sinon from 'sinon'
4
+ import { expect } from 'chai'
4
5
5
6
describe ( 'Almanac' , ( ) => {
6
7
let almanac
@@ -189,4 +190,22 @@ describe('Almanac', () => {
189
190
} )
190
191
} )
191
192
} )
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
+ } )
192
211
} )
You can’t perform that action at this time.
0 commit comments