Skip to content

Commit

Permalink
Merge e131714 into 23cc2b9
Browse files Browse the repository at this point in the history
  • Loading branch information
negue committed Mar 21, 2019
2 parents 23cc2b9 + e131714 commit b7951a3
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
12 changes: 12 additions & 0 deletions test/common/libs/inAppRewards.js
Expand Up @@ -62,6 +62,18 @@ describe('inAppRewards', () => {
expect(result[9].path).to.eql('potion');
});

it('ignores null/undefined entries', () => {
user.pinnedItems = testPinnedItems;
user.pinnedItems.push(null);
user.pinnedItems.push(undefined);
user.pinnedItemsOrder = testPinnedItemsOrder;

let result = inAppRewards(user);

expect(result[2].path).to.eql('armoire');
expect(result[9].path).to.eql('potion');
});

it('does not return seasonal items which have been unpinned', () => {
if (officialPinnedItems.length === 0) {
return; // if no seasonal items, this test is not applicable
Expand Down
18 changes: 18 additions & 0 deletions test/common/ops/pinnedGearUtils.js
@@ -0,0 +1,18 @@
import {
generateUser,
} from '../../helpers/common.helper';
import {addPinnedGear} from '../../../website/common/script/ops/pinnedGearUtils';

describe('shared.ops.pinnedGearUtils.addPinnedGear', () => {
let user;

beforeEach(() => {
user = generateUser();
});

it('not adds an item with empty properties to pinnedItems', () => {
addPinnedGear(user, undefined, undefined);

expect(user.pinnedItems.length).to.be.eql(0);
});
});
4 changes: 3 additions & 1 deletion website/client/components/ui/drawer.vue
Expand Up @@ -174,7 +174,9 @@ export default {
let minPaddingBottom = 20;
let drawerHeight = this.$el.offsetHeight;
let standardPage = document.getElementsByClassName('standard-page')[0];
standardPage.style.paddingBottom = `${drawerHeight + minPaddingBottom}px`;
if (standardPage) {
standardPage.style.paddingBottom = `${drawerHeight + minPaddingBottom}px`;
}
},
toggle () {
this.open = !this.isOpen;
Expand Down
3 changes: 0 additions & 3 deletions website/client/store/actions/shops.js
Expand Up @@ -20,9 +20,6 @@ function buyItem (store, params) {

let opResult = buyOp(user, {params, quantity});

user.pinnedItems = opResult[0].pinnedItems;


return {
result: opResult,
httpCall: axios.post(`/api/v4/user/buy/${params.key}`),
Expand Down
12 changes: 8 additions & 4 deletions website/common/script/libs/inAppRewards.js
Expand Up @@ -4,6 +4,7 @@ import getOfficialPinnedItems from './getOfficialPinnedItems';
import compactArray from 'lodash/compact';

import getItemByPathAndType from './getItemByPathAndType';
import {checkPinnedAreasForNullEntries} from '../ops/pinnedGearUtils';

/**
* Orders the pinned items so we always get our inAppRewards in the order
Expand Down Expand Up @@ -32,6 +33,8 @@ function sortInAppRewards (user, items) {
}

module.exports = function getPinnedItems (user) {
checkPinnedAreasForNullEntries(user);

let officialPinnedItems = getOfficialPinnedItems(user);

const officialPinnedItemsNotUnpinned = officialPinnedItems.filter(officialPin => {
Expand All @@ -41,11 +44,12 @@ module.exports = function getPinnedItems (user) {

const pinnedItems = officialPinnedItemsNotUnpinned.concat(user.pinnedItems);

let items = pinnedItems.map(({type, path}) => {
let item = getItemByPathAndType(type, path);
let items = pinnedItems
.map(({type, path}) => {
let item = getItemByPathAndType(type, path);

return getItemInfo(user, type, item, officialPinnedItems);
});
return getItemInfo(user, type, item, officialPinnedItems);
});

shops.checkMarketGearLocked(user, items);

Expand Down
3 changes: 2 additions & 1 deletion website/common/script/libs/shops.js
Expand Up @@ -107,7 +107,8 @@ function getClassName (classType, language) {
// TODO Refactor the `.locked` logic
shops.checkMarketGearLocked = function checkMarketGearLocked (user, items) {
let result = filter(items, ['pinType', 'marketGear']);
let availableGear = map(updateStore(user), (item) => getItemInfo(user, 'marketGear', item).path);
const officialPinnedItems = getOfficialPinnedItems(user);
let availableGear = map(updateStore(user), (item) => getItemInfo(user, 'marketGear', item, officialPinnedItems).path);
for (let gear of result) {
if (gear.klass !== user.stats.class) {
gear.locked = true;
Expand Down
13 changes: 11 additions & 2 deletions website/common/script/ops/pinnedGearUtils.js
Expand Up @@ -27,6 +27,15 @@ function pathExistsInArray (array, path) {
});
}

function checkForNullEntries (array) {
return array.filter(e => Boolean(e));
}

function checkPinnedAreasForNullEntries (user) {
user.pinnedItems = checkForNullEntries(user.pinnedItems);
user.unpinnedItems = checkForNullEntries(user.unpinnedItems);
}

function selectGearToPin (user) {
let changes = [];

Expand All @@ -41,11 +50,10 @@ function selectGearToPin (user) {
return sortBy(changes, (change) => sortOrder[change.type]);
}


function addPinnedGear (user, type, path) {
const foundIndex = pathExistsInArray(user.pinnedItems, path);

if (foundIndex === -1) {
if (foundIndex === -1 && type && path) {
user.pinnedItems.push({
type,
path,
Expand Down Expand Up @@ -176,5 +184,6 @@ module.exports = {
togglePinnedItem,
removeItemByPath,
selectGearToPin,
checkPinnedAreasForNullEntries,
isPinned,
};

0 comments on commit b7951a3

Please sign in to comment.