Comment on page

General Developer Guidelines

Unit Testing + Higher Order Functions

Consider how unit testing will be done when creating code. In most cases, this means that use of external services should be done through injections of higher order functions, which can be simulated more easily in unit testing. For example: function foo(inputs){ // Business logic var result = collection.insert(doc) // business logic } In this case, unit testing this specific function would be quite difficult because our goal is to test that a specific input leads to a specific output or space of outputs. Instead, it would be easier to unit test by doing this: function foo(inputs, db_insert){ // Business logic var result = db_insert(doc) // business logic }
The db_insert function can then be separately unit tested or tested under integration testing.

Error Handling

Try to anticipate common errors that might come up and handle them. In general, API structures should include a error boolean at the top level of the JSON object so that the consuming service will know if an error has occurred or not. Additionally, include and err_msg field if there was an error along with an error code (integer). The error boolean should always be present. Log the error along with the most important pieces of the context to make identification and troubleshooting easier.