From 7818b5ca79888822a598af1909c1e0bdeb7176db Mon Sep 17 00:00:00 2001 From: haad Date: Sun, 31 Dec 2017 17:11:04 +0200 Subject: [PATCH] Add a test for dropping a database --- test/drop.test.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/drop.test.js diff --git a/test/drop.test.js b/test/drop.test.js new file mode 100644 index 0000000..ff26dcb --- /dev/null +++ b/test/drop.test.js @@ -0,0 +1,50 @@ +'use strict' + +const assert = require('assert') +const fs = require('fs') +const path = require('path') +const rmrf = require('rimraf') +const OrbitDB = require('../src/OrbitDB') +const config = require('./utils/config') +const startIpfs = require('./utils/start-ipfs') + +const dbPath = './orbitdb/tests/drop' +const ipfsPath = './orbitdb/tests/drop/ipfs' + +describe('orbit-db - Drop Database', function() { + this.timeout(config.timeout) + + let ipfs, orbitdb, db, address + let localDataPath + + before(async () => { + config.daemon1.repo = ipfsPath + rmrf.sync(config.daemon1.repo) + rmrf.sync(dbPath) + ipfs = await startIpfs(config.daemon1) + orbitdb = new OrbitDB(ipfs, dbPath) + }) + + after(async () => { + if(orbitdb) + orbitdb.stop() + + if (ipfs) + await ipfs.stop() + + rmrf.sync(dbPath) + }) + + describe('Drop', function() { + before(async () => { + db = await orbitdb.create('first', 'feed') + localDataPath = path.join(dbPath, db.address.root, db.address.path) + assert.equal(fs.existsSync(localDataPath), true) + }) + + it('removes local database files', async () => { + await db.drop() + assert.equal(fs.existsSync(localDataPath), false) + }) + }) +})