habitica/test/api-legacy
2015-10-22 18:04:16 -05:00
..
anonymized.coffee Fix legacy tests 2015-10-20 20:17:10 -05:00
api-helper.js Convert legacy api helper to js 2015-10-20 21:53:52 -05:00
challenges.coffee Fix legacy tests 2015-10-20 20:17:10 -05:00
chat.coffee Fix legacy tests 2015-10-20 20:17:10 -05:00
coupons.coffee Fix legacy tests 2015-10-20 20:17:10 -05:00
get_user.coffee Rename existing api tests to api-legacy 2015-09-16 08:12:47 -05:00
groups.coffee Move group tests to new test structure 2015-10-22 18:04:16 -05:00
inAppPurchases.coffee Merge branch 'develop' into new_api_test_infrastructure 2015-10-20 21:18:49 -05:00
party.coffee Fix legacy tests 2015-10-20 20:17:10 -05:00
pushNotifications.coffee Fix legacy tests 2015-10-20 20:17:10 -05:00
README.md Rename existing api tests to api-legacy 2015-09-16 08:12:47 -05:00
score.coffee Fix legacy tests 2015-10-20 20:17:10 -05:00
subscriptions.coffee Rename existing api tests to api-legacy 2015-09-16 08:12:47 -05:00
todos.coffee Fix legacy tests 2015-10-20 20:17:10 -05:00
users.coffee Fix legacy tests 2015-10-20 20:17:10 -05:00

API Tests

Our API tests are written in coffeescript using the Mocha testing framework.

There's a variety of ways to run the tests:

# Individually
mocha test/api/name_of_test.coffee
# The entire collection of api tests
mocha test/api
# As part of the whole test suite
npm test

Modules

Some modules are declared in the 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 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.