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

Commit

Permalink
fix: rewrite to use v2 stock count reports
Browse files Browse the repository at this point in the history
BREAKING CHANGE: no longer supports v1 stock count reports

Connects fielded/van-orga#934.
  • Loading branch information
tlvince committed Feb 8, 2018
1 parent e048131 commit 9c55c6c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@
var stock = stockCount.stock;

var decoratedStock = Object.keys(stock).reduce(function (decorated, product) {
var amount = stock[product];
// v2 stock count report
var amount = stock[product].amount;
var status = void 0;
var allocation = void 0;
var productThresholds = void 0;
Expand Down
2 changes: 1 addition & 1 deletion dist/bundle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/state-indicators.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class StateIndicatorsService {
const stock = stockCount.stock

const decoratedStock = Object.keys(stock).reduce((decorated, product) => {
let amount = stock[product]
// v2 stock count report
let amount = stock[product].amount
let status
let allocation
let productThresholds
Expand Down
26 changes: 13 additions & 13 deletions test/state-indicators.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ describe('state indicators service', function () {
var lgaStockCounts = [
{
location: { zone: 'nc', state: 'kogi', lga: 'a' },
stock: { 'product:a': 1, 'product:b': 3, 'product:c': 10, 'product:d': 36 },
stock: { 'product:a': { amount: 1 }, 'product:b': { amount: 3 }, 'product:c': { amount: 10 }, 'product:d': { amount: 36 } },
store: { type: 'lga' }
},
{
location: { zone: 'nc', state: 'kogi', lga: 'b' },
stock: { 'product:a': 0, 'product:b': 0, 'product:c': 11, 'product:d': 30 },
stock: { 'product:a': { amount: 0 }, 'product:b': { amount: 0 }, 'product:c': { amount: 11 }, 'product:d': { amount: 30 } },
store: { type: 'lga' }
},
{
location: { zone: 'nc', state: 'kogi', lga: 'c' },
stock: { 'product:a': 0, 'product:b': 0, 'product:c': 0, 'product:d': 75 },
stock: { 'product:a': { amount: 0 }, 'product:b': { amount: 0 }, 'product:c': { amount: 0 }, 'product:d': { amount: 75 } },
store: { type: 'lga' }
},
{
Expand All @@ -54,23 +54,23 @@ describe('state indicators service', function () {
var stateStockCounts = [
{
location: { zone: 'nc', state: 'kogi' },
stock: { 'product:a': 0, 'product:b': 1, 'product:c': 10, 'product:d': 40 },
stock: { 'product:a': { amount: 0 }, 'product:b': { amount: 1 }, 'product:c': { amount: 10 }, 'product:d': { amount: 40 } },
store: { type: 'state' }
}
]

var zoneStockCounts = [
{
location: { zone: 'nc' },
stock: { 'product:a': 0, 'product:b': 11, 'product:c': 20, 'product:d': 40 },
stock: { 'product:a': { amount: 0 }, 'product:b': { amount: 11 }, 'product:c': { amount: 20 }, 'product:d': { amount: 40 } },
store: { type: 'zone' }
}
]

var nationalStockCounts = [
{
location: { national: 'national' },
stock: { 'product:a': 1, 'product:b': 3, 'product:c': 10, 'product:d': 36 },
stock: { 'product:a': { amount: 1 }, 'product:b': { amount: 3 }, 'product:c': { amount: 10 }, 'product:d': { amount: 36 } },
store: { type: 'national' }
}
]
Expand Down Expand Up @@ -435,7 +435,7 @@ describe('state indicators service', function () {
var noRestockStateStockCounts = [
{
location: { zone: 'nc', state: 'kogi' },
stock: { 'product:a': 5, 'product:b': 10, 'product:c': 20, 'product:d': 30 },
stock: { 'product:a': { amount: 5 }, 'product:b': { amount: 10 }, 'product:c': { amount: 20 }, 'product:d': { amount: 30 } },
store: { type: 'state' }
}
]
Expand Down Expand Up @@ -482,7 +482,7 @@ describe('state indicators service', function () {
})
var unknownLgaStockCount = {
location: { zone: 'nc', state: 'kogi', lga: 'unknown' },
stock: { 'product:a': 2, 'product:b': 3, 'product:c': 10, 'product:d': 20 },
stock: { 'product:a': { amount: 2 }, 'product:b': { amount: 3 }, 'product:c': { amount: 10 }, 'product:d': { amount: 20 } },
store: { type: 'lga' }
}
var expected = [
Expand Down Expand Up @@ -512,7 +512,7 @@ describe('state indicators service', function () {
it('is true for lgas if any product is below reorder level', function (done) {
var noRestockNeeded = {
location: { zone: 'nc', state: 'kogi', lga: 'b' },
stock: { 'product:a': 3, 'product:b': 3, 'product:c': 3, 'product:d': 3 },
stock: { 'product:a': { amount: 3 }, 'product:b': { amount: 3 }, 'product:c': { amount: 3 }, 'product:d': { amount: 3 } },
store: { type: 'lga' }
}
var stockCounts = [angular.copy(lgaStockCounts[0]), noRestockNeeded]
Expand All @@ -527,12 +527,12 @@ describe('state indicators service', function () {
it('is true for states if any product is below max level', function (done) {
var reStockNeeded = {
location: { zone: 'nc', state: 'kogi' },
stock: { 'product:a': 4, 'product:b': 9, 'product:c': 19, 'product:d': 29 },
stock: { 'product:a': { amount: 4 }, 'product:b': { amount: 9 }, 'product:c': { amount: 19 }, 'product:d': { amount: 29 } },
store: { type: 'state' }
}
var noRestockNeeded = {
location: { zone: 'nc', state: 'kogi' },
stock: { 'product:a': 10, 'product:b': 10, 'product:c': 20, 'product:d': 30 },
stock: { 'product:a': { amount: 10 }, 'product:b': { amount: 10 }, 'product:c': { amount: 20 }, 'product:d': { amount: 30 } },
store: { type: 'state' }
}
var stockCounts = [reStockNeeded, noRestockNeeded]
Expand All @@ -547,12 +547,12 @@ describe('state indicators service', function () {
it('is true for zones if any product is below max level', function (done) {
var reStockNeeded = {
location: { zone: 'nc' },
stock: { 'product:a': 4, 'product:b': 9, 'product:c': 19, 'product:d': 29 },
stock: { 'product:a': { amount: 4 }, 'product:b': { amount: 9 }, 'product:c': { amount: 19 }, 'product:d': { amount: 29 } },
store: { type: 'zone' }
}
var noRestockNeeded = {
location: { zone: 'nc' },
stock: { 'product:a': 10, 'product:b': 10, 'product:c': 20, 'product:d': 30 },
stock: { 'product:a': { amount: 10 }, 'product:b': { amount: 10 }, 'product:c': { amount: 20 }, 'product:d': { amount: 30 } },
store: { type: 'zone' }
}
var stockCounts = [reStockNeeded, noRestockNeeded]
Expand Down

0 comments on commit 9c55c6c

Please sign in to comment.