fix(spells): add some spells tests, don't send up body to spell paths

This commit is contained in:
Tyler Renelle
2014-01-22 00:16:52 -08:00
parent c6f7ab8a5c
commit e0646bb98d
4 changed files with 43 additions and 16 deletions
+7 -13
View File
@@ -322,14 +322,8 @@ api.buyGemsPaypalIPN = function(req, res, next) {
*/
api.cast = function(req, res) {
var user = res.locals.user;
var type, target;
if (req.body.type) { // this is the method implemented in the app, it's not correct
type = req.body.type;
target = req.body.target;
} else if (req.query.targetType) { // this is the supported API method
type = req.query.targetType;
target = req.query.targetId;
}
var targetType = req.query.targetType;
var targetId = req.query.targetId;
var klass = shared.content.spells.special[req.params.spell] ? 'special' : user.stats.class
var spell = shared.content.spells[klass][req.params.spell];
@@ -340,9 +334,9 @@ api.cast = function(req, res) {
res.json(saved);
}
switch (type) {
switch (targetType) {
case 'task':
spell.cast(user, user.tasks[target.id]);
spell.cast(user, user.tasks[targetId]);
user.save(done);
break;
@@ -361,20 +355,20 @@ api.cast = function(req, res) {
// Solo player? let's just create a faux group for simpler code
var g = group ? group : {members:[user]};
var series = [], found;
if (type == 'party') {
if (targetType == 'party') {
spell.cast(user, g.members);
series = _.transform(g.members, function(m,v,k){
m.push(function(cb2){v.save(cb2)});
});
} else {
found = _.find(g.members, {_id: target._id})
found = _.find(g.members, {_id: targetId})
spell.cast(user, found);
series.push(function(cb2){found.save(cb2)});
}
if (group) {
series.push(function(cb2){
var message = '`'+user.profile.name+' casts '+spell.text + (type=='user' ? ' on '+found.profile.name : ' for the party')+'.`';
var message = '`'+user.profile.name+' casts '+spell.text + (targetType=='user' ? ' on '+found.profile.name : ' for the party')+'.`';
group.sendChat(message);
group.save(cb2);
})