We are going to make our lives a lot easier if we write some helper code for our tests which ensures that at the start of each test run, the database is empty. Let's put this into spec/resetDatabase.js:
'use strict'; var async = require('async'); var resetDatabase = function (dbSession, callback) { async.series( [ function (callback) { dbSession.remove('keyword', '1', function (err) { callback(err) }); }, function (callback) { dbSession.remove('category', '1', function (err) { callback(err) }); } ], function (err, results) { callback(err); } ); }; module.exports = resetDatabase;
As you can see, we make use of a dbSession object. We need to create a module where this is set up, in file src/backend/dbSession...