mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 19:47:03 +00:00
setting up for testing REST
This commit is contained in:
parent
b672a07632
commit
2e43d71a66
4 changed files with 97 additions and 74 deletions
10
Makefile
10
Makefile
|
|
@ -1,20 +1,18 @@
|
|||
compile:
|
||||
./node_modules/coffee-script/bin/coffee -bw -o ./lib -c ./src
|
||||
|
||||
test-casper:
|
||||
casperjs test ./test
|
||||
|
||||
MOCHA_TESTS := $(shell find test/ -name '*.mocha.*')
|
||||
MOCHA = mocha --compilers coffee:coffee-script
|
||||
OUT_FILE = "test-output.tmp"
|
||||
|
||||
g = "."
|
||||
|
||||
#@NODE_ENV=test $(MOCHA) --grep "$(g)" $(MOCHA_TESTS) | tee $(OUT_FILE)
|
||||
test-mocha:
|
||||
@NODE_ENV=test $(MOCHA) ./test/user.mocha.coffee
|
||||
@NODE_ENV=test $(MOCHA) --grep "$(g)" $(MOCHA_TESTS)
|
||||
#@NODE_ENV=test $(MOCHA) --grep "$(g)" $(MOCHA_TESTS) | tee $(OUT_FILE)
|
||||
|
||||
test-casper:
|
||||
casperjs test ./test/rest.casper.coffee
|
||||
|
||||
test: test-mocha
|
||||
test!:
|
||||
@perl -n -e '/\[31m 0\) (.*?).\[0m/ && print "make test g=\"$$1\$$\""' $(OUT_FILE) | sh
|
||||
|
|
|
|||
69
test/browser.casper.coffee
Normal file
69
test/browser.casper.coffee
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
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"
|
||||
|
||||
# ---------- Setup Tasks ------------
|
||||
casper.then ->
|
||||
['habit', 'daily', 'todo', 'reward'].forEach (type) ->
|
||||
# Add 15 of each task type
|
||||
casper.repeat 15, ->
|
||||
casper.fill "form#new-#{type}", {'new-task': type } # why can't I use true here?
|
||||
casper.click "form#new-#{type} input[type=submit]"
|
||||
@then ->
|
||||
utils.dump @evaluate -> _.pluck(window.DERBY.model.get('_user.tasks'), 'text')
|
||||
|
||||
|
||||
# ---------- Run Cron ------------
|
||||
casper.then ->
|
||||
@evaluate -> window.DERBY.model.set('_user.lastCron', new Date('09/01/2012'));
|
||||
@then -> @reload ->
|
||||
@echo 'Refreshing pag (running cron)'
|
||||
@then -> @reload ->
|
||||
@echo 'Refreshing page (trying to trigger the database-spaz bug)'
|
||||
|
||||
# ---------- Todos gain delta on cron ------------
|
||||
casper.then ->
|
||||
todoBefore = @evaluate -> window.DERBY.model.get('_todoList')[0]
|
||||
@then ->
|
||||
@evaluate ->
|
||||
window.DERBY.model.set('_user.lastCron', new Date('09/17/2012'))
|
||||
@then -> @reload()
|
||||
@then ->
|
||||
@wait 2000, ->
|
||||
todoAfter = @evaluate -> window.DERBY.model.get('_todoList')[0]
|
||||
@then -> @test.assert(todoBefore.value > todoAfter.value, "Incomplete TODO gained value on cron")
|
||||
utils.dump todoBefore
|
||||
utils.dump todoAfter
|
||||
|
||||
# ---------- 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"
|
||||
|
||||
# ---------- Run ------------
|
||||
|
||||
casper.run ->
|
||||
@test.renderResults true
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
url = 'http://localhost:3000'
|
||||
utils = require('utils')
|
||||
casper = require("casper").create()
|
||||
_ = require('../public/js/underscore-min.js')
|
||||
|
||||
# ---------- Main Stuff ------------
|
||||
|
||||
casper.start url, ->
|
||||
@test.assertTitle "HabitRPG", "homepage title is the one expected"
|
||||
|
||||
# ---------- Setup Tasks ------------
|
||||
casper.then ->
|
||||
_.each ['habit', 'daily', 'todo', 'reward'], (type) ->
|
||||
# Add 15 of each task type
|
||||
casper.repeat 15, ->
|
||||
casper.fill "form#new-#{type}", {'new-task': type } # why can't I use true here?
|
||||
casper.click "form#new-#{type} input[type=submit]"
|
||||
# @then ->
|
||||
# utils.dump @evaluate -> _.pluck(window.DERBY.model.get('_user.tasks'), 'text')
|
||||
|
||||
|
||||
# ---------- Run Cron ------------
|
||||
casper.then ->
|
||||
@evaluate -> window.DERBY.model.set('_user.lastCron', new Date('09/01/2012'));
|
||||
# @then -> @reload ->
|
||||
# @echo 'Refreshing pag (running cron)'
|
||||
# @then -> @reload ->
|
||||
# @echo 'Refreshing page (trying to trigger the database-spaz bug)'
|
||||
|
||||
# ---------- Todos gain delta on cron ------------
|
||||
# casper.then ->
|
||||
# todoBefore = @evaluate -> window.DERBY.model.get('_todoList')[0]
|
||||
# @then ->
|
||||
# @evaluate ->
|
||||
# window.DERBY.model.set('_user.lastCron', new Date('09/17/2012'))
|
||||
# @then -> @reload()
|
||||
# @then ->
|
||||
# @wait 2000, ->
|
||||
# todoAfter = @evaluate -> window.DERBY.model.get('_todoList')[0]
|
||||
# @then -> @test.assert(todoBefore.value > todoAfter.value, "Incomplete TODO gained value on cron")
|
||||
# utils.dump todoBefore
|
||||
# utils.dump todoAfter
|
||||
|
||||
# ---------- 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
|
||||
24
test/rest.casper.coffee
Normal file
24
test/rest.casper.coffee
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
url = 'http://localhost:3000'
|
||||
utils = require('utils')
|
||||
casper = require("casper").create()
|
||||
uid = undefined
|
||||
|
||||
# ---------- Main Stuff ------------
|
||||
|
||||
casper.start url, ->
|
||||
uid = @evaluate -> window.DERBY.model.get("_user.id")
|
||||
utils.dump uid
|
||||
|
||||
# ---------- REST API ------------
|
||||
|
||||
casper.thenOpen "#{url}/users/#{uid}"
|
||||
casper.thenOpen "#{url}/users/#{uid}/tasks"
|
||||
casper.thenOpen "#{url}/users/#{uid}/tasks/{taskId}"
|
||||
casper.thenOpen "#{url}/users/#{uid}/tasks/{taskId}"
|
||||
|
||||
casper.thenOpen "#{url}/users/#{uid}/score"
|
||||
|
||||
# ---------- Run ------------
|
||||
|
||||
casper.run ->
|
||||
@test.renderResults true
|
||||
Loading…
Reference in a new issue