Skip to content
This repository was archived by the owner on Jan 14, 2020. It is now read-only.

Commit 8f511d0

Browse files
feat: default all factors to version 1
1 parent 3aa8f95 commit 8f511d0

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/thresholds.service.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ const getFactorVersion = (stockCount, factor, options) => {
2525
if (options.version === 'last') {
2626
return options.version
2727
}
28-
if (stockCount[factor]) {
29-
return stockCount[factor].version
28+
if (!(stockCount[factor] && stockCount[factor].version)) {
29+
return 1
3030
}
31+
return stockCount[factor].version
3132
}
3233

3334
const getFactor = (location, versions, version) => {

test/thresholds.service.spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ describe('thresholds service', function () {
186186
var actual = thresholdsService.calculateThresholds(unroundedLocation, stockCount, products)
187187
expect(actual).toEqual(expected)
188188
})
189-
it('uses the last version of plans and allocations if { version: "last"} is passed as option', function () {
189+
it('uses the last version of all factors if { version: "last"} is passed as option', function () {
190190
var expected = {
191191
'product:a': {
192192
min: 200,
@@ -204,6 +204,24 @@ describe('thresholds service', function () {
204204
var actual = thresholdsService.calculateThresholds(location, stockCount, products, null, { version: 'last' })
205205
expect(actual).toEqual(expected)
206206
})
207+
it('uses 1 as default version for all factors if no version is provided', function () {
208+
var expected = {
209+
'product:a': {
210+
min: 50,
211+
reOrder: 100,
212+
max: 250,
213+
targetPopulation: 500
214+
},
215+
'product:b': {
216+
min: 100,
217+
reOrder: 200,
218+
max: 500,
219+
targetPopulation: 1000
220+
}
221+
}
222+
var actual = thresholdsService.calculateThresholds(location, {}, products)
223+
expect(actual).toEqual(expected)
224+
})
207225
})
208226

209227
describe('getThresholdsFor', function () {

0 commit comments

Comments
 (0)