Rename Client to OrbitDB and set it as module's entry point. Move files to appropriate directories.

This commit is contained in:
haad
2016-04-27 08:48:12 +02:00
parent 81a54f762d
commit 3d12247bdb
18 changed files with 59 additions and 103 deletions

View File

@@ -1,12 +1,12 @@
'use strict';
const _ = require('lodash');
const path = require('path');
const assert = require('assert');
const async = require('asyncawait/async');
const await = require('asyncawait/await');
const ipfsd = require('ipfsd-ctl');
const OrbitClient = require('../src/Client');
const _ = require('lodash');
const path = require('path');
const assert = require('assert');
const async = require('asyncawait/async');
const await = require('asyncawait/await');
const ipfsd = require('ipfsd-ctl');
const OrbitDB = require('../src/OrbitDB');
// Mute logging
require('logplease').setLogLevel('ERROR');
@@ -44,9 +44,7 @@ describe('Orbit Client', function() {
try {
ipfs = await(startIpfs());
client = await(OrbitClient.connect('localhost', 3333, username, password, ipfs, { allowOffline: true }));
// db = await(client.channel(channel, '', false));
// db.delete();
client = await(OrbitDB.connect('localhost', 3333, username, password, ipfs, { allowOffline: true }));
} catch(e) {
console.log(e);
assert.equal(e, null);
@@ -134,9 +132,10 @@ describe('Orbit Client', function() {
*/
describe('Add events', function() {
beforeEach(async(() => {
beforeEach(async((done) => {
db = await(client.eventlog(channel, false));
db.delete();
done();
}));
it('adds an item to an empty channel', async((done) => {
@@ -183,8 +182,6 @@ describe('Orbit Client', function() {
beforeEach(async(() => {
db = await(client.eventlog(channel, false));
db.delete();
// const items = db.iterator().collect();
// assert.equal(items.length, 0);
}));
it('deletes an item when only one item in the database', async((done) => {
@@ -530,10 +527,6 @@ describe('Orbit Client', function() {
});
describe('Key-Value Store', function() {
// before(() => {
// db.delete();
// });
beforeEach(async((done) => {
db = await(client.kvstore(channel, '', false));
db.delete();
@@ -545,15 +538,9 @@ describe('Orbit Client', function() {
});
it('put', async((done) => {
// db = await(client.kvstore(channel, '', false));
await(db.put('key1', 'hello!'));
const value = db.get('key1');
// let all = db.iterator().collect();
assert.equal(value, 'hello!');
// assert.equal(all.length, 1);
// assert.equal(all[0].hash.startsWith('Qm'), true);
// assert.equal(all[0].key, 'key1');
// assert.notEqual(all[0].meta, null);
done();
}));
@@ -572,6 +559,19 @@ describe('Orbit Client', function() {
done();
}));
it('put/get - multiple keys', async((done) => {
await(db.put('key1', 'hello1'));
await(db.put('key2', 'hello2'));
await(db.put('key3', 'hello3'));
const v1 = db.get('key1');
const v2 = db.get('key2');
const v3 = db.get('key3');
assert.equal(v1, 'hello1');
assert.equal(v2, 'hello2');
assert.equal(v3, 'hello3');
done();
}));
it('deletes a key', async((done) => {
await(db.put('key1', 'hello!'));
await(db.del('key1'));
@@ -590,28 +590,6 @@ describe('Orbit Client', function() {
done();
}));
it('put - multiple keys', async((done) => {
await(db.put('key1', 'hello1'));
await(db.put('key2', 'hello2'));
await(db.put('key3', 'hello3'));
// const all = db.iterator().collect();
// assert.equal(all.length, 1);
done();
}));
it('get - multiple keys', async((done) => {
await(db.put('key1', 'hello1'));
await(db.put('key2', 'hello2'));
await(db.put('key3', 'hello3'));
const v1 = db.get('key1');
const v2 = db.get('key2');
const v3 = db.get('key3');
assert.equal(v1, 'hello1');
assert.equal(v2, 'hello2');
assert.equal(v3, 'hello3');
done();
}));
it('get - integer value', async((done) => {
await(db.put('key1', 123));
const v1 = db.get('key1');
@@ -623,7 +601,6 @@ describe('Orbit Client', function() {
const val = { one: 'first', two: 2 };
await(db.put('key1', val));
const v1 = db.get('key1');
// console.log(v1)
assert.equal(_.isEqual(v1, val), true);
done();
}));

View File

@@ -4,7 +4,7 @@ const assert = require('assert');
const Promise = require('bluebird');
const rimraf = require('rimraf')
const ipfsd = require('ipfsd-ctl');
const OrbitClient = require('../src/Client');
const OrbitDB = require('../src/OrbitDB');
const OrbitServer = require('orbit-server/src/server');
// Mute logging
@@ -42,7 +42,7 @@ describe('CounterStore', function() {
startIpfs().then((res) => {
ipfs = res;
Promise.map([username, username2], (login) => {
return OrbitClient.connect('localhost', 3333, login, '', ipfs, { allowOffline: false, cacheFile: './orbit-db-cache.json' });
return OrbitDB.connect('localhost', 3333, login, '', ipfs, { allowOffline: false, cacheFile: './orbit-db-cache.json' });
}).then((clients) => {
client1 = clients[0];
client2 = clients[1];