Refactor the basic example given in the folder before to better enable unit tests to be done.
Each of the following files has been split into two:
authorize.js
-- becomesauthorize.js
andauthorizeHandler.js
booksquery.js
-- becomesbooksquery.js
andbooksqueryHandlers.js
favourites.js
-- becomesfavourites.js
andfavouritesHandlers.js
users.js
-- becomesusers.js
andusersHandlers.js
Route handling is now done in the *Handlers.js
files, and route-specific functionality appears in the specialised files.
Note that callbacks are used a lot in this code, to keep the concepts simple. However you can see that these are beginning to make the code messy.
Promises are a much better choice as the equivalent code would be much easier to read and understand.
Now that the files like authorize.js
, booksquery.js
, etc. do not contain request and response handling functionality, they can be properly unit tested using jasmine-node
or similar!