Preventing users from buying already gifted subscriber items (#7734)

* Adding the unopened mystery items to the call to get not obtained subscriber items. closes #7712

* refactoring according to pr

* Refactoring according to pr. moved time-travelers to it's own file and added new tests.
This commit is contained in:
Travis
2016-12-15 08:00:49 -08:00
committed by Keith Holliday
parent 0817cf96e1
commit fa788f49fc
8 changed files with 79 additions and 31 deletions

View File

@@ -0,0 +1,31 @@
import _ from 'lodash';
import mysterySets from './mystery-sets';
import gear from './gear';
let mystery = mysterySets;
_.each(mystery, (v, k) => {
return v.items = _.where(gear.flat, {
mystery: k,
});
});
let timeTravelerStore = (user) => {
let ownedKeys;
let owned = user.items.gear.owned;
let unopenedGifts = user.purchased.plan.mysteryItems;
ownedKeys = _.keys((typeof owned.toObject === 'function' ? owned.toObject() : undefined) || owned);
ownedKeys = _.union(ownedKeys, unopenedGifts);
return _.reduce(mystery, (m, v, k) => {
if (k === 'wondercon' || ownedKeys.indexOf(v.items[0].key) !== -1) {
return m;
}
m[k] = v;
return m;
}, {});
};
module.exports = {
timeTravelerStore,
mystery,
};