mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-03 08:21:07 +00:00
Merge pull request #25 from djuretic/test_drops
Added drop system tests
This commit is contained in:
commit
fe9446c1d5
2 changed files with 39 additions and 0 deletions
|
|
@ -12,6 +12,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "*",
|
"mocha": "*",
|
||||||
"expect.js": "*",
|
"expect.js": "*",
|
||||||
|
"sinon": "~1.7.3",
|
||||||
"grunt-contrib-cssmin": "~0.6.0",
|
"grunt-contrib-cssmin": "~0.6.0",
|
||||||
"grunt": "~0.4.1",
|
"grunt": "~0.4.1",
|
||||||
"grunt-browserify": "~1.2.4"
|
"grunt-browserify": "~1.2.4"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
_ = require 'lodash'
|
_ = require 'lodash'
|
||||||
expect = require 'expect.js'
|
expect = require 'expect.js'
|
||||||
|
sinon = require 'sinon'
|
||||||
moment = require 'moment'
|
moment = require 'moment'
|
||||||
|
|
||||||
# Custom modules
|
# Custom modules
|
||||||
|
|
@ -62,6 +63,11 @@ expectDayResetNoDamage = (b,a) ->
|
||||||
delete after._tmp
|
delete after._tmp
|
||||||
expect(after).to.eql before
|
expect(after).to.eql before
|
||||||
|
|
||||||
|
cycle = (array)->
|
||||||
|
n = -1
|
||||||
|
->
|
||||||
|
n++
|
||||||
|
return array[n % array.length]
|
||||||
|
|
||||||
###### Specs ######
|
###### Specs ######
|
||||||
|
|
||||||
|
|
@ -118,6 +124,38 @@ describe 'User', ->
|
||||||
expect(user.items.armor).to.eql 0
|
expect(user.items.armor).to.eql 0
|
||||||
expect(user.stats.gp).to.eql 1
|
expect(user.stats.gp).to.eql 1
|
||||||
|
|
||||||
|
describe 'drop system', ->
|
||||||
|
user = null
|
||||||
|
|
||||||
|
beforeEach ->
|
||||||
|
user = helpers.newUser()
|
||||||
|
user.flags.dropsEnabled = true
|
||||||
|
# too many Math.random calls to stub, let's return the last element
|
||||||
|
sinon.stub(helpers, 'randomVal', (x)->x[x.length-1])
|
||||||
|
|
||||||
|
it 'gets a golden potion', ->
|
||||||
|
sinon.stub(Math, 'random').returns 0
|
||||||
|
algos.score(user, user.dailys[0], 'up')
|
||||||
|
expect(user.items.eggs).to.eql undefined
|
||||||
|
expect(user.items.hatchingPotions).to.eql ['Golden']
|
||||||
|
|
||||||
|
it 'gets a bear cub egg', ->
|
||||||
|
sinon.stub(Math, 'random', cycle [0, 0.6])
|
||||||
|
algos.score(user, user.dailys[0], 'up')
|
||||||
|
expect(user.items.eggs.length).to.eql 1
|
||||||
|
expect(user.items.eggs[0].name).to.eql 'BearCub'
|
||||||
|
expect(user.items.hatchingPotions).to.eql undefined
|
||||||
|
|
||||||
|
it 'does not get a drop', ->
|
||||||
|
sinon.stub(Math, 'random').returns 0.5
|
||||||
|
algos.score(user, user.dailys[0], 'up')
|
||||||
|
expect(user.items.eggs).to.eql undefined
|
||||||
|
expect(user.items.hatchingPotions).to.eql undefined
|
||||||
|
|
||||||
|
afterEach ->
|
||||||
|
Math.random.restore()
|
||||||
|
helpers.randomVal.restore()
|
||||||
|
|
||||||
describe 'Simple Scoring', ->
|
describe 'Simple Scoring', ->
|
||||||
|
|
||||||
it 'Habits : Up', ->
|
it 'Habits : Up', ->
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue