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

Commit f367a67

Browse files
fix: update location target population field name
1 parent 0eb18e0 commit f367a67

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/thresholds.service.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ const getFactors = (stockCount, location, options) => {
4848
return {}
4949
}
5050

51-
if (!(location.targetPopulation && location.targetPopulation.length)) {
51+
if (!(location.targetPopulations && location.targetPopulations.length)) {
5252
return {}
5353
}
5454
const allocationsVersion = getFactorVersion(stockCount, 'allocations', options)
5555
const plansVersion = getFactorVersion(stockCount, 'plans', options)
56-
const targetPopulationVersion = getFactorVersion(stockCount, 'targetPopulation', options)
56+
const targetPopulationVersion = getFactorVersion(stockCount, 'targetPopulations', options)
5757

5858
if (typeof allocationsVersion === 'undefined' ||
5959
typeof plansVersion === 'undefined' ||
@@ -62,18 +62,18 @@ const getFactors = (stockCount, location, options) => {
6262
return {}
6363
}
6464

65-
const allocation = getFactor(location, location.allocations, allocationsVersion)
66-
const targetPopulation = getFactor(location, location.targetPopulation, targetPopulationVersion)
65+
const allocations = getFactor(location, location.allocations, allocationsVersion)
66+
const targetPopulations = getFactor(location, location.targetPopulations, targetPopulationVersion)
6767

6868
let plans = zonePlans
6969
if (location.level !== 'zone') {
7070
plans = getFactor(location, location.plans, plansVersion)
7171
}
7272

7373
return {
74-
weeklyLevels: allocation && allocation.weeklyLevels,
74+
weeklyLevels: allocations && allocations.weeklyLevels,
7575
weeksOfStock: plans && plans.weeksOfStock,
76-
targetPopulation: targetPopulation && targetPopulation.targetPopulation
76+
targetPopulations: targetPopulations && targetPopulations.monthlyTargetPopulations
7777
}
7878
}
7979

@@ -101,9 +101,9 @@ class ThresholdsService {
101101
return
102102
}
103103

104-
const { weeklyLevels, weeksOfStock, targetPopulation } = getFactors(stockCount, location, options)
104+
const { weeklyLevels, weeksOfStock, targetPopulations } = getFactors(stockCount, location, options)
105105

106-
if (!(weeklyLevels && weeksOfStock && targetPopulation)) {
106+
if (!(weeklyLevels && weeksOfStock && targetPopulations)) {
107107
return
108108
}
109109

@@ -130,7 +130,7 @@ class ThresholdsService {
130130
return productThresholds
131131
}, {})
132132

133-
index[productId].targetPopulation = targetPopulation[productId]
133+
index[productId].targetPopulation = targetPopulations[productId]
134134

135135
return index
136136
}, {})
@@ -155,8 +155,12 @@ class ThresholdsService {
155155
const id = this.smartId.idify(scLocation, locationIdPattern)
156156
const allocations = stockCount.allocations || { version: 1 }
157157
const plans = stockCount.plans || { version: 1 }
158-
const targetPopulation = stockCount.targetPopulation || { version: 1 }
159-
index[id] = angular.merge({}, { allocations: allocations, plans: plans, targetPopulation: targetPopulation })
158+
const targetPopulations = stockCount.targetPopulations || { version: 1 }
159+
index[id] = angular.merge({}, {
160+
allocations,
161+
plans,
162+
targetPopulations
163+
})
160164

161165
if (scLocation.lga) {
162166
if (!promises.lga) {

test/thresholds.service.spec.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ describe('thresholds service', function () {
4747
}
4848
}
4949
],
50-
targetPopulation: [
50+
targetPopulations: [
5151
{
5252
version: 1,
53-
targetPopulation: {
53+
monthlyTargetPopulations: {
5454
'product:a': 500,
5555
'product:b': 1000
5656
}
5757
},
5858
{
5959
version: 2,
60-
targetPopulation: {
60+
monthlyTargetPopulations: {
6161
'product:a': 1000,
6262
'product:b': 2000
6363
}
@@ -86,7 +86,7 @@ describe('thresholds service', function () {
8686
var stockCount = {
8787
allocations: { version: 2 },
8888
plans: { version: 1 },
89-
targetPopulation: { version: 2 }
89+
targetPopulations: { version: 2 }
9090
}
9191

9292
var products = [
@@ -228,7 +228,7 @@ describe('thresholds service', function () {
228228
it('takes an array of objects with location, allocations and plans fields and returns an object of location thresholds', function (done) {
229229
var stockCounts = [
230230
// { location: { zone: 'nc' }, allocations: { version: 2 }, plans: { version: 1 } },
231-
{ location: { zone: 'nc', state: 'kogi' }, allocations: { version: 2 }, plans: { version: 1 }, targetPopulation: { version: 2 } },
231+
{ location: { zone: 'nc', state: 'kogi' }, allocations: { version: 2 }, plans: { version: 1 }, targetPopulations: { version: 2 } },
232232
{ location: { zone: 'nc', state: 'kogi', lga: 'adavi' } }
233233
]
234234
var expected = {
@@ -241,7 +241,7 @@ describe('thresholds service', function () {
241241
'zone:nc:state:kogi': {
242242
allocations: { version: 2 },
243243
plans: { version: 1 },
244-
targetPopulation: { version: 2 },
244+
targetPopulations: { version: 2 },
245245
thresholds: {
246246
'product:a': { min: 100, reOrder: 200, max: 500, targetPopulation: 1000 },
247247
'product:b': { min: 200, reOrder: 400, max: 1000, targetPopulation: 2000 }
@@ -250,7 +250,7 @@ describe('thresholds service', function () {
250250
'zone:nc:state:kogi:lga:adavi': {
251251
allocations: { version: 1 },
252252
plans: { version: 1 },
253-
targetPopulation: { version: 1 },
253+
targetPopulations: { version: 1 },
254254
thresholds: {
255255
'product:a': { min: 50, reOrder: 100, max: 250, targetPopulation: 500 },
256256
'product:b': { min: 100, reOrder: 200, max: 500, targetPopulation: 1000 }

0 commit comments

Comments
 (0)