DEV: Add tests for invite system (PR #12524)

This includes only tests and minor fixes of bugs discovered while writing tests. Another pull request will cover more of the client side.

GitHub

Awesome, I looooove tests!