From 48393637fceb8405699997550d46916fdb3828a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Wed, 23 Oct 2013 21:56:09 -0300 Subject: [PATCH 1/6] using length matcher to have more helpful error messages --- tests/algos.mocha.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/algos.mocha.coffee b/tests/algos.mocha.coffee index 630862b39b..0fce726625 100644 --- a/tests/algos.mocha.coffee +++ b/tests/algos.mocha.coffee @@ -30,8 +30,8 @@ beforeAfter = (options={}) -> expectLostPoints = (before, after, taskType) -> if taskType in ['daily','habit'] expect(after.stats.hp).to.be.lessThan before.stats.hp - expect(_.size(after["#{taskType}s"][0].history)).to.be(1) - else expect(_.size(after.history.todos)).to.be(1) + expect(after["#{taskType}s"][0].history).to.have.length(1) + else expect(after.history.todos).to.have.length(1) expect(after.stats.exp).to.be 0 expect(after.stats.gp).to.be 0 expect(after["#{taskType}s"][0].value).to.be.lessThan before["#{taskType}s"][0].value @@ -41,7 +41,7 @@ expectGainedPoints = (before, after, taskType) -> expect(after.stats.exp).to.be.greaterThan before.stats.exp expect(after.stats.gp).to.be.greaterThan before.stats.gp expect(after["#{taskType}s"][0].value).to.be.greaterThan before["#{taskType}s"][0].value - expect(_.size(after["#{taskType}s"][0].history)).to.be(1) if taskType is 'habit' + expect(after["#{taskType}s"][0].history).to.have.length(1) if taskType is 'habit' # daily & todo histories handled on cron expectNoChange = (before,after) -> expect(before).to.eql after @@ -52,11 +52,11 @@ expectDayResetNoDamage = (b,a) -> expect(task.completed).to.be false expect(before.dailys[i].value).to.be task.value expect(before.dailys[i].streak).to.be task.streak - expect(_.size(task.history)).to.be(1) + expect(task.history).to.have.length(1) _.each after.todos, (task,i) -> expect(task.completed).to.be false expect(before.todos[i].value).to.be.greaterThan task.value - expect(_.size(after.history.todos)).to.be(1) + expect(after.history.todos).to.have.length(1) # hack so we can compare user before/after obj equality sans effected paths _.each ['dailys','todos','history','lastCron'], (path) -> _.each [before,after], (obj) -> delete obj[path] @@ -219,7 +219,7 @@ describe 'Cron', -> # but they devalue expect(after.todos[0].value).to.be.lessThan before.todos[0].value - expect(_.size(after.history.todos)).to.be 1 + expect(after.history.todos).to.have.length 1 describe 'dailies', -> From b5fefc2664c90c7a54afd668f087bb62fc900dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Wed, 23 Oct 2013 22:25:58 -0300 Subject: [PATCH 2/6] add test for priority values --- tests/algos.mocha.coffee | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/algos.mocha.coffee b/tests/algos.mocha.coffee index 0fce726625..13fe5a8a7e 100644 --- a/tests/algos.mocha.coffee +++ b/tests/algos.mocha.coffee @@ -332,3 +332,10 @@ describe 'Helper', -> expect(algos.tnl 10).to.eql 260 expect(algos.tnl 99).to.eql 3580 expect(algos.tnl 100).to.eql 0 + + it 'calculates priority values', -> + expect(algos.priorityValue()).to.eql 1 + expect(algos.priorityValue '!').to.eql 1 + expect(algos.priorityValue '!!').to.eql 1.5 + expect(algos.priorityValue '!!!').to.eql 2 + expect(algos.priorityValue '!!!!').to.eql 1 From dd79638bac57e50c3b6bd6e86c51e1e772227ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Fri, 25 Oct 2013 23:22:09 -0300 Subject: [PATCH 3/6] allow any branch in travis builds --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0bd176cf2a..6e5919de39 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,3 @@ language: node_js node_js: - "0.10" -branches: - only: - - rewrite From ecc8ff740eea5b76a8eeae0f8821f50e96fad77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Fri, 25 Oct 2013 23:40:25 -0300 Subject: [PATCH 4/6] add lastDrop to helpers.newUser --- script/helpers.coffee | 2 +- tests/algos.mocha.coffee | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/script/helpers.coffee b/script/helpers.coffee index b5fbdf330f..2f2b63996f 100644 --- a/script/helpers.coffee +++ b/script/helpers.coffee @@ -76,7 +76,7 @@ module.exports = # _id / id handled by Racer stats: { gp: 0, exp: 0, lvl: 1, hp: 50 } invitations: {party:null, guilds: []} - items: { weapon: 0, armor: 0, head: 0, shield: 0 } + items: { weapon: 0, armor: 0, head: 0, shield: 0, lastDrop: { date: +new Date, count: 0 } } preferences: { gender: 'm', skin: 'white', hair: 'blond', armorSet: 'v1', dayStart:0, showHelm: true } apiToken: uuid() # set in newUserObject below lastCron: +new Date #this will be replaced with `+new Date` on first run diff --git a/tests/algos.mocha.coffee b/tests/algos.mocha.coffee index 13fe5a8a7e..390f83e34c 100644 --- a/tests/algos.mocha.coffee +++ b/tests/algos.mocha.coffee @@ -75,7 +75,11 @@ describe 'User', -> it 'sets correct user defaults', -> user = helpers.newUser() expect(user.stats).to.eql { gp: 0, exp: 0, lvl: 1, hp: 50 } - expect(user.items).to.eql { weapon: 0, armor: 0, head: 0, shield: 0 } + expect(user.items.weapon).to.eql 0 + expect(user.items.armor).to.eql 0 + expect(user.items.head).to.eql 0 + expect(user.items.shield).to.eql 0 + expect(user.items.lastDrop.count).to.eql 0 expect(user.preferences).to.eql { gender: 'm', skin: 'white', hair: 'blond', armorSet: 'v1', dayStart:0, showHelm: true } expect(user.balance).to.eql 0 expect(user.lastCron).to.be.greaterThan 0 @@ -95,7 +99,10 @@ describe 'User', -> user.weapon = 1 algos.revive user expect(user.stats).to.eql { gp: 0, exp: 0, lvl: 1, hp: 50 } - expect(user.items).to.eql { weapon: 0, armor: 0, head: 0, shield: 0 } + expect(user.items.weapon).to.eql 0 + expect(user.items.armor).to.eql 0 + expect(user.items.head).to.eql 0 + expect(user.items.shield).to.eql 0 describe 'store', -> it 'recovers hp buying potions', -> From fab7a109208893efabc7ba631020d9673fd6f48e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Sun, 27 Oct 2013 11:07:25 -0300 Subject: [PATCH 5/6] make cron tests locale aware (first day of the week) --- tests/algos.mocha.coffee | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/algos.mocha.coffee b/tests/algos.mocha.coffee index 390f83e34c..3e81baf748 100644 --- a/tests/algos.mocha.coffee +++ b/tests/algos.mocha.coffee @@ -9,10 +9,10 @@ helpers = require '../script/helpers.coffee' items = require '../script/items.coffee' ### Helper Functions #### - expectStrings = (obj, paths) -> _.each paths, (path) -> expect(obj[path]).to.be.ok() +# options.daysAgo: days ago when the last cron was executed beforeAfter = (options={}) -> user = helpers.newUser() [before, after] = [_.cloneDeep(user), _.cloneDeep(user)] @@ -69,6 +69,14 @@ cycle = (array)-> n++ return array[n % array.length] +repeatWithoutLastWeekday = ()-> + repeat = {su:1,m:1,t:1,w:1,th:1,f:1,s:1} + if helpers.startOfWeek(moment().zone(0)).isoWeekday() == 1 # Monday + repeat.su = false + else + repeat.s = false + {repeat: repeat} + ###### Specs ###### describe 'User', -> @@ -293,7 +301,7 @@ describe 'Cron', -> 'unchecked': {checked:false, expect: 'losePoints'} 'not due yesterday': - defaults: {repeat:{su:false,m:1,t:1,w:1,th:1,f:1,s:1}} + defaults: repeatWithoutLastWeekday() steps: '(simple)': {expect:'noDamage'} 'post-dayStart': {currentHour:5,dayStart:4, expect:'noDamage'} @@ -346,3 +354,8 @@ describe 'Helper', -> expect(algos.priorityValue '!!').to.eql 1.5 expect(algos.priorityValue '!!!').to.eql 2 expect(algos.priorityValue '!!!!').to.eql 1 + + it 'calculates the start of the day', -> + expect(helpers.startOfDay({now: new Date(2013, 0, 1, 0)}).format('YYYY-MM-DD HH:mm')).to.eql '2013-01-01 00:00' + expect(helpers.startOfDay({now: new Date(2013, 0, 1, 5)}).format('YYYY-MM-DD HH:mm')).to.eql '2013-01-01 00:00' + expect(helpers.startOfDay({now: new Date(2013, 0, 1, 23, 59, 59)}).format('YYYY-MM-DD HH:mm')).to.eql '2013-01-01 00:00' From 8743e00b623fc96f0fbe3fe2adf63ae301969c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Jureti=C4=87?= Date: Thu, 31 Oct 2013 22:07:19 -0300 Subject: [PATCH 6/6] show how to run tests in readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index fcc3045096..0f7fdb7185 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ Shared resources useful for the multiple HabitRPG repositories, that way all the * `algos.score(user, task, direction)`, etc * TODO document all the functions +##Tests +* `npm install` + ##CSS Shared CSS between the website and the mobile app is a fuzzy area. Spritesheets definitely go in habitrpg-shared (since mobile uses them too). Other things, like customizer buttons, *may* want to go here? As you find sharable components, (1) move them