Ported read card, added unit tests, added read card route and integration tests

This commit is contained in:
Keith Holliday
2016-04-01 09:17:40 -05:00
parent 3089658cc7
commit 6d9617e345
6 changed files with 139 additions and 8 deletions

View File

@@ -1,10 +1,28 @@
module.exports = function(user, req, cb) {
var cardType;
cardType = req.params.cardType;
user.items.special[cardType + "Received"].shift();
if (typeof user.markModified === "function") {
user.markModified("items.special." + cardType + "Received");
import splitWhitespace from '../libs/splitWhitespace';
import _ from 'lodash';
import i18n from '../i18n';
import {
BadRequest,
NotAuthorized,
} from '../libs/errors';
import content from '../content/index';
module.exports = function readCard (user, req = {}) {
let cardType = _.get(req.params, 'cardType');
if (!cardType) {
throw new BadRequest(i18n.t('cardTypeRequired', req.language));
}
if (_.keys(content.cardTypes).indexOf(cardType) === -1) {
throw new NotAuthorized(i18n.t('cardTypeNotAllowed', req.language));
}
user.items.special[`${cardType}Received`].shift();
user.flags.cardReceived = false;
return typeof cb === "function" ? cb(null, 'items.special flags.cardReceived') : void 0;
return {
message: i18n.t('readCard', {cardType}, req.language),
data: _.pick(user, splitWhitespace('items.special flags.cardReceived')),
};
};