diff --git a/lib/app/scoring.js b/lib/app/scoring.js index aa4a810277..ba14d1d1f3 100644 --- a/lib/app/scoring.js +++ b/lib/app/scoring.js @@ -33,13 +33,6 @@ hpModifier = function(user, value) { updateStats = function(user, stats) { var money, tnl; - if (stats.hp != null) { - if (stats.hp < 0) { - user.set('stats.lvl', 0); - } else { - user.set('stats.hp', stats.hp); - } - } if (stats.exp != null) { tnl = user.get('_tnl'); if (stats.exp >= tnl) { @@ -61,6 +54,13 @@ updateStats = function(user, stats) { } user.set('stats.exp', stats.exp); } + if (stats.hp != null) { + if (stats.hp < 0) { + user.set('stats.lvl', 0); + } else { + user.set('stats.hp', stats.hp); + } + } if (stats.money != null) { if (!(typeof money !== "undefined" && money !== null) || money < 0) { money = 0.0; diff --git a/src/app/scoring.coffee b/src/app/scoring.coffee index 698cc7be2f..9dc177df79 100644 --- a/src/app/scoring.coffee +++ b/src/app/scoring.coffee @@ -28,13 +28,6 @@ hpModifier = (user, value) -> # Setter for user.stats: handles death, leveling up, etc updateStats = (user, stats) -> - if stats.hp? - # game over - if stats.hp < 0 - user.set 'stats.lvl', 0 # this signifies dead - else - user.set 'stats.hp', stats.hp - if stats.exp? # level up & carry-over exp tnl = user.get '_tnl' @@ -58,12 +51,18 @@ updateStats = (user, stats) -> user.set 'stats.exp', stats.exp + if stats.hp? + # game over + if stats.hp < 0 + user.set 'stats.lvl', 0 # this signifies dead + else + user.set 'stats.hp', stats.hp + if stats.money? money = 0.0 if (!money? or money<0) user.set 'stats.money', stats.money module.exports.score = score = (spec = {user:null, task:null, direction:null, cron:null}) -> - # console.log spec, "scoring.coffee: score( ->spec<- )" [user, task, direction, cron] = [spec.user, spec.task, spec.direction, spec.cron] # up / down was called by itself, probably as REST from 3rd party service diff --git a/test/test.coffee b/test/test.coffee new file mode 100644 index 0000000000..8c48030e1e --- /dev/null +++ b/test/test.coffee @@ -0,0 +1,35 @@ +url = 'http://localhost:3000' +utils = require('utils') +casper = require("casper").create() + +# ---------- Main Stuff ------------ + +casper.start url, -> + @test.assertTitle "HabitRPG", "homepage title is the one expected" + + +# ---------- User Death ------------ +casper.then -> + @repeat 55, -> + @click '.habits a[data-direction="down"]' + +casper.then -> + userStats = @evaluate -> + window.DERBY.model.get('_user.stats') + utils.dump userStats + + @test.assert(@visible('#dead-modal'), 'Revive Modal Visible') + @test.assert(userStats.hp == 0, 'User HP: 0') + @test.assert(userStats.lvl == 0, 'User Lvl: 0') + @test.assert(userStats.money == 0, 'User GP: 0') + +# ---------- Misc Pages ------------ + +# casper.thenOpen "#{url}/terms", -> + # @test.assertTitle "Terms Of Use", "terms page works" +# +# casper.thenOpen "#{url}/privacy", -> + # @test.assertTitle "Privacy Policy", "privacy page works" + +casper.run -> + @test.renderResults true \ No newline at end of file