Closed davidwood closed 10 years ago
Ah you added the "missing document" error. Yeah, I kind of forgot that one! Hm, there are a couple of things I would like to ask you.
One is about the JavaScript pattern used.
I'm using a pattern that uses multiple if
operands, instead of if/else
. You can read about this pattern here (check the versus example).
If is not a bother, can you rewrite it to be like that? (yeah, I know is silly, but I'm trying to keep all the code like that)
The other thing I wanted to mention is about db.__doc_count
.
On lib/mockDB.js
, I'm creating that function as an non-enumerable method. The idea is to provide several methods that can be called from the unit test code to check things without requiring to make an http request. (Right now, they are not "several"; only that one, and is not even mentioned in the documentation. But once I add more, that will change.)
At the moment, that function only returns the count of the array. So, in the end is the same as using .length
on the array of the keys (like I'm doing on lib/mockDB.js
), or using __.size
on underscore (like you are doing).
However, once I add the ability to delete documents by posting "_deleted":true
, that function will also filter out those documents, and it will be not only a counter, like it is right now.
So I think is better to use that function instead of using __.size
.
What you think?
Your code does what it should and the new tests are nice, so, if you change those thing, I'll accept them. And thanks a lot for your contributions! I really appreciate them ;)
I tweak the conditionals to not use if/else
.
I also rewrote the __doc_count
to use a reduce function to only count the docs where _deleted
is not true
and updated doc_count
property to use this instead of __.size
. I also updated the mockDB factory function, to make it a bit more concise.
Ok, merged. Thanks!
When requesting a document that does not exist, a 404 error should be returned, but the server was returning a 500.
I also added tests for the get_db code, and fixed an error with the doc_count return value.