db.unit.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const { assert, expect, should } = require('chai');
  2. const db = require('../lib/db');
  3. const paths = require('../config/paths.json');
  4. const settings = require('../config/settings.json'); // get the settings
  5. const dirs = Object.keys(paths); // get a list of the paths from the keys
  6. const defaults = settings.defaults || {}; // load the defaults
  7. describe('DB tests', function() {
  8. let database, options, dir;
  9. let payload = {
  10. "input": "/some/path/to/a/file",
  11. "output": "/another/path/to/a/file",
  12. "status": "",
  13. "date": new Date()
  14. };
  15. before(async function() {
  16. dir = dirs[0];
  17. options = Object.assign({}, defaults, paths[dir]); // baseline the options
  18. database = db.connect(dir,options);
  19. });
  20. it('set', async function() {
  21. const result = await db.set(database, payload);
  22. expect(result).to.be.an('object');
  23. expect(result.input).to.equal('/some/path/to/a/file');
  24. });
  25. it('update', async function() {
  26. payload.status = 'updated';
  27. const result = await db.set(database, '/some/path/to/a/file', payload);
  28. expect(result).to.be.an('object');
  29. expect(result.status).to.equal('updated');
  30. });
  31. it('find', async function() {
  32. const result = await db.find(database,'/some/path/to/a/file');
  33. expect(result).to.be.an('object');
  34. expect(result.input).to.equal('/some/path/to/a/file');
  35. });
  36. it('remove', async function() {
  37. await db.remove(database,'/some/path/to/a/file');
  38. });
  39. });