diff --git a/test/unit/local-data.spec.js b/test/unit/local-data.spec.js new file mode 100644 index 000000000..0627889f6 --- /dev/null +++ b/test/unit/local-data.spec.js @@ -0,0 +1,37 @@ +'use strict'; + +const assert = require('assert'); +const LocalData = require('../../src/lib/storage/local/local-data'); +const path = require('path'); +const _ = require('lodash'); + + +describe('Local Database', function() { + + + describe('reading database', () => { + + const buildCorruptedPath = () => path.join(__dirname, './partials/storage/verdaccio-corrupted.db.json'); + + it('should return empty database on read corrupted database', () => { + const config = new LocalData(buildCorruptedPath()); + assert(_.isEmpty(config.data.list)); + }); + + it('should return a database on read valid database', () => { + const config = new LocalData(path.join(__dirname, './partials/storage/verdaccio.db.json')); + assert(_.isEmpty(config.data.list) === false); + }); + + it('should fails on sync a corrupted database', () => { + const config = new LocalData(buildCorruptedPath()); + const error = config.sync(); + + assert(_.isError(error)); + assert(error.message.match(/locked/)); + }); + + }); + +}); + diff --git a/test/unit/partials/storage/verdaccio-corrupted.db.json b/test/unit/partials/storage/verdaccio-corrupted.db.json new file mode 100644 index 000000000..9950bb074 --- /dev/null +++ b/test/unit/partials/storage/verdaccio-corrupted.db.json @@ -0,0 +1 @@ +{"list"[],"secret":"14705eeaed167749990dafa07f908d2a9504bfdb0f6ca4102eed5acba0bc9076"} diff --git a/test/unit/partials/storage/verdaccio.db.json b/test/unit/partials/storage/verdaccio.db.json new file mode 100644 index 000000000..3759b48f0 --- /dev/null +++ b/test/unit/partials/storage/verdaccio.db.json @@ -0,0 +1 @@ +{"list":["@verdaccio/test"],"secret":"48cd053de97d4ef34aea4f1efb902334442bea1e735df5fdc9424c986a281b3d"}