mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Add readme. Adjust api-helper.coffee
This commit is contained in:
20
test/api/README.md
Normal file
20
test/api/README.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# API Tests
|
||||||
|
|
||||||
|
Our API tests are written in [coffeescript](http://coffeescript.org/) using the [Mocha testing framework](http://mochajs.org/).
|
||||||
|
|
||||||
|
### Modules
|
||||||
|
Some modules are declared in the [api-helper.coffee](api-helper.coffee) file for use in any of the api tests:
|
||||||
|
|
||||||
|
* `moment` - time manipulation
|
||||||
|
* `async` - run async processes, good for before blocks
|
||||||
|
* `lodash (_)` - many utilities
|
||||||
|
* `shared` - generate uuids
|
||||||
|
* `expect` - making assertions
|
||||||
|
* `User` - look up a User in the db
|
||||||
|
|
||||||
|
## Helper Methods
|
||||||
|
|
||||||
|
There are helper methods declared in the [api-helper.coffee](api-helper.coffee) file. Some useful methods contained there:
|
||||||
|
|
||||||
|
* `registerNewUser(callback, main)` - Theres a global user variable that gets overwritten with the new user whenever you call `registerNewUser` unless you pass false in as the second argument.
|
||||||
|
* `registerManyUsers(number, callback)` - Good for testing things that require many users. The callback function returns new users as and array in the second argument.
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
global.User = require("../../website/src/models/user").model
|
|
||||||
##############################
|
##############################
|
||||||
# Global modules
|
# Global modules
|
||||||
##############################
|
##############################
|
||||||
@@ -10,6 +9,7 @@ global.async = require("async")
|
|||||||
global._ = require("lodash")
|
global._ = require("lodash")
|
||||||
global.expect = require("expect.js")
|
global.expect = require("expect.js")
|
||||||
global.shared = require("../../common")
|
global.shared = require("../../common")
|
||||||
|
global.User = require("../../website/src/models/user").model
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
# Nconf config
|
# Nconf config
|
||||||
@@ -34,7 +34,6 @@ global.expectCode = (res, code) ->
|
|||||||
global.expect(res.body.err).to.be `undefined` if code is 200
|
global.expect(res.body.err).to.be `undefined` if code is 200
|
||||||
global.expect(res.statusCode).to.be code
|
global.expect(res.statusCode).to.be code
|
||||||
|
|
||||||
|
|
||||||
global.registerNewUser = (cb, main) ->
|
global.registerNewUser = (cb, main) ->
|
||||||
main = true unless main?
|
main = true unless main?
|
||||||
randomID = shared.uuid()
|
randomID = shared.uuid()
|
||||||
|
|||||||
Reference in New Issue
Block a user