Merge branch 'api-v3' into api-v3-client
|
|
@ -37,7 +37,7 @@
|
|||
"jquery-ui": "1.10.3",
|
||||
"jquery.cookie": "1.4.0",
|
||||
"js-emoji": "snicker/js-emoji#f25d8a303f",
|
||||
"marked": "0.2.9",
|
||||
"remarkable": "^1.6.2",
|
||||
"ngInfiniteScroll": "1.0.0",
|
||||
"pnotify": "1.3.1",
|
||||
"sticky": "*",
|
||||
|
|
|
|||
732
common/dist/sprites/spritesmith-main-10.css
vendored
BIN
common/dist/sprites/spritesmith-main-10.png
vendored
|
Before Width: | Height: | Size: 143 KiB After Width: | Height: | Size: 142 KiB |
880
common/dist/sprites/spritesmith-main-11.css
vendored
BIN
common/dist/sprites/spritesmith-main-11.png
vendored
|
Before Width: | Height: | Size: 155 KiB After Width: | Height: | Size: 155 KiB |
954
common/dist/sprites/spritesmith-main-12.css
vendored
BIN
common/dist/sprites/spritesmith-main-12.png
vendored
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 2 KiB |
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 1.9 KiB |
|
|
@ -113,14 +113,13 @@
|
|||
"missingKeyParam": "\"req.params.key\" is required.",
|
||||
"mysterySetNotFound": "Mystery set not found, or set already owned.",
|
||||
"itemNotFound": "Item \"<%= key %>\" not found.",
|
||||
"cannoyBuyItem": "You can't buy this item.",
|
||||
"cannotBuyItem": "You can't buy this item.",
|
||||
"missingTypeKeyEquip": "\"key\" and \"type\" are required parameters.",
|
||||
"missingPetFoodFeed": "\"pet\" and \"food\" are required parameters.",
|
||||
"invalidPetName": "Invalid pet name supplied.",
|
||||
"missingEggHatchingPotionHatch": "\"egg\" and \"hatchingPotion\" are required parameters.",
|
||||
"invalidTypeEquip": "\"type\" must be one of 'equipped', 'pet', 'mount', 'costume'.",
|
||||
"cannotDeleteActiveAccount": "You have an active subscription, cancel your plan before deleting your account.",
|
||||
"cannoyBuyItem": "You can't buy this item",
|
||||
"messageRequired": "A message is required.",
|
||||
"toUserIDRequired": "A toUserId is required",
|
||||
"notAuthorizedToSendMessageToThisUser": "Can't send message to this user.",
|
||||
|
|
@ -160,7 +159,8 @@
|
|||
"sold": "You sold a <%= key %> <%= type %>",
|
||||
"pathRequired": "Path string is required",
|
||||
"unlocked": "Items have been unlocked",
|
||||
"alreadyUnlocked": "Item already unlocked",
|
||||
"alreadyUnlocked": "Full set already unlocked.",
|
||||
"alreadyUnlockedPart": "Full set already partially unlocked.",
|
||||
"cannotRevive": "Cannot revive if not dead",
|
||||
"rebirthComplete": "You have been reborn!",
|
||||
"petNotOwned": "You do not own this pet.",
|
||||
|
|
@ -170,5 +170,6 @@
|
|||
"pushDeviceAdded": "Push device added successfully",
|
||||
"pushDeviceAlreadyAdded": "The user already has the push device",
|
||||
"resetComplete": "Reset completed",
|
||||
"lvl10ChangeClass": "To change class you must be at least level 10."
|
||||
"lvl10ChangeClass": "To change class you must be at least level 10.",
|
||||
"equipmentAlreadyOwned": "You already own that piece of equipment"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,6 +113,9 @@ import scoreTask from './ops/scoreTask';
|
|||
import sleep from './ops/sleep';
|
||||
import allocate from './ops/allocate';
|
||||
import buy from './ops/buy';
|
||||
import buyGear from './ops/buyGear';
|
||||
import buyPotion from './ops/buyPotion';
|
||||
import buyArmoire from './ops/buyArmoire';
|
||||
import buyMysterySet from './ops/buyMysterySet';
|
||||
import buyQuest from './ops/buyQuest';
|
||||
import buySpecialSpell from './ops/buySpecialSpell';
|
||||
|
|
@ -150,6 +153,9 @@ api.ops = {
|
|||
sleep,
|
||||
allocate,
|
||||
buy,
|
||||
buyGear,
|
||||
buyPotion,
|
||||
buyArmoire,
|
||||
buyMysterySet,
|
||||
buySpecialSpell,
|
||||
buyQuest,
|
||||
|
|
@ -266,6 +272,9 @@ api.wrap = function wrapUser (user, main = true) {
|
|||
releaseMounts: _.partial(importedOps.releaseMounts, user),
|
||||
releaseBoth: _.partial(importedOps.releaseBoth, user),
|
||||
buy: _.partial(importedOps.buy, user),
|
||||
buyPotion: _.partial(importedOps.buyPotion, user),
|
||||
buyArmoire: _.partial(importedOps.buyArmoire, user),
|
||||
buyGear: _.partial(importedOps.buyGear, user),
|
||||
buyQuest: _.partial(importedOps.buyQuest, user),
|
||||
buyMysterySet: _.partial(importedOps.buyMysterySet, user),
|
||||
hourglassPurchase: _.partial(importedOps.hourglassPurchase, user),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import _ from 'lodash';
|
||||
import i18n from '../i18n';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
|
|
@ -35,10 +34,8 @@ module.exports = function addPushDevice (user, req = {}) {
|
|||
|
||||
pushDevices.push(item);
|
||||
|
||||
let response = {
|
||||
data: _.pick(user, splitWhitespace('pushDevices')),
|
||||
message: i18n.t('pushDeviceAdded', req.language),
|
||||
};
|
||||
|
||||
return response;
|
||||
return [
|
||||
user.pushDevices,
|
||||
i18n.t('pushDeviceAdded', req.language),
|
||||
];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ import {
|
|||
import _ from 'lodash';
|
||||
|
||||
module.exports = function addWebhook (user, req = {}) {
|
||||
let wh;
|
||||
wh = user.preferences.webhooks;
|
||||
let wh = user.preferences.webhooks;
|
||||
|
||||
if (!validator.isURL(_.get(req, 'body.url'))) throw new BadRequest(i18n.t('invalidUrl', req.language));
|
||||
if (!validator.isBoolean(_.get(req, 'body.enabled'))) throw new BadRequest(i18n.t('invalidEnabled', req.language));
|
||||
|
|
@ -18,9 +17,11 @@ module.exports = function addWebhook (user, req = {}) {
|
|||
if (req.v2 === true) {
|
||||
return user.preferences.webhooks;
|
||||
} else {
|
||||
return refPush(wh, {
|
||||
url: req.body.url,
|
||||
enabled: req.body.enabled,
|
||||
});
|
||||
return [
|
||||
refPush(wh, {
|
||||
url: req.body.url,
|
||||
enabled: req.body.enabled,
|
||||
}),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import _ from 'lodash';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import {
|
||||
ATTRIBUTES,
|
||||
} from '../constants';
|
||||
|
|
@ -26,5 +25,7 @@ module.exports = function allocate (user, req = {}) {
|
|||
throw new NotAuthorized(i18n.t('notEnoughAttrPoints', req.language));
|
||||
}
|
||||
|
||||
return _.pick(user, splitWhitespace('stats'));
|
||||
return [
|
||||
user.stats,
|
||||
];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ module.exports = function allocateNow (user, req = {}) {
|
|||
if (req.v2 === true) {
|
||||
return _.pick(user, 'stats');
|
||||
} else {
|
||||
return {
|
||||
data: _.pick(user, 'stats'),
|
||||
};
|
||||
return [
|
||||
user.stats,
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,5 +15,7 @@ module.exports = function blockUser (user, req = {}) {
|
|||
}
|
||||
|
||||
user.markModified('inbox.blocks');
|
||||
return user.inbox.blocks;
|
||||
return [
|
||||
user.inbox.blocks,
|
||||
];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,142 +1,24 @@
|
|||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import _ from 'lodash';
|
||||
import count from '../count';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
NotFound,
|
||||
} from '../libs/errors';
|
||||
import predictableRandom from '../fns/predictableRandom';
|
||||
import randomVal from '../fns/randomVal';
|
||||
import handleTwoHanded from '../fns/handleTwoHanded';
|
||||
import ultimateGear from '../fns/ultimateGear';
|
||||
import buyPotion from './buyPotion';
|
||||
import buyArmoire from './buyArmoire';
|
||||
import buyGear from './buyGear';
|
||||
|
||||
module.exports = function buy (user, req = {}, analytics) {
|
||||
let key = _.get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(i18n.t('missingKeyParam', req.language));
|
||||
|
||||
let item;
|
||||
let buyRes;
|
||||
if (key === 'potion') {
|
||||
item = content.potion;
|
||||
buyRes = buyPotion(user, req, analytics);
|
||||
} else if (key === 'armoire') {
|
||||
item = content.armoire;
|
||||
buyRes = buyArmoire(user, req, analytics);
|
||||
} else {
|
||||
item = content.gear.flat[key];
|
||||
}
|
||||
if (!item) throw new NotFound(i18n.t('itemNotFound', {key}, req.language));
|
||||
|
||||
if (user.stats.gp < item.value) {
|
||||
throw new NotAuthorized(i18n.t('messageNotEnoughGold', req.language));
|
||||
buyRes = buyGear(user, req, analytics);
|
||||
}
|
||||
|
||||
if (item.canOwn && !item.canOwn(user)) {
|
||||
throw new NotAuthorized(i18n.t('cannoyBuyItem', req.language));
|
||||
}
|
||||
|
||||
let armoireResp;
|
||||
let armoireResult;
|
||||
let eligibleEquipment;
|
||||
let drop;
|
||||
let message;
|
||||
|
||||
if (item.key === 'potion') {
|
||||
user.stats.hp += 15;
|
||||
if (user.stats.hp > 50) {
|
||||
user.stats.hp = 50;
|
||||
}
|
||||
} else if (item.key === 'armoire') {
|
||||
armoireResult = predictableRandom(user, user.stats.gp);
|
||||
eligibleEquipment = _.filter(content.gear.flat, (eligible) => {
|
||||
return eligible.klass === 'armoire' && !user.items.gear.owned[eligible.key];
|
||||
});
|
||||
|
||||
if (!_.isEmpty(eligibleEquipment) && (armoireResult < 0.6 || !user.flags.armoireOpened)) {
|
||||
eligibleEquipment.sort();
|
||||
drop = randomVal(user, eligibleEquipment);
|
||||
|
||||
user.items.gear.owned[drop.key] = true;
|
||||
user.flags.armoireOpened = true;
|
||||
message = i18n.t('armoireEquipment', {
|
||||
image: `<span class="shop_${drop.key} pull-left"></span>`,
|
||||
dropText: drop.text(req.language),
|
||||
}, req.language);
|
||||
|
||||
if (count.remainingGearInSet(user.items.gear.owned, 'armoire') === 0) {
|
||||
user.flags.armoireEmpty = true;
|
||||
}
|
||||
|
||||
armoireResp = {
|
||||
type: 'gear',
|
||||
dropKey: drop.key,
|
||||
dropText: drop.text(req.language),
|
||||
};
|
||||
} else if ((!_.isEmpty(eligibleEquipment) && armoireResult < 0.8) || armoireResult < 0.5) { // eslint-disable-line no-extra-parens
|
||||
drop = randomVal(user, _.where(content.food, {
|
||||
canDrop: true,
|
||||
}));
|
||||
user.items.food[drop.key] = user.items.food[drop.key] || 0;
|
||||
user.items.food[drop.key] += 1;
|
||||
|
||||
message = i18n.t('armoireFood', {
|
||||
image: `<span class="Pet_Food_${drop.key} pull-left"></span>`,
|
||||
dropArticle: drop.article,
|
||||
dropText: drop.text(req.language),
|
||||
}, req.language);
|
||||
armoireResp = {
|
||||
type: 'food',
|
||||
dropKey: drop.key,
|
||||
dropArticle: drop.article,
|
||||
dropText: drop.text(req.language),
|
||||
};
|
||||
} else {
|
||||
let armoireExp = Math.floor(predictableRandom(user, user.stats.exp) * 40 + 10);
|
||||
user.stats.exp += armoireExp;
|
||||
message = i18n.t('armoireExp', req.language);
|
||||
armoireResp = {
|
||||
type: 'experience',
|
||||
value: armoireExp,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (user.preferences.autoEquip) {
|
||||
user.items.gear.equipped[item.type] = item.key;
|
||||
message = handleTwoHanded(user, item, undefined, req);
|
||||
}
|
||||
user.items.gear.owned[item.key] = true;
|
||||
|
||||
if (item.last) ultimateGear(user);
|
||||
}
|
||||
|
||||
user.stats.gp -= item.value;
|
||||
|
||||
if (!message) {
|
||||
message = i18n.t('messageBought', {
|
||||
itemText: item.text(req.language),
|
||||
}, req.language);
|
||||
}
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
uuid: user._id,
|
||||
itemKey: key,
|
||||
acquireMethod: 'Gold',
|
||||
goldCost: item.value,
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
|
||||
let res = {
|
||||
data: _.pick(user, splitWhitespace('items achievements stats flags')),
|
||||
message,
|
||||
};
|
||||
|
||||
if (armoireResp) res.armoire = armoireResp;
|
||||
|
||||
if (req.v2 === true) {
|
||||
return res.data;
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
return buyRes;
|
||||
};
|
||||
|
|
|
|||
115
common/script/ops/buyArmoire.js
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import _ from 'lodash';
|
||||
import count from '../count';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import predictableRandom from '../fns/predictableRandom';
|
||||
import randomVal from '../fns/randomVal';
|
||||
|
||||
module.exports = function buyArmoire (user, req = {}, analytics) {
|
||||
let item = content.armoire;
|
||||
|
||||
if (user.stats.gp < item.value) {
|
||||
throw new NotAuthorized(i18n.t('messageNotEnoughGold', req.language));
|
||||
}
|
||||
|
||||
if (item.canOwn && !item.canOwn(user)) {
|
||||
throw new NotAuthorized(i18n.t('cannotBuyItem', req.language));
|
||||
}
|
||||
|
||||
let armoireResp;
|
||||
let armoireResult;
|
||||
let eligibleEquipment;
|
||||
let drop;
|
||||
let message;
|
||||
|
||||
armoireResult = predictableRandom(user, user.stats.gp);
|
||||
eligibleEquipment = _.filter(content.gear.flat, (eligible) => {
|
||||
return eligible.klass === 'armoire' && !user.items.gear.owned[eligible.key];
|
||||
});
|
||||
|
||||
if (!_.isEmpty(eligibleEquipment) && (armoireResult < 0.6 || !user.flags.armoireOpened)) {
|
||||
eligibleEquipment.sort();
|
||||
drop = randomVal(user, eligibleEquipment);
|
||||
|
||||
if (user.items.gear.owned[drop.key]) {
|
||||
throw new NotAuthorized(i18n.t('equipmentAlradyOwned', req.language));
|
||||
}
|
||||
|
||||
user.items.gear.owned[drop.key] = true;
|
||||
user.flags.armoireOpened = true;
|
||||
message = i18n.t('armoireEquipment', {
|
||||
image: `<span class="shop_${drop.key} pull-left"></span>`,
|
||||
dropText: drop.text(req.language),
|
||||
}, req.language);
|
||||
|
||||
if (count.remainingGearInSet(user.items.gear.owned, 'armoire') === 0) {
|
||||
user.flags.armoireEmpty = true;
|
||||
}
|
||||
|
||||
armoireResp = {
|
||||
type: 'gear',
|
||||
dropKey: drop.key,
|
||||
dropText: drop.text(req.language),
|
||||
};
|
||||
} else if ((!_.isEmpty(eligibleEquipment) && armoireResult < 0.8) || armoireResult < 0.5) { // eslint-disable-line no-extra-parens
|
||||
drop = randomVal(user, _.where(content.food, {
|
||||
canDrop: true,
|
||||
}));
|
||||
user.items.food[drop.key] = user.items.food[drop.key] || 0;
|
||||
user.items.food[drop.key] += 1;
|
||||
|
||||
message = i18n.t('armoireFood', {
|
||||
image: `<span class="Pet_Food_${drop.key} pull-left"></span>`,
|
||||
dropArticle: drop.article,
|
||||
dropText: drop.text(req.language),
|
||||
}, req.language);
|
||||
armoireResp = {
|
||||
type: 'food',
|
||||
dropKey: drop.key,
|
||||
dropArticle: drop.article,
|
||||
dropText: drop.text(req.language),
|
||||
};
|
||||
} else {
|
||||
let armoireExp = Math.floor(predictableRandom(user, user.stats.exp) * 40 + 10);
|
||||
user.stats.exp += armoireExp;
|
||||
message = i18n.t('armoireExp', req.language);
|
||||
armoireResp = {
|
||||
type: 'experience',
|
||||
value: armoireExp,
|
||||
};
|
||||
}
|
||||
|
||||
user.stats.gp -= item.value;
|
||||
|
||||
if (!message) {
|
||||
message = i18n.t('messageBought', {
|
||||
itemText: item.text(req.language),
|
||||
}, req.language);
|
||||
}
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
uuid: user._id,
|
||||
itemKey: 'Armoire',
|
||||
acquireMethod: 'Gold',
|
||||
goldCost: item.value,
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
|
||||
let resData = _.pick(user, splitWhitespace('items flags'));
|
||||
if (armoireResp) resData.armoire = armoireResp;
|
||||
|
||||
if (req.v2 === true) {
|
||||
return resData;
|
||||
} else {
|
||||
return [
|
||||
resData,
|
||||
message,
|
||||
];
|
||||
}
|
||||
};
|
||||
70
common/script/ops/buyGear.js
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import _ from 'lodash';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
NotFound,
|
||||
} from '../libs/errors';
|
||||
import handleTwoHanded from '../fns/handleTwoHanded';
|
||||
import ultimateGear from '../fns/ultimateGear';
|
||||
|
||||
module.exports = function buyGear (user, req = {}, analytics) {
|
||||
let key = _.get(req, 'params.key');
|
||||
if (!key) throw new BadRequest(i18n.t('missingKeyParam', req.language));
|
||||
|
||||
let item = content.gear.flat[key];
|
||||
|
||||
if (!item) throw new NotFound(i18n.t('itemNotFound', {key}, req.language));
|
||||
|
||||
if (user.stats.gp < item.value) {
|
||||
throw new NotAuthorized(i18n.t('messageNotEnoughGold', req.language));
|
||||
}
|
||||
|
||||
if (item.canOwn && !item.canOwn(user)) {
|
||||
throw new NotAuthorized(i18n.t('cannotBuyItem', req.language));
|
||||
}
|
||||
|
||||
let message;
|
||||
|
||||
if (user.items.gear.owned[item.key]) {
|
||||
throw new NotAuthorized(i18n.t('equipmentAlreadyOwned', req.language));
|
||||
}
|
||||
|
||||
if (user.preferences.autoEquip) {
|
||||
user.items.gear.equipped[item.type] = item.key;
|
||||
message = handleTwoHanded(user, item, undefined, req);
|
||||
}
|
||||
|
||||
user.items.gear.owned[item.key] = true;
|
||||
|
||||
if (item.last) ultimateGear(user);
|
||||
|
||||
user.stats.gp -= item.value;
|
||||
|
||||
if (!message) {
|
||||
message = i18n.t('messageBought', {
|
||||
itemText: item.text(req.language),
|
||||
}, req.language);
|
||||
}
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
uuid: user._id,
|
||||
itemKey: key,
|
||||
acquireMethod: 'Gold',
|
||||
goldCost: item.value,
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
|
||||
if (req.v2 === true) {
|
||||
return _.pick(user, splitWhitespace('items achievements stats flags'));
|
||||
} else {
|
||||
return [
|
||||
_.pick(user, splitWhitespace('items achievements stats flags')),
|
||||
message,
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
@ -47,9 +47,9 @@ module.exports = function buyMysterySet (user, req = {}, analytics) {
|
|||
if (req.v2 === true) {
|
||||
return pickDeep(user, splitWhitespace('items purchased.plan.consecutive'));
|
||||
} else {
|
||||
return {
|
||||
data: pickDeep(user, splitWhitespace('items purchased.plan.consecutive')),
|
||||
message: i18n.t('hourglassPurchaseSet', req.language),
|
||||
};
|
||||
return [
|
||||
{ items: user.items, purchasedPlanConsecutive: user.purchased.plan.consecutive },
|
||||
i18n.t('hourglassPurchaseSet', req.language),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
48
common/script/ops/buyPotion.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
|
||||
module.exports = function buyPotion (user, req = {}, analytics) {
|
||||
let item = content.potion;
|
||||
|
||||
if (user.stats.gp < item.value) {
|
||||
throw new NotAuthorized(i18n.t('messageNotEnoughGold', req.language));
|
||||
}
|
||||
|
||||
if (item.canOwn && !item.canOwn(user)) {
|
||||
throw new NotAuthorized(i18n.t('cannotBuyItem', req.language));
|
||||
}
|
||||
|
||||
user.stats.hp += 15;
|
||||
if (user.stats.hp > 50) {
|
||||
user.stats.hp = 50;
|
||||
}
|
||||
|
||||
user.stats.gp -= item.value;
|
||||
|
||||
let message = i18n.t('messageBought', {
|
||||
itemText: item.text(req.language),
|
||||
}, req.language);
|
||||
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
uuid: user._id,
|
||||
itemKey: 'Potion',
|
||||
acquireMethod: 'Gold',
|
||||
goldCost: item.value,
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
|
||||
if (req.v2 === true) {
|
||||
return user.stats;
|
||||
} else {
|
||||
return [
|
||||
user.stats,
|
||||
message,
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
@ -40,11 +40,11 @@ module.exports = function buyQuest (user, req = {}, analytics) {
|
|||
if (req.v2 === true) {
|
||||
return user.items.quests;
|
||||
} else {
|
||||
return {
|
||||
data: user.items.quests,
|
||||
message: i18n.t('messageBought', {
|
||||
return [
|
||||
user.items.quests,
|
||||
i18n.t('messageBought', {
|
||||
itemText: item.text(req.language),
|
||||
}, req.language),
|
||||
};
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ module.exports = function buySpecialSpell (user, req = {}) {
|
|||
if (req.v2 === true) {
|
||||
return _.pick(user, splitWhitespace('items stats'));
|
||||
} else {
|
||||
return {
|
||||
data: _.pick(user, splitWhitespace('items stats')),
|
||||
message: i18n.t('messageBought', {
|
||||
return [
|
||||
_.pick(user, splitWhitespace('items stats')),
|
||||
i18n.t('messageBought', {
|
||||
itemText: item.text(req.language),
|
||||
}, req.language),
|
||||
};
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -71,8 +71,8 @@ module.exports = function changeClass (user, req = {}, analytics) {
|
|||
if (req.v2 === true) {
|
||||
return _.pick(user, splitWhitespace('stats flags items preferences'));
|
||||
} else {
|
||||
return {
|
||||
data: _.pick(user, splitWhitespace('stats flags items preferences')),
|
||||
};
|
||||
return [
|
||||
_.pick(user, splitWhitespace('stats flags items preferences')),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
module.exports = function clearPMs (user) {
|
||||
user.inbox.messages = {};
|
||||
user.markModified('inbox.messages');
|
||||
return user.inbox.messages;
|
||||
return [
|
||||
user.inbox.messages,
|
||||
];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,5 +3,7 @@ import _ from 'lodash';
|
|||
module.exports = function deletePM (user, req = {}) {
|
||||
delete user.inbox.messages[_.get(req, 'params.id')];
|
||||
user.markModified(`inbox.messages.${req.params.id}`);
|
||||
return user.inbox.messages;
|
||||
return [
|
||||
user.inbox.messages,
|
||||
];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,5 +4,7 @@ module.exports = function deleteWebhook (user, req) {
|
|||
delete user.preferences.webhooks[_.get(req, 'params.id')];
|
||||
user.markModified('preferences.webhooks');
|
||||
|
||||
return user.preferences.webhooks;
|
||||
return [
|
||||
user.preferences.webhooks,
|
||||
];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ module.exports = function disableClasses (user, req = {}) {
|
|||
if (req.v2 === true) {
|
||||
return _.pick(user, splitWhitespace('stats flags preferences'));
|
||||
} else {
|
||||
return {
|
||||
data: _.pick(user, splitWhitespace('stats flags preferences')),
|
||||
};
|
||||
return [
|
||||
_.pick(user, splitWhitespace('stats flags preferences')),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -58,14 +58,11 @@ module.exports = function equip (user, req = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
let res = {
|
||||
data: user.items,
|
||||
};
|
||||
if (message) res.message = message;
|
||||
|
||||
if (req.v2 === true) {
|
||||
return user.items;
|
||||
} else {
|
||||
let res = [user.items];
|
||||
if (message) res.push(message);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -94,9 +94,9 @@ module.exports = function feed (user, req = {}) {
|
|||
value: userPets[pet],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
data: userPets[pet],
|
||||
return [
|
||||
userPets[pet],
|
||||
message,
|
||||
};
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ module.exports = function hatch (user, req = {}) {
|
|||
if (req.v2 === true) {
|
||||
return user.items;
|
||||
} else {
|
||||
return {
|
||||
message: i18n.t('messageHatched', req.language),
|
||||
data: user.items,
|
||||
};
|
||||
return [
|
||||
user.items,
|
||||
i18n.t('messageHatched', req.language),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import content from '../content/index';
|
||||
import i18n from '../i18n';
|
||||
import _ from 'lodash';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import pickDeep from '../libs/pickDeep';
|
||||
import {
|
||||
BadRequest,
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
|
||||
module.exports = function purchaseHourglass (user, req = {}, analytics) {
|
||||
let key = _.get(req, 'params.key');
|
||||
|
|
@ -51,14 +50,12 @@ module.exports = function purchaseHourglass (user, req = {}, analytics) {
|
|||
});
|
||||
}
|
||||
|
||||
let res = {
|
||||
data: pickDeep(user, splitWhitespace('items purchased.plan.consecutive')),
|
||||
message: i18n.t('hourglassPurchase', req.language),
|
||||
};
|
||||
|
||||
if (req.v2 === true) {
|
||||
return res.data;
|
||||
return _.pick(user, splitWhitespace('items purchased.plan.consecutive'));
|
||||
} else {
|
||||
return res;
|
||||
return [
|
||||
{ items: user.items, purchasedPlanConsecutive: user.purchased.plan.consecutive },
|
||||
i18n.t('hourglassPurchase', req.language),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ import releasePets from './releasePets';
|
|||
import releaseMounts from './releaseMounts';
|
||||
import releaseBoth from './releaseBoth';
|
||||
import buy from './buy';
|
||||
import buyGear from './buyGear';
|
||||
import buyPotion from './buyPotion';
|
||||
import buyArmoire from './buyArmoire';
|
||||
import buyQuest from './buyQuest';
|
||||
import buyMysterySet from './buyMysterySet';
|
||||
import hourglassPurchase from './hourglassPurchase';
|
||||
|
|
@ -77,6 +80,9 @@ module.exports = {
|
|||
releaseMounts,
|
||||
releaseBoth,
|
||||
buy,
|
||||
buyGear,
|
||||
buyPotion,
|
||||
buyArmoire,
|
||||
buyQuest,
|
||||
buyMysterySet,
|
||||
hourglassPurchase,
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ module.exports = function openMysteryItem (user, req = {}, analytics) {
|
|||
if (req.v2 === true) {
|
||||
return user.items.gear.owned;
|
||||
} else {
|
||||
return {
|
||||
message: i18n.t('mysteryItemOpened', req.language),
|
||||
data: user.items.gear.owned,
|
||||
};
|
||||
return [
|
||||
user.items.gear.owned,
|
||||
i18n.t('mysteryItemOpened', req.language),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -54,12 +54,10 @@ module.exports = function purchase (user, req = {}, analytics) {
|
|||
});
|
||||
}
|
||||
|
||||
let response = {
|
||||
data: _.pick(user, splitWhitespace('stats balance')),
|
||||
message: i18n.t('plusOneGem'),
|
||||
};
|
||||
|
||||
return response;
|
||||
return [
|
||||
_.pick(user, splitWhitespace('stats balance')),
|
||||
i18n.t('plusOneGem'),
|
||||
];
|
||||
}
|
||||
|
||||
let acceptedTypes = ['eggs', 'hatchingPotions', 'food', 'quests', 'gear'];
|
||||
|
|
@ -119,14 +117,12 @@ module.exports = function purchase (user, req = {}, analytics) {
|
|||
});
|
||||
}
|
||||
|
||||
let response = {
|
||||
data: _.pick(user, splitWhitespace('items balance')),
|
||||
message: i18n.t('purchased', {type, key}),
|
||||
};
|
||||
|
||||
if (req.v2 === true) {
|
||||
return response.data;
|
||||
return _.pick(user, splitWhitespace('items balance'));
|
||||
} else {
|
||||
return response;
|
||||
return [
|
||||
_.pick(user, splitWhitespace('items balance')),
|
||||
i18n.t('purchased', {type, key}),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ module.exports = function readCard (user, req = {}) {
|
|||
if (req.v2 === true) {
|
||||
return _.pick(user, splitWhitespace('items.special flags.cardReceived'));
|
||||
} else {
|
||||
return {
|
||||
message: i18n.t('readCard', {cardType}, req.language),
|
||||
data: _.pick(user, splitWhitespace('items.special flags.cardReceived')),
|
||||
};
|
||||
return [
|
||||
{ specialItems: user.items.special, cardReceived: user.flags.cardReceived },
|
||||
i18n.t('readCard', {cardType}, req.language),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -98,14 +98,12 @@ module.exports = function rebirth (user, tasks = [], req = {}, analytics) {
|
|||
|
||||
user.stats.buffs = {};
|
||||
|
||||
let response = {
|
||||
data: user,
|
||||
message: i18n.t('rebirthComplete'),
|
||||
};
|
||||
|
||||
if (req.v2 === true) {
|
||||
return user;
|
||||
} else {
|
||||
return response;
|
||||
return [
|
||||
{user, tasks},
|
||||
i18n.t('rebirthComplete'),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -57,14 +57,12 @@ module.exports = function releaseBoth (user, req = {}, analytics) {
|
|||
user.achievements.triadBingoCount++;
|
||||
}
|
||||
|
||||
let response = {
|
||||
data: _.pick(user, splitWhitespace('achievements')),
|
||||
message: i18n.t('mountsAndPetsReleased'),
|
||||
};
|
||||
|
||||
if (req.v2 === true) {
|
||||
return user;
|
||||
} else {
|
||||
return response;
|
||||
return [
|
||||
_.pick(user, splitWhitespace('achievements items balance')),
|
||||
i18n.t('mountsAndPetsReleased'),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ import i18n from '../i18n';
|
|||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import _ from 'lodash';
|
||||
|
||||
module.exports = function releaseMounts (user, req = {}, analytics) {
|
||||
let mount;
|
||||
|
|
@ -34,14 +32,12 @@ module.exports = function releaseMounts (user, req = {}, analytics) {
|
|||
});
|
||||
}
|
||||
|
||||
let response = {
|
||||
data: _.pick(user, splitWhitespace('mounts')),
|
||||
message: i18n.t('mountsReleased'),
|
||||
};
|
||||
|
||||
if (req.v2 === true) {
|
||||
return user;
|
||||
} else {
|
||||
return response;
|
||||
return [
|
||||
user.items.mounts,
|
||||
i18n.t('mountsReleased'),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ import i18n from '../i18n';
|
|||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import _ from 'lodash';
|
||||
|
||||
module.exports = function releasePets (user, req = {}, analytics) {
|
||||
if (user.balance < 1) {
|
||||
|
|
@ -32,14 +30,12 @@ module.exports = function releasePets (user, req = {}, analytics) {
|
|||
});
|
||||
}
|
||||
|
||||
let response = {
|
||||
data: _.pick(user, splitWhitespace('user.items.pets')),
|
||||
message: i18n.t('petsReleased'),
|
||||
};
|
||||
|
||||
if (req.v2 === true) {
|
||||
return user;
|
||||
} else {
|
||||
return response;
|
||||
return [
|
||||
user.items.pets,
|
||||
i18n.t('petsReleased'),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -27,14 +27,12 @@ module.exports = function reroll (user, tasks = [], req = {}, analytics) {
|
|||
});
|
||||
}
|
||||
|
||||
let response = {
|
||||
data: {user, tasks},
|
||||
message: i18n.t('rerollComplete'),
|
||||
};
|
||||
|
||||
if (req.v2 === true) {
|
||||
return user;
|
||||
} else {
|
||||
return response;
|
||||
return [
|
||||
{user, tasks},
|
||||
i18n.t('rerollComplete'),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -19,14 +19,12 @@ module.exports = function reset (user, tasks = [], req = {}) {
|
|||
|
||||
resetGear(user);
|
||||
|
||||
let response = {
|
||||
data: {user, tasksToRemove},
|
||||
message: i18n.t('resetComplete'),
|
||||
};
|
||||
|
||||
if (req.v2 === true) {
|
||||
return user;
|
||||
} else {
|
||||
return response;
|
||||
return [
|
||||
{user, tasksToRemove},
|
||||
i18n.t('resetComplete'),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import _ from 'lodash';
|
|||
import {
|
||||
NotAuthorized,
|
||||
} from '../libs/errors';
|
||||
import splitWhitespace from '../libs/splitWhitespace';
|
||||
import randomVal from '../fns/randomVal';
|
||||
|
||||
module.exports = function revive (user, req = {}, analytics) {
|
||||
|
|
@ -97,14 +96,12 @@ module.exports = function revive (user, req = {}, analytics) {
|
|||
});
|
||||
}
|
||||
|
||||
let response = {
|
||||
data: _.pick(user, splitWhitespace('user.items')),
|
||||
message,
|
||||
};
|
||||
|
||||
if (req.v2 === true) {
|
||||
return user;
|
||||
} else {
|
||||
return response;
|
||||
return [
|
||||
user.items,
|
||||
message,
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -257,5 +257,5 @@ module.exports = function scoreTask (options = {}, req = {}) {
|
|||
}
|
||||
|
||||
updateStats(user, stats, req);
|
||||
return delta;
|
||||
return [delta];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -33,14 +33,12 @@ module.exports = function sell (user, req = {}) {
|
|||
user.items[type][key]--;
|
||||
user.stats.gp += content[type][key].value;
|
||||
|
||||
let response = {
|
||||
data: _.pick(user, splitWhitespace('stats items')),
|
||||
message: i18n.t('sold', {type, key}),
|
||||
};
|
||||
|
||||
if (req.v2 === true) {
|
||||
return response.data;
|
||||
return _.pick(user, splitWhitespace('stats items'));
|
||||
} else {
|
||||
return response;
|
||||
return [
|
||||
_.pick(user, splitWhitespace('stats items')),
|
||||
i18n.t('sold', {type, key}),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,10 +4,6 @@ module.exports = function sleep (user, req = {}) {
|
|||
if (req.v2 === true) {
|
||||
return {};
|
||||
} else {
|
||||
return {
|
||||
preferences: {
|
||||
sleep: user.preferences.sleep,
|
||||
},
|
||||
};
|
||||
return [user.preferences.sleep];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import {
|
|||
BadRequest,
|
||||
} from '../libs/errors';
|
||||
|
||||
// If item is already purchased -> equip it
|
||||
// Otherwise unlock it
|
||||
module.exports = function unlock (user, req = {}, analytics) {
|
||||
let path = _.get(req.query, 'path');
|
||||
|
||||
|
|
@ -14,9 +16,9 @@ module.exports = function unlock (user, req = {}, analytics) {
|
|||
}
|
||||
|
||||
let isFullSet = path.indexOf(',') !== -1;
|
||||
let cost;
|
||||
let isBackground = path.indexOf('background.') !== -1;
|
||||
|
||||
let cost;
|
||||
if (isBackground && isFullSet) {
|
||||
cost = 3.75;
|
||||
} else if (isBackground) {
|
||||
|
|
@ -27,61 +29,82 @@ module.exports = function unlock (user, req = {}, analytics) {
|
|||
cost = 0.5;
|
||||
}
|
||||
|
||||
let alreadyOwns = !isFullSet && _.get(user, `purchased.${path}`) === true;
|
||||
let setPaths;
|
||||
let alreadyOwns;
|
||||
|
||||
if (isFullSet) {
|
||||
setPaths = path.split(',');
|
||||
let alreadyOwnedItems = 0;
|
||||
|
||||
_.each(setPaths, singlePath => {
|
||||
if (_.get(user, `purchased.${singlePath}`) === true) {
|
||||
alreadyOwnedItems++;
|
||||
}
|
||||
});
|
||||
|
||||
if (alreadyOwnedItems === setPaths.length) {
|
||||
throw new NotAuthorized(i18n.t('alreadyUnlocked', req.language));
|
||||
} else if (alreadyOwnedItems > 0) {
|
||||
throw new NotAuthorized(i18n.t('alreadyUnlockedPart', req.language));
|
||||
}
|
||||
} else {
|
||||
alreadyOwns = _.get(user, `purchased.${path}`) === true;
|
||||
}
|
||||
|
||||
if ((!user.balance || user.balance < cost) && !alreadyOwns) {
|
||||
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
|
||||
}
|
||||
|
||||
if (isFullSet) {
|
||||
_.each(path.split(','), function markItemsAsPurchased (pathPart) {
|
||||
_.each(setPaths, function markItemsAsPurchased (pathPart) {
|
||||
if (path.indexOf('gear.') !== -1) {
|
||||
_.set(user, pathPart, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
_.set(user, `purchased.${pathPart}`, true);
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
if (alreadyOwns) {
|
||||
if (alreadyOwns) { // eslint-disable-line no-lonely-if
|
||||
let split = path.split('.');
|
||||
let value = split.pop();
|
||||
let key = split.join('.');
|
||||
if (key === 'background' && value === user.preferences.background) {
|
||||
value = '';
|
||||
}
|
||||
|
||||
_.set(user, `preferences.${key}`, value);
|
||||
|
||||
throw new NotAuthorized(i18n.t('alreadyUnlocked', req.language));
|
||||
} else {
|
||||
_.set(user, `purchased.${path}`, true);
|
||||
}
|
||||
_.set(user, `purchased.${path}`, true);
|
||||
}
|
||||
|
||||
if (path.indexOf('gear.') === -1) {
|
||||
user.markModified('purchased');
|
||||
if (!alreadyOwns) {
|
||||
if (path.indexOf('gear.') === -1) {
|
||||
user.markModified('purchased');
|
||||
}
|
||||
|
||||
user.balance -= cost;
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
uuid: user._id,
|
||||
itemKey: path,
|
||||
itemType: 'customization',
|
||||
acquireMethod: 'Gems',
|
||||
gemCost: cost / 0.25,
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
user.balance -= cost;
|
||||
let response = [
|
||||
_.pick(user, splitWhitespace('purchased preferences items')),
|
||||
];
|
||||
|
||||
if (analytics) {
|
||||
analytics.track('acquire item', {
|
||||
uuid: user._id,
|
||||
itemKey: path,
|
||||
itemType: 'customization',
|
||||
acquireMethod: 'Gems',
|
||||
gemCost: cost / 0.25,
|
||||
category: 'behavior',
|
||||
});
|
||||
}
|
||||
|
||||
let response = {
|
||||
data: _.pick(user, splitWhitespace('purchased preferences items')),
|
||||
message: i18n.t('unlocked'),
|
||||
};
|
||||
if (!alreadyOwns) response.push(i18n.t('unlocked', req.language));
|
||||
|
||||
if (req.v2 === true) {
|
||||
return response.data;
|
||||
return response[0];
|
||||
} else {
|
||||
return response;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,5 +22,5 @@ module.exports = function updateTask (task, req = {}) {
|
|||
|
||||
_.merge(task, _.omit(req.body, ['_id', 'id', 'type']));
|
||||
|
||||
return task;
|
||||
return [task];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,6 +15,6 @@ module.exports = function updateWebhook (user, req) {
|
|||
if (req.v2 === true) {
|
||||
return user.preferences.webhooks;
|
||||
} else {
|
||||
return user.preferences.webhooks[req.params.id];
|
||||
return [user.preferences.webhooks[req.params.id]];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,18 +6,10 @@
|
|||
*/
|
||||
(function(){
|
||||
var md = function () {
|
||||
marked.setOptions({
|
||||
gfm:true,
|
||||
pedantic:false,
|
||||
sanitize:true
|
||||
// callback for code highlighter
|
||||
// Uncomment this (and htljs.tabReplace below) if we add in highlight.js (http://www.heikura.me/#!/angularjs-markdown-directive)
|
||||
// highlight:function (code, lang) {
|
||||
// if (lang != undefined)
|
||||
// return hljs.highlight(lang, code).value;
|
||||
//
|
||||
// return hljs.highlightAuto(code).value;
|
||||
// }
|
||||
var remarkable = new Remarkable({
|
||||
// TODO: Add in code highlighting?
|
||||
// highlight: function (#<{(|str, lang|)}>#) { return ''; }
|
||||
linkify: true
|
||||
});
|
||||
|
||||
emoji.img_path = 'common/img/emoji/unicode/';
|
||||
|
|
@ -26,57 +18,60 @@
|
|||
if (markdown == undefined)
|
||||
return '';
|
||||
|
||||
markdown = marked(markdown);
|
||||
markdown = remarkable.render(markdown);
|
||||
markdown = emoji.replace_colons(markdown);
|
||||
markdown = emoji.replace_unified(markdown);
|
||||
|
||||
return markdown;
|
||||
};
|
||||
|
||||
// This was applie to marked, the old markdown library which has an xss exploit.
|
||||
// If we want this behavior again, we'll need to rewrite it.
|
||||
// ---
|
||||
// [nickgordon20131123] this hacky override wraps images with a link to the image in a new window, and also adds some classes in case we want to style
|
||||
marked.InlineLexer.prototype.outputLink = function(cap, link) {
|
||||
var escape = function(html, encode) {
|
||||
return html
|
||||
.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
};
|
||||
if (cap[0].charAt(0) !== '!') {
|
||||
return '<a class="markdown-link" target="_blank" href="'
|
||||
+ escape(link.href)
|
||||
+ '"'
|
||||
+ (link.title
|
||||
? ' title="'
|
||||
+ escape(link.title)
|
||||
+ '"'
|
||||
: '')
|
||||
+ '>'
|
||||
+ this.output(cap[1])
|
||||
+ '</a>';
|
||||
} else {
|
||||
return '<a class="markdown-img-link" target="_blank" href="'
|
||||
+ escape(link.href)
|
||||
+ '"'
|
||||
+ (link.title
|
||||
? ' title="'
|
||||
+ escape(link.title)
|
||||
+ '"'
|
||||
: '')
|
||||
+ '><img class="markdown-img" src="'
|
||||
+ escape(link.href)
|
||||
+ '" alt="'
|
||||
+ escape(cap[1])
|
||||
+ '"'
|
||||
+ (link.title
|
||||
? ' title="'
|
||||
+ escape(link.title)
|
||||
+ '"'
|
||||
: '')
|
||||
+ '></a>';
|
||||
}
|
||||
}
|
||||
// marked.InlineLexer.prototype.outputLink = function(cap, link) {
|
||||
// var escape = function(html, encode) {
|
||||
// return html
|
||||
// .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
|
||||
// .replace(/</g, '<')
|
||||
// .replace(/>/g, '>')
|
||||
// .replace(/"/g, '"')
|
||||
// .replace(/'/g, ''');
|
||||
// };
|
||||
// if (cap[0].charAt(0) !== '!') {
|
||||
// return '<a class="markdown-link" target="_blank" href="'
|
||||
// + escape(link.href)
|
||||
// + '"'
|
||||
// + (link.title
|
||||
// ? ' title="'
|
||||
// + escape(link.title)
|
||||
// + '"'
|
||||
// : '')
|
||||
// + '>'
|
||||
// + this.output(cap[1])
|
||||
// + '</a>';
|
||||
// } else {
|
||||
// return '<a class="markdown-img-link" target="_blank" href="'
|
||||
// + escape(link.href)
|
||||
// + '"'
|
||||
// + (link.title
|
||||
// ? ' title="'
|
||||
// + escape(link.title)
|
||||
// + '"'
|
||||
// : '')
|
||||
// + '><img class="markdown-img" src="'
|
||||
// + escape(link.href)
|
||||
// + '" alt="'
|
||||
// + escape(cap[1])
|
||||
// + '"'
|
||||
// + (link.title
|
||||
// ? ' title="'
|
||||
// + escape(link.title)
|
||||
// + '"'
|
||||
// : '')
|
||||
// + '></a>';
|
||||
// }
|
||||
// }
|
||||
|
||||
//hljs.tabReplace = ' ';
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ module.exports = function karmaConfig (config) {
|
|||
'website/public/bower_components/ngInfiniteScroll/build/ng-infinite-scroll.js',
|
||||
'website/public/bower_components/select2/select2.js',
|
||||
'website/public/bower_components/angular-ui-select2/src/select2.js',
|
||||
'website/public/bower_components/marked/lib/marked.js',
|
||||
'website/public/bower_components/remarkable/dist/remarkable.min.js',
|
||||
'website/public/bower_components/js-emoji/emoji.js',
|
||||
'common/dist/scripts/habitrpg-shared.js',
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@
|
|||
"js2xmlparser": "~1.0.0",
|
||||
"lodash": "^3.10.1",
|
||||
"loggly": "~1.0.8",
|
||||
"marked": "^0.3.5",
|
||||
"merge-stream": "^1.0.0",
|
||||
"method-override": "^2.3.5",
|
||||
"moment": "~2.10.6",
|
||||
|
|
@ -79,6 +78,7 @@
|
|||
"ps-tree": "^1.0.0",
|
||||
"push-notify": "^1.1.1",
|
||||
"q": "^1.4.1",
|
||||
"remarkable": "^1.6.2",
|
||||
"request": "~2.44.0",
|
||||
"run-sequence": "^1.1.4",
|
||||
"s3-upload-stream": "^1.0.6",
|
||||
|
|
|
|||
|
|
@ -44,6 +44,15 @@ describe('POST /group/:groupId/join', () => {
|
|||
expect(res.leader.profile.name).to.eql(user.profile.name);
|
||||
});
|
||||
|
||||
it('returns an error is user was already a member', async () => {
|
||||
await joiningUser.post(`/groups/${publicGuild._id}/join`);
|
||||
await expect(joiningUser.post(`/groups/${publicGuild._id}/join`)).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('userAlreadyInGroup'),
|
||||
});
|
||||
});
|
||||
|
||||
it('promotes joining member in a public empty guild to leader', async () => {
|
||||
await user.post(`/groups/${publicGuild._id}/leave`);
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,6 @@ describe('POST /user/allocate', () => {
|
|||
await user.sync();
|
||||
expect(user.stats.con).to.equal(1);
|
||||
expect(user.stats.points).to.equal(0);
|
||||
expect(res.stats.con).to.equal(1);
|
||||
expect(res.con).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,11 +18,7 @@ describe('POST /user/allocate-now', () => {
|
|||
let res = await user.post('/user/allocate-now');
|
||||
await user.sync();
|
||||
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
stats: user.stats,
|
||||
},
|
||||
});
|
||||
expect(res).to.eql(user.stats);
|
||||
expect(user.stats.points).to.equal(0);
|
||||
expect(user.stats.con).to.equal(9);
|
||||
expect(user.stats.int).to.equal(8);
|
||||
|
|
|
|||
|
|
@ -26,17 +26,26 @@ describe('POST /user/buy/:key', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('buys an item', async () => {
|
||||
it('buys a potion', async () => {
|
||||
await user.update({
|
||||
'stats.gp': 400,
|
||||
});
|
||||
|
||||
let potion = content.potion;
|
||||
let res = await user.post('/user/buy/potion');
|
||||
await user.sync();
|
||||
|
||||
expect(res.data).to.eql({
|
||||
items: JSON.parse(JSON.stringify(user.items)), // otherwise dates can't be compared
|
||||
achievements: user.achievements,
|
||||
stats: user.stats,
|
||||
flags: JSON.parse(JSON.stringify(user.flags)), // otherwise dates can't be compared
|
||||
});
|
||||
expect(user.stats.hp).to.equal(50);
|
||||
expect(res.data).to.eql(user.stats);
|
||||
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
|
||||
});
|
||||
|
||||
it('buys a piece of gear', async () => {
|
||||
let key = 'armor_warrior_1';
|
||||
|
||||
await user.post(`/user/buy/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(user.items.gear.owned).to.eql({ armor_warrior_1: true }); // eslint-disable-line camelcase
|
||||
});
|
||||
});
|
||||
|
|
|
|||
44
test/api/v3/integration/user/POST-user_buy_armoire.test.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import shared from '../../../../../common/script';
|
||||
|
||||
let content = shared.content;
|
||||
|
||||
describe('POST /user/buy-armoire', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
'stats.hp': 40,
|
||||
});
|
||||
});
|
||||
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('returns an error if user does not have enough gold', async () => {
|
||||
await expect(user.post('/user/buy-potion'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('messageNotEnoughGold'),
|
||||
});
|
||||
});
|
||||
|
||||
xit('buys a piece of armoire', async () => {
|
||||
await user.update({
|
||||
'stats.gp': 400,
|
||||
});
|
||||
|
||||
let potion = content.potion;
|
||||
let res = await user.post('/user/buy-potion');
|
||||
await user.sync();
|
||||
|
||||
expect(user.stats.hp).to.equal(50);
|
||||
expect(res.data).to.eql({
|
||||
stats: user.stats,
|
||||
});
|
||||
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
|
||||
});
|
||||
});
|
||||
34
test/api/v3/integration/user/POST-user_buy_gear.test.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('POST /user/buy-gear/:key', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
'stats.gp': 400,
|
||||
});
|
||||
});
|
||||
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('returns an error if the item is not found', async () => {
|
||||
await expect(user.post('/user/buy-gear/notExisting'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('itemNotFound', {key: 'notExisting'}),
|
||||
});
|
||||
});
|
||||
|
||||
it('buys a piece of gear', async () => {
|
||||
let key = 'armor_warrior_1';
|
||||
|
||||
await user.post(`/user/buy-gear/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(user.items.gear.owned).to.eql({ armor_warrior_1: true }); // eslint-disable-line camelcase
|
||||
});
|
||||
});
|
||||
|
|
@ -31,11 +31,7 @@ describe('POST /user/buy-mystery-set/:key', () => {
|
|||
|
||||
expect(res.data).to.eql({
|
||||
items: JSON.parse(JSON.stringify(user.items)), // otherwise dates can't be compared
|
||||
purchased: {
|
||||
plan: {
|
||||
consecutive: user.purchased.plan.consecutive,
|
||||
},
|
||||
},
|
||||
purchasedPlanConsecutive: user.purchased.plan.consecutive,
|
||||
});
|
||||
expect(res.message).to.equal(t('hourglassPurchaseSet'));
|
||||
});
|
||||
|
|
|
|||
42
test/api/v3/integration/user/POST-user_buy_potion.test.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import shared from '../../../../../common/script';
|
||||
|
||||
let content = shared.content;
|
||||
|
||||
describe('POST /user/buy-potion', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
'stats.hp': 40,
|
||||
});
|
||||
});
|
||||
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('returns an error if user does not have enough gold', async () => {
|
||||
await expect(user.post('/user/buy-potion'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('messageNotEnoughGold'),
|
||||
});
|
||||
});
|
||||
|
||||
it('buys a potion', async () => {
|
||||
await user.update({
|
||||
'stats.gp': 400,
|
||||
});
|
||||
|
||||
let potion = content.potion;
|
||||
let res = await user.post('/user/buy-potion');
|
||||
await user.sync();
|
||||
|
||||
expect(user.stats.hp).to.equal(50);
|
||||
expect(res.data).to.eql(user.stats);
|
||||
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
|
||||
});
|
||||
});
|
||||
|
|
@ -18,13 +18,13 @@ describe('POST /user/change-class', () => {
|
|||
let res = await user.post('/user/change-class?class=rogue');
|
||||
await user.sync();
|
||||
|
||||
expect(res).to.eql({
|
||||
data: JSON.parse(JSON.stringify({
|
||||
expect(res).to.eql(JSON.parse(
|
||||
JSON.stringify({
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
})),
|
||||
});
|
||||
})
|
||||
));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ describe('POST /user/disable-classes', () => {
|
|||
let res = await user.post('/user/disable-classes');
|
||||
await user.sync();
|
||||
|
||||
expect(res).to.eql({
|
||||
data: JSON.parse(JSON.stringify({
|
||||
expect(res).to.eql(JSON.parse(
|
||||
JSON.stringify({
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
})),
|
||||
});
|
||||
})
|
||||
));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -35,8 +35,6 @@ describe('POST /user/equip/:type/:key', () => {
|
|||
let res = await user.post('/user/equip/equipped/weapon_warrior_2');
|
||||
await user.sync();
|
||||
|
||||
expect(res).to.eql({
|
||||
data: JSON.parse(JSON.stringify(user.items)),
|
||||
});
|
||||
expect(res).to.eql(JSON.parse(JSON.stringify(user.items)));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,16 +13,12 @@ describe('POST /user/sleep', () => {
|
|||
|
||||
it('toggles sleep status', async () => {
|
||||
let res = await user.post('/user/sleep');
|
||||
expect(res).to.eql({
|
||||
preferences: {sleep: true},
|
||||
});
|
||||
expect(res).to.eql(true);
|
||||
await user.sync();
|
||||
expect(user.preferences.sleep).to.be.true;
|
||||
|
||||
let res2 = await user.post('/user/sleep');
|
||||
expect(res2).to.eql({
|
||||
preferences: {sleep: false},
|
||||
});
|
||||
expect(res2).to.eql(false);
|
||||
await user.sync();
|
||||
expect(user.preferences.sleep).to.be.false;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ describe('POST /user/reset-password', async () => {
|
|||
let response = await user.post(endpoint, {
|
||||
email: user.auth.local.email,
|
||||
});
|
||||
expect(response).to.eql({ message: t('passwordReset') });
|
||||
expect(response).to.eql({ data: {}, message: t('passwordReset') });
|
||||
await user.sync();
|
||||
expect(user.auth.local.hashed_password).to.not.eql(previousPassword);
|
||||
});
|
||||
|
|
@ -25,7 +25,7 @@ describe('POST /user/reset-password', async () => {
|
|||
let response = await user.post(endpoint, {
|
||||
email: 'nonExistent@email.com',
|
||||
});
|
||||
expect(response).to.eql({ message: t('passwordReset') });
|
||||
expect(response).to.eql({ data: {}, message: t('passwordReset') });
|
||||
});
|
||||
|
||||
it('errors if email is not provided', async () => {
|
||||
|
|
@ -36,4 +36,3 @@ describe('POST /user/reset-password', async () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,21 @@ describe('response middleware', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('can be passed a third parameter to be used as optional message', () => {
|
||||
responseMiddleware(req, res, next);
|
||||
res.respond(200, {field: 1}, 'hello');
|
||||
|
||||
expect(res.status).to.be.calledOnce;
|
||||
expect(res.json).to.be.calledOnce;
|
||||
|
||||
expect(res.status).to.be.calledWith(200);
|
||||
expect(res.json).to.be.calledWith({
|
||||
success: true,
|
||||
data: {field: 1},
|
||||
message: 'hello',
|
||||
});
|
||||
});
|
||||
|
||||
it('treats status >= 400 as failures', () => {
|
||||
responseMiddleware(req, res, next);
|
||||
res.respond(403, {field: 1});
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ describe('Challenge Model', () => {
|
|||
};
|
||||
|
||||
Tasks.Task.sanitize(req.body);
|
||||
_.assign(task, common.ops.updateTask(task.toObject(), req));
|
||||
_.assign(task, common.ops.updateTask(task.toObject(), req)[0]);
|
||||
|
||||
await challenge.updateTask(task);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ describe('shared.ops.addPushDevice', () => {
|
|||
});
|
||||
|
||||
it('adds a push device', () => {
|
||||
let response = addPushDevice(user, {body: {regId, type}});
|
||||
let [, message] = addPushDevice(user, {body: {regId, type}});
|
||||
|
||||
expect(response.message).to.equal(i18n.t('pushDeviceAdded'));
|
||||
expect(message).to.equal(i18n.t('pushDeviceAdded'));
|
||||
expect(user.pushDevices[0].type).to.equal(type);
|
||||
expect(user.pushDevices[0].regId).to.equal(regId);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,17 +18,13 @@ describe('shared.ops.allocateNow', () => {
|
|||
user.stats.str = 9;
|
||||
user.preferences.allocationMode = 'flat';
|
||||
|
||||
let res = allocateNow(user);
|
||||
let [data] = allocateNow(user);
|
||||
|
||||
expect(user.stats.points).to.equal(0);
|
||||
expect(user.stats.con).to.equal(9);
|
||||
expect(user.stats.int).to.equal(8);
|
||||
expect(user.stats.per).to.equal(9);
|
||||
expect(user.stats.str).to.equal(9);
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
stats: user.stats,
|
||||
},
|
||||
});
|
||||
expect(data).to.eql(user.stats);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ describe('shared.ops.blockUser', () => {
|
|||
});
|
||||
|
||||
it('blocks user', () => {
|
||||
let result = blockUser(user, { params: { uuid: blockedUser._id } });
|
||||
let [result] = blockUser(user, { params: { uuid: blockedUser._id } });
|
||||
expect(user.inbox.blocks).to.eql([blockedUser._id]);
|
||||
expect(result).to.eql([blockedUser._id]);
|
||||
result = blockUser(user, { params: { uuid: blockedUser2._id } });
|
||||
[result] = blockUser(user, { params: { uuid: blockedUser2._id } });
|
||||
expect(user.inbox.blocks).to.eql([blockedUser._id, blockedUser2._id]);
|
||||
expect(result).to.eql([blockedUser._id, blockedUser2._id]);
|
||||
});
|
||||
|
|
@ -37,7 +37,7 @@ describe('shared.ops.blockUser', () => {
|
|||
it('blocks, then unblocks user', () => {
|
||||
blockUser(user, { params: { uuid: blockedUser._id } });
|
||||
expect(user.inbox.blocks).to.eql([blockedUser._id]);
|
||||
let result = blockUser(user, { params: { uuid: blockedUser._id } });
|
||||
let [result] = blockUser(user, { params: { uuid: blockedUser._id } });
|
||||
expect(user.inbox.blocks).to.eql([]);
|
||||
expect(result).to.eql([]);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,15 +1,10 @@
|
|||
/* eslint-disable camelcase */
|
||||
|
||||
import sinon from 'sinon'; // eslint-disable-line no-shadow
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import count from '../../../common/script/count';
|
||||
import buy from '../../../common/script/ops/buy';
|
||||
import shared from '../../../common/script';
|
||||
import content from '../../../common/script/content/index';
|
||||
import {
|
||||
NotAuthorized,
|
||||
BadRequest,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
|
||||
|
|
@ -30,277 +25,27 @@ describe('shared.ops.buy', () => {
|
|||
},
|
||||
stats: { gp: 200 },
|
||||
});
|
||||
|
||||
sinon.stub(shared.fns, 'randomVal');
|
||||
sinon.stub(shared.fns, 'predictableRandom');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
shared.fns.randomVal.restore();
|
||||
shared.fns.predictableRandom.restore();
|
||||
it('returns error when key is not provided', (done) => {
|
||||
try {
|
||||
buy(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(BadRequest);
|
||||
expect(err.message).to.equal(i18n.t('missingKeyParam'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
context('Potion', () => {
|
||||
it('recovers 15 hp', () => {
|
||||
user.stats.hp = 30;
|
||||
buy(user, {params: {key: 'potion'}});
|
||||
expect(user.stats.hp).to.eql(45);
|
||||
});
|
||||
|
||||
it('does not increase hp above 50', () => {
|
||||
user.stats.hp = 45;
|
||||
buy(user, {params: {key: 'potion'}});
|
||||
expect(user.stats.hp).to.eql(50);
|
||||
});
|
||||
|
||||
it('deducts 25 gp', () => {
|
||||
user.stats.hp = 45;
|
||||
buy(user, {params: {key: 'potion'}});
|
||||
|
||||
expect(user.stats.gp).to.eql(175);
|
||||
});
|
||||
|
||||
it('does not purchase if not enough gp', (done) => {
|
||||
user.stats.hp = 45;
|
||||
user.stats.gp = 5;
|
||||
try {
|
||||
buy(user, {params: {key: 'potion'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
expect(user.stats.hp).to.eql(45);
|
||||
expect(user.stats.gp).to.eql(5);
|
||||
|
||||
done();
|
||||
}
|
||||
});
|
||||
it('recovers 15 hp', () => {
|
||||
user.stats.hp = 30;
|
||||
buy(user, {params: {key: 'potion'}});
|
||||
expect(user.stats.hp).to.eql(45);
|
||||
});
|
||||
|
||||
context('Gear', () => {
|
||||
it('adds equipment to inventory', () => {
|
||||
user.stats.gp = 31;
|
||||
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, armor_warrior_1: true });
|
||||
});
|
||||
|
||||
it('deducts gold from user', () => {
|
||||
user.stats.gp = 31;
|
||||
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.stats.gp).to.eql(1);
|
||||
});
|
||||
|
||||
it('auto equips equipment if user has auto-equip preference turned on', () => {
|
||||
user.stats.gp = 31;
|
||||
user.preferences.autoEquip = true;
|
||||
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('armor', 'armor_warrior_1');
|
||||
});
|
||||
|
||||
it('buys equipment but does not auto-equip', () => {
|
||||
user.stats.gp = 31;
|
||||
user.preferences.autoEquip = false;
|
||||
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.equipped.property).to.not.equal('armor_warrior_1');
|
||||
});
|
||||
|
||||
// TODO after user.ops.equip is done
|
||||
xit('removes one-handed weapon and shield if auto-equip is on and a two-hander is bought', () => {
|
||||
user.stats.gp = 100;
|
||||
user.preferences.autoEquip = true;
|
||||
buy(user, {params: {key: 'shield_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'shield_warrior_1'}});
|
||||
buy(user, {params: {key: 'weapon_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'weapon_warrior_1'}});
|
||||
|
||||
buy(user, {params: {key: 'weapon_wizard_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('shield', 'shield_base_0');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_wizard_1');
|
||||
});
|
||||
|
||||
// TODO after user.ops.equip is done
|
||||
xit('buys two-handed equipment but does not automatically remove sword or shield', () => {
|
||||
user.stats.gp = 100;
|
||||
user.preferences.autoEquip = false;
|
||||
buy(user, {params: {key: 'shield_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'shield_warrior_1'}});
|
||||
buy(user, {params: {key: 'weapon_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'weapon_warrior_1'}});
|
||||
|
||||
buy(user, {params: {key: 'weapon_wizard_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('shield', 'shield_warrior_1');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_warrior_1');
|
||||
});
|
||||
|
||||
it('does not buy equipment without enough Gold', (done) => {
|
||||
user.stats.gp = 20;
|
||||
|
||||
try {
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
expect(user.items.gear.owned).to.not.have.property('armor_warrior_1');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
context('Enchanted Armoire', () => {
|
||||
let YIELD_EQUIPMENT = 0.5;
|
||||
let YIELD_FOOD = 0.7;
|
||||
let YIELD_EXP = 0.9;
|
||||
|
||||
let fullArmoire = {};
|
||||
|
||||
_(content.gearTypes).each((type) => {
|
||||
_(content.gear.tree[type].armoire).each((gearObject) => {
|
||||
let armoireKey = gearObject.key;
|
||||
|
||||
fullArmoire[armoireKey] = true;
|
||||
}).value();
|
||||
}).value();
|
||||
|
||||
beforeEach(() => {
|
||||
user.achievements.ultimateGearSets = { rogue: true };
|
||||
user.flags.armoireOpened = true;
|
||||
user.stats.exp = 0;
|
||||
user.items.food = {};
|
||||
});
|
||||
|
||||
context('failure conditions', () => {
|
||||
it('does not open if user does not have enough gold', (done) => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.stats.gp = 50;
|
||||
|
||||
try {
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not open without Ultimate Gear achievement', (done) => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.achievements.ultimateGearSets = {healer: false, wizard: false, rogue: false, warrior: false};
|
||||
|
||||
try {
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('cannoyBuyItem'));
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
context('non-gear awards', () => {
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives Experience', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EXP);
|
||||
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(46);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives food', () => {
|
||||
let honey = content.food.Honey;
|
||||
|
||||
shared.fns.randomVal.returns(honey);
|
||||
shared.fns.predictableRandom.returns(YIELD_FOOD);
|
||||
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.eql({Honey: 1});
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('does not give equipment if all equipment has been found', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.items.gear.owned = fullArmoire;
|
||||
user.stats.gp = 150;
|
||||
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql(fullArmoire);
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(0);
|
||||
|
||||
expect(user.stats.exp).to.eql(30);
|
||||
expect(user.stats.gp).to.eql(50);
|
||||
});
|
||||
});
|
||||
|
||||
context('gear awards', () => {
|
||||
beforeEach(() => {
|
||||
let shield = content.gear.tree.shield.armoire.gladiatorShield;
|
||||
|
||||
shared.fns.randomVal.returns(shield);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('always drops equipment the first time', () => {
|
||||
delete user.flags.armoireOpened;
|
||||
shared.fns.predictableRandom.returns(YIELD_EXP);
|
||||
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({
|
||||
weapon_warrior_0: true,
|
||||
shield_armoire_gladiatorShield: true,
|
||||
});
|
||||
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(_.size(fullArmoire) - 1);
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives more equipment', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.items.gear.owned = {
|
||||
weapon_warrior_0: true,
|
||||
head_armoire_hornedIronHelm: true,
|
||||
};
|
||||
user.stats.gp = 200;
|
||||
|
||||
buy(user, {params: {key: 'armoire'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true, shield_armoire_gladiatorShield: true, head_armoire_hornedIronHelm: true});
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(_.size(fullArmoire) - 2);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
});
|
||||
it('adds equipment to inventory', () => {
|
||||
user.stats.gp = 31;
|
||||
buy(user, {params: {key: 'armor_warrior_1'}});
|
||||
expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, armor_warrior_1: true });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
187
test/common/ops/buyArmoire.js
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
/* eslint-disable camelcase */
|
||||
|
||||
import sinon from 'sinon'; // eslint-disable-line no-shadow
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import count from '../../../common/script/count';
|
||||
import buyArmoire from '../../../common/script/ops/buyArmoire';
|
||||
import shared from '../../../common/script';
|
||||
import content from '../../../common/script/content/index';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
|
||||
describe('shared.ops.buyArmoire', () => {
|
||||
let user;
|
||||
let YIELD_EQUIPMENT = 0.5;
|
||||
let YIELD_FOOD = 0.7;
|
||||
let YIELD_EXP = 0.9;
|
||||
|
||||
let fullArmoire = {};
|
||||
|
||||
_(content.gearTypes).each((type) => {
|
||||
_(content.gear.tree[type].armoire).each((gearObject) => {
|
||||
let armoireKey = gearObject.key;
|
||||
|
||||
fullArmoire[armoireKey] = true;
|
||||
}).value();
|
||||
}).value();
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser({
|
||||
items: {
|
||||
gear: {
|
||||
owned: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
equipped: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
stats: { gp: 200 },
|
||||
});
|
||||
|
||||
user.achievements.ultimateGearSets = { rogue: true };
|
||||
user.flags.armoireOpened = true;
|
||||
user.stats.exp = 0;
|
||||
user.items.food = {};
|
||||
|
||||
sinon.stub(shared.fns, 'randomVal');
|
||||
sinon.stub(shared.fns, 'predictableRandom');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
shared.fns.randomVal.restore();
|
||||
shared.fns.predictableRandom.restore();
|
||||
});
|
||||
|
||||
context('failure conditions', () => {
|
||||
it('does not open if user does not have enough gold', (done) => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.stats.gp = 50;
|
||||
|
||||
try {
|
||||
buyArmoire(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not open without Ultimate Gear achievement', (done) => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.achievements.ultimateGearSets = {healer: false, wizard: false, rogue: false, warrior: false};
|
||||
|
||||
try {
|
||||
buyArmoire(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('cannotBuyItem'));
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
context('non-gear awards', () => {
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives Experience', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EXP);
|
||||
|
||||
buyArmoire(user);
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(46);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives food', () => {
|
||||
let honey = content.food.Honey;
|
||||
|
||||
shared.fns.randomVal.returns(honey);
|
||||
shared.fns.predictableRandom.returns(YIELD_FOOD);
|
||||
|
||||
buyArmoire(user);
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true});
|
||||
expect(user.items.food).to.eql({Honey: 1});
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('does not give equipment if all equipment has been found', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.items.gear.owned = fullArmoire;
|
||||
user.stats.gp = 150;
|
||||
|
||||
buyArmoire(user);
|
||||
|
||||
expect(user.items.gear.owned).to.eql(fullArmoire);
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(0);
|
||||
|
||||
expect(user.stats.exp).to.eql(30);
|
||||
expect(user.stats.gp).to.eql(50);
|
||||
});
|
||||
});
|
||||
|
||||
context('gear awards', () => {
|
||||
beforeEach(() => {
|
||||
let shield = content.gear.tree.shield.armoire.gladiatorShield;
|
||||
|
||||
shared.fns.randomVal.returns(shield);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('always drops equipment the first time', () => {
|
||||
delete user.flags.armoireOpened;
|
||||
shared.fns.predictableRandom.returns(YIELD_EXP);
|
||||
|
||||
buyArmoire(user);
|
||||
|
||||
expect(user.items.gear.owned).to.eql({
|
||||
weapon_warrior_0: true,
|
||||
shield_armoire_gladiatorShield: true,
|
||||
});
|
||||
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(_.size(fullArmoire) - 1);
|
||||
expect(user.items.food).to.be.empty;
|
||||
expect(user.stats.exp).to.eql(0);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
|
||||
// Skipped because can't stub predictableRandom correctly
|
||||
xit('gives more equipment', () => {
|
||||
shared.fns.predictableRandom.returns(YIELD_EQUIPMENT);
|
||||
user.items.gear.owned = {
|
||||
weapon_warrior_0: true,
|
||||
head_armoire_hornedIronHelm: true,
|
||||
};
|
||||
user.stats.gp = 200;
|
||||
|
||||
buyArmoire(user);
|
||||
|
||||
expect(user.items.gear.owned).to.eql({weapon_warrior_0: true, shield_armoire_gladiatorShield: true, head_armoire_hornedIronHelm: true});
|
||||
let armoireCount = count.remainingGearInSet(user.items.gear.owned, 'armoire');
|
||||
|
||||
expect(armoireCount).to.eql(_.size(fullArmoire) - 2);
|
||||
expect(user.stats.gp).to.eql(100);
|
||||
});
|
||||
});
|
||||
});
|
||||
132
test/common/ops/buyGear.js
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/* eslint-disable camelcase */
|
||||
|
||||
import sinon from 'sinon'; // eslint-disable-line no-shadow
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import buyGear from '../../../common/script/ops/buyGear';
|
||||
import shared from '../../../common/script';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
|
||||
describe('shared.ops.buyGear', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser({
|
||||
items: {
|
||||
gear: {
|
||||
owned: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
equipped: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
stats: { gp: 200 },
|
||||
});
|
||||
|
||||
sinon.stub(shared.fns, 'randomVal');
|
||||
sinon.stub(shared.fns, 'predictableRandom');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
shared.fns.randomVal.restore();
|
||||
shared.fns.predictableRandom.restore();
|
||||
});
|
||||
|
||||
context('Gear', () => {
|
||||
it('adds equipment to inventory', () => {
|
||||
user.stats.gp = 31;
|
||||
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.owned).to.eql({ weapon_warrior_0: true, armor_warrior_1: true });
|
||||
});
|
||||
|
||||
it('deducts gold from user', () => {
|
||||
user.stats.gp = 31;
|
||||
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.stats.gp).to.eql(1);
|
||||
});
|
||||
|
||||
it('auto equips equipment if user has auto-equip preference turned on', () => {
|
||||
user.stats.gp = 31;
|
||||
user.preferences.autoEquip = true;
|
||||
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('armor', 'armor_warrior_1');
|
||||
});
|
||||
|
||||
it('buyGears equipment but does not auto-equip', () => {
|
||||
user.stats.gp = 31;
|
||||
user.preferences.autoEquip = false;
|
||||
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
expect(user.items.gear.equipped.property).to.not.equal('armor_warrior_1');
|
||||
});
|
||||
|
||||
it('does not buyGear equipment twice', (done) => {
|
||||
user.stats.gp = 62;
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
|
||||
try {
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('equipmentAlreadyOwned'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO after user.ops.equip is done
|
||||
xit('removes one-handed weapon and shield if auto-equip is on and a two-hander is bought', () => {
|
||||
user.stats.gp = 100;
|
||||
user.preferences.autoEquip = true;
|
||||
buyGear(user, {params: {key: 'shield_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'shield_warrior_1'}});
|
||||
buyGear(user, {params: {key: 'weapon_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'weapon_warrior_1'}});
|
||||
|
||||
buyGear(user, {params: {key: 'weapon_wizard_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('shield', 'shield_base_0');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_wizard_1');
|
||||
});
|
||||
|
||||
// TODO after user.ops.equip is done
|
||||
xit('buyGears two-handed equipment but does not automatically remove sword or shield', () => {
|
||||
user.stats.gp = 100;
|
||||
user.preferences.autoEquip = false;
|
||||
buyGear(user, {params: {key: 'shield_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'shield_warrior_1'}});
|
||||
buyGear(user, {params: {key: 'weapon_warrior_1'}});
|
||||
user.ops.equip({params: {key: 'weapon_warrior_1'}});
|
||||
|
||||
buyGear(user, {params: {key: 'weapon_wizard_1'}});
|
||||
|
||||
expect(user.items.gear.equipped).to.have.property('shield', 'shield_warrior_1');
|
||||
expect(user.items.gear.equipped).to.have.property('weapon', 'weapon_warrior_1');
|
||||
});
|
||||
|
||||
it('does not buyGear equipment without enough Gold', (done) => {
|
||||
user.stats.gp = 20;
|
||||
|
||||
try {
|
||||
buyGear(user, {params: {key: 'armor_warrior_1'}});
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
expect(user.items.gear.owned).to.not.have.property('armor_warrior_1');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
65
test/common/ops/buyPotion.js
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/* eslint-disable camelcase */
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import buyPotion from '../../../common/script/ops/buyPotion';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../../common/script/libs/errors';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
|
||||
describe('shared.ops.buyPotion', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser({
|
||||
items: {
|
||||
gear: {
|
||||
owned: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
equipped: {
|
||||
weapon_warrior_0: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
stats: { gp: 200 },
|
||||
});
|
||||
});
|
||||
|
||||
context('Potion', () => {
|
||||
it('recovers 15 hp', () => {
|
||||
user.stats.hp = 30;
|
||||
buyPotion(user);
|
||||
expect(user.stats.hp).to.eql(45);
|
||||
});
|
||||
|
||||
it('does not increase hp above 50', () => {
|
||||
user.stats.hp = 45;
|
||||
buyPotion(user);
|
||||
expect(user.stats.hp).to.eql(50);
|
||||
});
|
||||
|
||||
it('deducts 25 gp', () => {
|
||||
user.stats.hp = 45;
|
||||
buyPotion(user);
|
||||
|
||||
expect(user.stats.gp).to.eql(175);
|
||||
});
|
||||
|
||||
it('does not purchase if not enough gp', (done) => {
|
||||
user.stats.hp = 45;
|
||||
user.stats.gp = 5;
|
||||
try {
|
||||
buyPotion(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('messageNotEnoughGold'));
|
||||
expect(user.stats.hp).to.eql(45);
|
||||
expect(user.stats.gp).to.eql(5);
|
||||
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -60,7 +60,7 @@ describe('shared.ops.buySpecialSpell', () => {
|
|||
user.stats.gp = 11;
|
||||
let item = content.special.thankyou;
|
||||
|
||||
let res = buySpecialSpell(user, {
|
||||
let [data, message] = buySpecialSpell(user, {
|
||||
params: {
|
||||
key: 'thankyou',
|
||||
},
|
||||
|
|
@ -68,11 +68,11 @@ describe('shared.ops.buySpecialSpell', () => {
|
|||
|
||||
expect(user.stats.gp).to.equal(1);
|
||||
expect(user.items.special.thankyou).to.equal(1);
|
||||
expect(res.data).to.eql({
|
||||
expect(data).to.eql({
|
||||
items: user.items,
|
||||
stats: user.stats,
|
||||
});
|
||||
expect(res.message).to.equal(i18n.t('messageBought', {
|
||||
expect(message).to.equal(i18n.t('messageBought', {
|
||||
itemText: item.text(),
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -46,14 +46,12 @@ describe('shared.ops.changeClass', () => {
|
|||
user.stats.class = 'healer';
|
||||
user.items.gear.owned.armor_rogue_1 = true; // eslint-disable-line camelcase
|
||||
|
||||
let res = changeClass(user, {query: {class: 'rogue'}});
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
},
|
||||
let [data] = changeClass(user, {query: {class: 'rogue'}});
|
||||
expect(data).to.eql({
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
});
|
||||
|
||||
expect(user.stats.class).to.equal('rogue');
|
||||
|
|
@ -80,14 +78,12 @@ describe('shared.ops.changeClass', () => {
|
|||
user.stats.int = 4;
|
||||
user.flags.classSelected = true;
|
||||
|
||||
let res = changeClass(user);
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
},
|
||||
let [data] = changeClass(user);
|
||||
expect(data).to.eql({
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
});
|
||||
|
||||
expect(user.preferences.disableClasses).to.be.false;
|
||||
|
|
@ -122,14 +118,12 @@ describe('shared.ops.changeClass', () => {
|
|||
user.stats.int = 4;
|
||||
user.flags.classSelected = true;
|
||||
|
||||
let res = changeClass(user);
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
},
|
||||
let [data] = changeClass(user);
|
||||
expect(data).to.eql({
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
items: user.items,
|
||||
});
|
||||
|
||||
expect(user.balance).to.equal(0.25);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ describe('shared.ops.clearPMs', () => {
|
|||
|
||||
it('clears messages', () => {
|
||||
expect(user.inbox.messages).to.not.eql({});
|
||||
let result = clearPMs(user);
|
||||
let [result] = clearPMs(user);
|
||||
expect(user.inbox.messages).to.eql({});
|
||||
expect(result).to.eql({});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import {
|
|||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
|
||||
describe('shared.ops.clearPMs', () => {
|
||||
describe('shared.ops.deletePM', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
@ -13,7 +13,7 @@ describe('shared.ops.clearPMs', () => {
|
|||
|
||||
it('delete message', () => {
|
||||
expect(user.inbox.messages).to.not.eql({ second: 'message' });
|
||||
let response = deletePM(user, { params: { id: 'first' } });
|
||||
let [response] = deletePM(user, { params: { id: 'first' } });
|
||||
expect(user.inbox.messages).to.eql({ second: 'message' });
|
||||
expect(response).to.eql({ second: 'message' });
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ describe('shared.ops.deleteWebhook', () => {
|
|||
|
||||
it('succeeds', () => {
|
||||
user.preferences.webhooks = { 'some-id': {}, 'another-id': {} };
|
||||
let res = deleteWebhook(user, req);
|
||||
let [data] = deleteWebhook(user, req);
|
||||
expect(user.preferences.webhooks).to.eql({'another-id': {}});
|
||||
expect(res).to.equal(user.preferences.webhooks);
|
||||
expect(data).to.equal(user.preferences.webhooks);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,13 +18,11 @@ describe('shared.ops.disableClasses', () => {
|
|||
user.preferences.autoAllocate = false;
|
||||
user.stats.points = 2;
|
||||
|
||||
let res = disableClasses(user);
|
||||
expect(res).to.eql({
|
||||
data: {
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
},
|
||||
let [data] = disableClasses(user);
|
||||
expect(data).to.eql({
|
||||
preferences: user.preferences,
|
||||
stats: user.stats,
|
||||
flags: user.flags,
|
||||
});
|
||||
|
||||
expect(user.stats.class).to.equal('warrior');
|
||||
|
|
|
|||
|
|
@ -37,20 +37,20 @@ describe('shared.ops.equip', () => {
|
|||
equip(user, {params: {key: 'weapon_warrior_1'}});
|
||||
|
||||
// one-handed to one-handed
|
||||
let res = equip(user, {params: {key: 'weapon_warrior_2'}});
|
||||
expect(res.message).to.not.exists;
|
||||
let [, message] = equip(user, {params: {key: 'weapon_warrior_2'}});
|
||||
expect(message).to.not.exists;
|
||||
|
||||
// one-handed to two-handed
|
||||
res = equip(user, {params: {key: 'weapon_wizard_1'}});
|
||||
expect(res.message).to.not.exists;
|
||||
[, message] = equip(user, {params: {key: 'weapon_wizard_1'}});
|
||||
expect(message).to.not.exists;
|
||||
|
||||
// two-handed to two-handed
|
||||
res = equip(user, {params: {key: 'weapon_wizard_2'}});
|
||||
expect(res.message).to.not.exists;
|
||||
[, message] = equip(user, {params: {key: 'weapon_wizard_2'}});
|
||||
expect(message).to.not.exists;
|
||||
|
||||
// two-handed to one-handed
|
||||
res = equip(user, {params: {key: 'weapon_warrior_2'}});
|
||||
expect(res.message).to.not.exists;
|
||||
[, message] = equip(user, {params: {key: 'weapon_warrior_2'}});
|
||||
expect(message).to.not.exists;
|
||||
});
|
||||
|
||||
it('should send messages if equipping a two-hander causes the off-hander to be unequipped', () => {
|
||||
|
|
@ -58,10 +58,11 @@ describe('shared.ops.equip', () => {
|
|||
equip(user, {params: {key: 'shield_warrior_1'}});
|
||||
|
||||
// equipping two-hander
|
||||
let res = equip(user, {params: {key: 'weapon_wizard_1'}});
|
||||
let [data, message] = equip(user, {params: {key: 'weapon_wizard_1'}});
|
||||
let weapon = content.gear.flat.weapon_wizard_1;
|
||||
let item = content.gear.flat.shield_warrior_1;
|
||||
|
||||
let res = {data, message};
|
||||
expect(res).to.eql({
|
||||
message: i18n.t('messageTwoHandedEquip', {twoHandedText: weapon.text(), offHandedText: item.text()}),
|
||||
data: user.items,
|
||||
|
|
@ -74,8 +75,9 @@ describe('shared.ops.equip', () => {
|
|||
let weapon = content.gear.flat.weapon_wizard_1;
|
||||
let shield = content.gear.flat.shield_warrior_1;
|
||||
|
||||
let res = equip(user, {params: {key: 'shield_warrior_1'}});
|
||||
let [data, message] = equip(user, {params: {key: 'shield_warrior_1'}});
|
||||
|
||||
let res = {data, message};
|
||||
expect(res).to.eql({
|
||||
message: i18n.t('messageTwoHandedUnequip', {twoHandedText: weapon.text(), offHandedText: shield.text()}),
|
||||
data: user.items,
|
||||
|
|
|
|||
|
|
@ -105,16 +105,14 @@ describe('shared.ops.feed', () => {
|
|||
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
|
||||
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
|
||||
|
||||
let res = feed(user, {params: {pet: 'Wolf-Base', food: 'Saddle'}});
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Base'],
|
||||
message: i18n.t('messageEvolve', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Saddle'}});
|
||||
expect(data).to.eql(user.items.pets['Wolf-Base']);
|
||||
expect(message).to.eql(i18n.t('messageEvolve', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
});
|
||||
}));
|
||||
|
||||
expect(user.items.food.Saddle).to.equal(1);
|
||||
expect(user.items.pets['Wolf-Base']).to.equal(-1);
|
||||
|
|
@ -131,17 +129,15 @@ describe('shared.ops.feed', () => {
|
|||
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
|
||||
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
|
||||
|
||||
let res = feed(user, {params: {pet: 'Wolf-Base', food: 'Meat'}});
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Base'],
|
||||
message: i18n.t('messageLikesFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
foodText: food.text(),
|
||||
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Meat'}});
|
||||
expect(data).to.eql(user.items.pets['Wolf-Base']);
|
||||
expect(message).to.eql(i18n.t('messageLikesFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
});
|
||||
foodText: food.text(),
|
||||
}));
|
||||
|
||||
expect(user.items.food.Meat).to.equal(1);
|
||||
expect(user.items.pets['Wolf-Base']).to.equal(10);
|
||||
|
|
@ -156,17 +152,15 @@ describe('shared.ops.feed', () => {
|
|||
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
|
||||
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
|
||||
|
||||
let res = feed(user, {params: {pet: 'Wolf-Spooky', food: 'Milk'}});
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Spooky'],
|
||||
message: i18n.t('messageLikesFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
foodText: food.text(),
|
||||
let [data, message] = feed(user, {params: {pet: 'Wolf-Spooky', food: 'Milk'}});
|
||||
expect(data).to.eql(user.items.pets['Wolf-Spooky']);
|
||||
expect(message).to.eql(i18n.t('messageLikesFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
});
|
||||
foodText: food.text(),
|
||||
}));
|
||||
|
||||
expect(user.items.food.Milk).to.equal(1);
|
||||
expect(user.items.pets['Wolf-Spooky']).to.equal(10);
|
||||
|
|
@ -181,17 +175,15 @@ describe('shared.ops.feed', () => {
|
|||
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
|
||||
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
|
||||
|
||||
let res = feed(user, {params: {pet: 'Wolf-Base', food: 'Milk'}});
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Base'],
|
||||
message: i18n.t('messageDontEnjoyFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
foodText: food.text(),
|
||||
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Milk'}});
|
||||
expect(data).to.eql(user.items.pets['Wolf-Base']);
|
||||
expect(message).to.eql(i18n.t('messageDontEnjoyFood', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
});
|
||||
foodText: food.text(),
|
||||
}));
|
||||
|
||||
expect(user.items.food.Milk).to.equal(1);
|
||||
expect(user.items.pets['Wolf-Base']).to.equal(7);
|
||||
|
|
@ -206,16 +198,14 @@ describe('shared.ops.feed', () => {
|
|||
let potionText = content.hatchingPotions[potion] ? content.hatchingPotions[potion].text() : potion;
|
||||
let eggText = content.eggs[egg] ? content.eggs[egg].text() : egg;
|
||||
|
||||
let res = feed(user, {params: {pet: 'Wolf-Base', food: 'Milk'}});
|
||||
expect(res).to.eql({
|
||||
data: user.items.pets['Wolf-Base'],
|
||||
message: i18n.t('messageEvolve', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
let [data, message] = feed(user, {params: {pet: 'Wolf-Base', food: 'Milk'}});
|
||||
expect(data).to.eql(user.items.pets['Wolf-Base']);
|
||||
expect(message).to.eql(i18n.t('messageEvolve', {
|
||||
egg: i18n.t('petName', {
|
||||
potion: potionText,
|
||||
egg: eggText,
|
||||
}),
|
||||
});
|
||||
}));
|
||||
|
||||
expect(user.items.food.Milk).to.equal(1);
|
||||
expect(user.items.pets['Wolf-Base']).to.equal(-1);
|
||||
|
|
|
|||
|
|
@ -99,9 +99,9 @@ describe('shared.ops.hatch', () => {
|
|||
user.items.eggs = {Wolf: 1};
|
||||
user.items.hatchingPotions = {Base: 1};
|
||||
user.items.pets = {};
|
||||
let res = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
|
||||
expect(res.message).to.equal(i18n.t('messageHatched'));
|
||||
expect(res.data).to.eql(user.items);
|
||||
let [data, message] = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
|
||||
expect(message).to.equal(i18n.t('messageHatched'));
|
||||
expect(data).to.eql(user.items);
|
||||
expect(user.items.pets).to.eql({'Wolf-Base': 5});
|
||||
expect(user.items.eggs).to.eql({Wolf: 0});
|
||||
expect(user.items.hatchingPotions).to.eql({Base: 0});
|
||||
|
|
@ -111,9 +111,9 @@ describe('shared.ops.hatch', () => {
|
|||
user.items.eggs = {Cheetah: 1};
|
||||
user.items.hatchingPotions = {Base: 1};
|
||||
user.items.pets = {};
|
||||
let res = hatch(user, {params: {egg: 'Cheetah', hatchingPotion: 'Base'}});
|
||||
expect(res.message).to.equal(i18n.t('messageHatched'));
|
||||
expect(res.data).to.eql(user.items);
|
||||
let [data, message] = hatch(user, {params: {egg: 'Cheetah', hatchingPotion: 'Base'}});
|
||||
expect(message).to.equal(i18n.t('messageHatched'));
|
||||
expect(data).to.eql(user.items);
|
||||
expect(user.items.pets).to.eql({'Cheetah-Base': 5});
|
||||
expect(user.items.eggs).to.eql({Cheetah: 0});
|
||||
expect(user.items.hatchingPotions).to.eql({Base: 0});
|
||||
|
|
@ -123,9 +123,9 @@ describe('shared.ops.hatch', () => {
|
|||
user.items.eggs = {Wolf: 1};
|
||||
user.items.hatchingPotions = {Spooky: 1};
|
||||
user.items.pets = {};
|
||||
let res = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Spooky'}});
|
||||
expect(res.message).to.equal(i18n.t('messageHatched'));
|
||||
expect(res.data).to.eql(user.items);
|
||||
let [data, message] = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Spooky'}});
|
||||
expect(message).to.equal(i18n.t('messageHatched'));
|
||||
expect(data).to.eql(user.items);
|
||||
expect(user.items.pets).to.eql({'Wolf-Spooky': 5});
|
||||
expect(user.items.eggs).to.eql({Wolf: 0});
|
||||
expect(user.items.hatchingPotions).to.eql({Spooky: 0});
|
||||
|
|
@ -135,9 +135,9 @@ describe('shared.ops.hatch', () => {
|
|||
user.items.eggs = {Wolf: 1};
|
||||
user.items.hatchingPotions = {Base: 1};
|
||||
user.items.pets = {'Wolf-Base': -1};
|
||||
let res = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
|
||||
expect(res.message).to.eql(i18n.t('messageHatched'));
|
||||
expect(res.data).to.eql(user.items);
|
||||
let [data, message] = hatch(user, {params: {egg: 'Wolf', hatchingPotion: 'Base'}});
|
||||
expect(message).to.eql(i18n.t('messageHatched'));
|
||||
expect(data).to.eql(user.items);
|
||||
expect(user.items.pets).to.eql({'Wolf-Base': 5});
|
||||
expect(user.items.eggs).to.eql({Wolf: 0});
|
||||
expect(user.items.hatchingPotions).to.eql({Base: 0});
|
||||
|
|
|
|||
|
|
@ -126,9 +126,9 @@ describe('user.ops.hourglassPurchase', () => {
|
|||
it('buys a pet', () => {
|
||||
user.purchased.plan.consecutive.trinkets = 2;
|
||||
|
||||
let response = hourglassPurchase(user, {params: {type: 'pets', key: 'MantisShrimp-Base'}});
|
||||
let [, message] = hourglassPurchase(user, {params: {type: 'pets', key: 'MantisShrimp-Base'}});
|
||||
|
||||
expect(response.message).to.eql(i18n.t('hourglassPurchase'));
|
||||
expect(message).to.eql(i18n.t('hourglassPurchase'));
|
||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||
expect(user.items.pets).to.eql({'MantisShrimp-Base': 5});
|
||||
});
|
||||
|
|
@ -136,8 +136,8 @@ describe('user.ops.hourglassPurchase', () => {
|
|||
it('buys a mount', () => {
|
||||
user.purchased.plan.consecutive.trinkets = 2;
|
||||
|
||||
let response = hourglassPurchase(user, {params: {type: 'mounts', key: 'MantisShrimp-Base'}});
|
||||
expect(response.message).to.eql(i18n.t('hourglassPurchase'));
|
||||
let [, message] = hourglassPurchase(user, {params: {type: 'mounts', key: 'MantisShrimp-Base'}});
|
||||
expect(message).to.eql(i18n.t('hourglassPurchase'));
|
||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||
expect(user.items.mounts).to.eql({'MantisShrimp-Base': true});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ describe('shared.ops.openMysteryItem', () => {
|
|||
|
||||
user.purchased.plan.mysteryItems = [mysteryItemKey];
|
||||
|
||||
let response = openMysteryItem(user);
|
||||
let [data, message] = openMysteryItem(user);
|
||||
|
||||
expect(user.items.gear.owned[mysteryItemKey]).to.be.true;
|
||||
expect(response.message).to.equal(i18n.t('mysteryItemOpened'));
|
||||
expect(response.data).to.equal(user.items.gear.owned);
|
||||
expect(message).to.equal(i18n.t('mysteryItemOpened'));
|
||||
expect(data).to.equal(user.items.gear.owned);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import {
|
|||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
|
||||
describe('shared.ops.feed', () => {
|
||||
describe('shared.ops.purchase', () => {
|
||||
let user;
|
||||
let goldPoints = 40;
|
||||
let gemsBought = 40;
|
||||
|
|
@ -128,7 +128,7 @@ describe('shared.ops.feed', () => {
|
|||
});
|
||||
});
|
||||
|
||||
context('successful feeding', () => {
|
||||
context('successful purchase', () => {
|
||||
let userGemAmount = 10;
|
||||
|
||||
before(() => {
|
||||
|
|
@ -138,9 +138,9 @@ describe('shared.ops.feed', () => {
|
|||
});
|
||||
|
||||
it('purchases gems', () => {
|
||||
let purchaseResponse = purchase(user, {params: {type: 'gems', key: 'gem'}});
|
||||
let [, message] = purchase(user, {params: {type: 'gems', key: 'gem'}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('plusOneGem'));
|
||||
expect(message).to.equal(i18n.t('plusOneGem'));
|
||||
expect(user.balance).to.equal(userGemAmount + 0.25);
|
||||
expect(user.purchased.plan.gemsBought).to.equal(1);
|
||||
expect(user.stats.gp).to.equal(goldPoints - planGemLimits.convRate);
|
||||
|
|
@ -150,9 +150,9 @@ describe('shared.ops.feed', () => {
|
|||
let type = 'eggs';
|
||||
let key = 'Wolf';
|
||||
|
||||
let purchaseResponse = purchase(user, {params: {type, key}});
|
||||
let [, message] = purchase(user, {params: {type, key}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(user.items[type][key]).to.equal(1);
|
||||
});
|
||||
|
||||
|
|
@ -160,9 +160,9 @@ describe('shared.ops.feed', () => {
|
|||
let type = 'hatchingPotions';
|
||||
let key = 'Base';
|
||||
|
||||
let purchaseResponse = purchase(user, {params: {type, key}});
|
||||
let [, message] = purchase(user, {params: {type, key}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(user.items[type][key]).to.equal(1);
|
||||
});
|
||||
|
||||
|
|
@ -170,9 +170,9 @@ describe('shared.ops.feed', () => {
|
|||
let type = 'food';
|
||||
let key = 'Meat';
|
||||
|
||||
let purchaseResponse = purchase(user, {params: {type, key}});
|
||||
let [, message] = purchase(user, {params: {type, key}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(user.items[type][key]).to.equal(1);
|
||||
});
|
||||
|
||||
|
|
@ -180,9 +180,9 @@ describe('shared.ops.feed', () => {
|
|||
let type = 'quests';
|
||||
let key = 'gryphon';
|
||||
|
||||
let purchaseResponse = purchase(user, {params: {type, key}});
|
||||
let [, message] = purchase(user, {params: {type, key}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(user.items[type][key]).to.equal(1);
|
||||
});
|
||||
|
||||
|
|
@ -190,9 +190,9 @@ describe('shared.ops.feed', () => {
|
|||
let type = 'gear';
|
||||
let key = 'headAccessory_special_tigerEars';
|
||||
|
||||
let purchaseResponse = purchase(user, {params: {type, key}});
|
||||
let [, message] = purchase(user, {params: {type, key}});
|
||||
|
||||
expect(purchaseResponse.message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(message).to.equal(i18n.t('purchased', {type, key}));
|
||||
expect(user.items.gear.owned[key]).to.be.true;
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ describe('shared.ops.readCard', () => {
|
|||
});
|
||||
|
||||
it('reads a card', () => {
|
||||
let response = readCard(user, {params: {cardType: 'greeting'}});
|
||||
let [, message] = readCard(user, {params: {cardType: 'greeting'}});
|
||||
|
||||
expect(response.message).to.equal(i18n.t('readCard', {cardType}));
|
||||
expect(message).to.equal(i18n.t('readCard', {cardType}));
|
||||
expect(user.items.special[`${cardType}Received`]).to.be.empty;
|
||||
expect(user.flags.cardReceived).to.be.false;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -35,18 +35,18 @@ describe('shared.ops.rebirth', () => {
|
|||
});
|
||||
|
||||
it('rebirths a user with enough gems', () => {
|
||||
let response = rebirth(user);
|
||||
let [, message] = rebirth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('rebirthComplete'));
|
||||
expect(message).to.equal(i18n.t('rebirthComplete'));
|
||||
});
|
||||
|
||||
it('rebirths a user with not enough gems but max level', () => {
|
||||
user.balance = 0;
|
||||
user.stats.lvl = MAX_LEVEL;
|
||||
|
||||
let response = rebirth(user);
|
||||
let [, message] = rebirth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('rebirthComplete'));
|
||||
expect(message).to.equal(i18n.t('rebirthComplete'));
|
||||
});
|
||||
|
||||
it('resets user\'s taks values except for rewards to 0', () => {
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ describe('shared.ops.releaseBoth', () => {
|
|||
});
|
||||
|
||||
it('grants triad bingo with gems', () => {
|
||||
let response = releaseBoth(user);
|
||||
let [, message] = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.achievements.triadBingoCount).to.equal(1);
|
||||
});
|
||||
|
||||
|
|
@ -44,24 +44,24 @@ describe('shared.ops.releaseBoth', () => {
|
|||
user.achievements.triadBingo = 1;
|
||||
user.achievements.triadBingoCount = 1;
|
||||
|
||||
let response = releaseBoth(user);
|
||||
let [, message] = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.achievements.triadBingoCount).to.equal(2);
|
||||
});
|
||||
|
||||
it('releases pets', () => {
|
||||
let response = releaseBoth(user);
|
||||
let [, message] = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.items.pets[animal]).to.be.empty;
|
||||
expect(user.items.mounts[animal]).to.equal(null);
|
||||
});
|
||||
|
||||
it('releases mounts', () => {
|
||||
let response = releaseBoth(user);
|
||||
let [, message] = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.items.mounts[animal]).to.equal(null);
|
||||
});
|
||||
|
||||
|
|
|
|||