Improved testing in books.spec and user.spec
Because users is a route that I am as of yet not using I wanted to do a
little proof of concept for myself to refer back to when it comes to
mocking request and response objects for testing my routes. A lot of
what I plan to do on the back end of this website will mostly be simple
routes returning json. I needed to learn how to mock.
The books.spec is a little more difficult to mock. I removed all the
horrible circular mocking that was in it before and tried once again to
use nock to intercept the books api call. It worked, but there is an
explanation in the file as to why I commented it out and felt it better
to leave this route untested. If my app is using a lot of googleapi
calls, it may become necessary to learn how to either properly work
around the google api calls in tests, or intercept them fully with
nock.It looks like nock recorder might help me figure out how.
Proper nock of discovery google call.
I did a nock.recorder.rec() in books to produce the code I put into a
module called discovery-nock.js. This file is returns a function to
call, that will in turn set up a nock for the call to the discovery api.
This change made it possible to nock the whole thing and therefore test
the route function. Kudos to nock.recorder.rec().
I also set up a simple mock for the books.index route.