On Tue, 27 Dec 2016 21:07:05 GMT, Sönke Ludwig wrote:

On Tue, 27 Dec 2016 07:53:36 GMT, Joshua Hodkinson wrote:

Hey guys,

I'm curious about how to approach unit testing a class being utilized in the web framework, e.g checking routes return the correct content, that auth is being check correctly, etc.

I have seen the createTestHTTPServerRequest and createTestHTTPServerResponse functions, but I'm not entirely sure how to utilize them, does anyone have examples?

Thanks

There are some simple uses in the router unit tests. If you need to send a body, you can pass a MemoryStream to createTestHTTPServerRequest (or any other stream type).

However, this API alone is not particularly convenient when doing more complex tests. There is an open pull request that attempts to implement a nicer API on top. It got stuck in a state of discussion, but should eventually become part of the library. For now, you could manually take the code there and use it for implementing the tests.

Ok thanks for that, how might I go about mocking up a mongo connection? I could start a new instance with the pre build commands in the test configuration but that's starting to approach integration tests.

I might need to consider having interface which would make testing easier + moving to a rest api at a later date easier.