Remove more boilerplate using helpers

- refactor common boiler and use closure for unique part of test
- inline json data
- add test for invalid JSON
- Simulate a fake database error