buddycloud/buddycloud-server — pull request #92 by Schnouki (2012-10-15 18:08:18+00:00)
Title: Unit tests

Hi world,

This branch adds unit tests to the node server.

Why another test suite when there's already [one in Java](https://github.com/buddycloud/buddycloud-test-suite), you will ask. Well, for several reasons.

- These tests are in the same repo as the code they cover, making it easier to do test-driven development, with new tests added in the same branches as new features or bug fixes.
- They are written in the same language as the server and using the same libs as the server, making it easier for server developers to read and write new tests.
- Since they run in the same process, we can even have full stack traces when something goes wrong.
- Everything needed to test federated services is available: disco entries, database setup, etc., without needing to run an actual XMPP server.
- Travis integration: once this is merged, we can enable the GitHub Travis hook and get free cool stuff: build report after each push and for pull requests, tests ran against Node 0.6 and 0.8, etc. It's also easier to setup than Jenkins, and requires almost no maintenance. The only thing Jenkins can do that Travis can't is to deploy the new code automatically on crater.

The Java test suite can probably be used against this server too. And if the Node server passes the Java tests, it will mean that both servers speak the same language, which would be freakin' cool :)

Right now these 50 tests only cover a few features:

- replying to disco and software version queries
- channel creation, with default config or not
- posting, replying and updating posts, to local and remote channels and from remote services, testing permissions on open and private channels
- retrieving posts, also testing permissions
- retracting local and remote posts, also testing permissions

As you can see in the history, this already allowed me to fix 8 bugs in the server. So I'm pretty happy with this.

In the future I'll add more tests for subscriptions/affiliations management, channel configuration, etc. And new features and bug fixes will include new tests to prevent regressions and make sure that everything behaves as documented.

If you want to test this: pull the branch, compile the server with `npm i .`, start PostgreSQL on your machine, and run `npm test`. On my laptop `npm test` takes 6 seconds, including almost 3s for preparing the DB.