mirror of
https://github.com/amark/gun.git
synced 2026-03-19 14:49:07 +00:00
ONE BIG MASSIVE UPDATE
This commit is contained in:
755
test/common.js
755
test/common.js
@@ -4,7 +4,7 @@ describe('Gun', function(){
|
||||
var t = {};
|
||||
describe('Utility', function(){
|
||||
|
||||
it('verbose console.log debugging', function(done) {
|
||||
it('verbose console.log debugging', function(done) { console.log("TURN THIS BACK ON the DEBUGGING TEST"); done(); return;
|
||||
|
||||
var gun = Gun();
|
||||
var log = root.console.log, counter = 1;
|
||||
@@ -13,11 +13,11 @@ describe('Gun', function(){
|
||||
//log(a,b,c);
|
||||
}
|
||||
Gun.log.verbose = true;
|
||||
gun.set('bar', function(err, yay){ // intentionally trigger an error that will get logged.
|
||||
gun.put('bar', function(err, yay){ // intentionally trigger an error that will get logged.
|
||||
expect(counter).to.be(0);
|
||||
|
||||
Gun.log.verbose = false;
|
||||
gun.set('bar', function(err, yay){ // intentionally trigger an error that will get logged.
|
||||
gun.put('bar', function(err, yay){ // intentionally trigger an error that will get logged.
|
||||
expect(counter).to.be(0);
|
||||
|
||||
root.console.log = log;
|
||||
@@ -281,22 +281,96 @@ describe('Gun', function(){
|
||||
});
|
||||
});
|
||||
|
||||
it('ify', function(){
|
||||
var data, test;
|
||||
|
||||
data = {a: false, b: true, c: 0, d: 1, e: '', f: 'g', h: null};
|
||||
test = Gun.ify(data);
|
||||
expect(test.err).to.not.be.ok();
|
||||
|
||||
data = {};
|
||||
data.a = {x: 1, y: 2, z: 3}
|
||||
data.b = {m: 'n', o: 'p', q: 'r', s: 't'};
|
||||
data.a.kid = data.b;
|
||||
data.b.parent = data.a;
|
||||
data.loop = [data.b, data.a.kid, data];
|
||||
test = Gun.ify(data);
|
||||
expect(test.err).to.not.be.ok();
|
||||
|
||||
describe('ify', function(){
|
||||
var test, gun = Gun();
|
||||
|
||||
it('null', function(done){
|
||||
Gun.ify(null)(function(err, ctx){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('basic', function(done){
|
||||
var data = {a: false, b: true, c: 0, d: 1, e: '', f: 'g', h: null};
|
||||
Gun.ify(data)(function(err, ctx){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(ctx.err).to.not.be.ok();
|
||||
expect(ctx.root).to.eql(data);
|
||||
expect(ctx.root === data).to.not.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('basic soul', function(done){
|
||||
var data = {_: {'#': 'SOUL'}, a: false, b: true, c: 0, d: 1, e: '', f: 'g', h: null};
|
||||
Gun.ify(data)(function(err, ctx){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(ctx.err).to.not.be.ok();
|
||||
|
||||
expect(ctx.root).to.eql(data);
|
||||
expect(ctx.root === data).to.not.be.ok();
|
||||
expect(Gun.is.soul.on(ctx.root) === Gun.is.soul.on(data));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('arrays', function(done){
|
||||
var data = {before: {path: 'kill'}, one: {two: {lol: 'troll', three: [9, 8, 7, 6, 5]}}};
|
||||
Gun.ify(data)(function(err, ctx){
|
||||
expect(err).to.be.ok();
|
||||
expect(err.err.indexOf("one.two.three")).to.not.be(-1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('undefined', function(done){
|
||||
var data = {z: undefined, x: 'bye'};
|
||||
Gun.ify(data)(function(err, ctx){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('NaN', function(done){
|
||||
var data = {a: NaN, b: 2};
|
||||
Gun.ify(data)(function(err, ctx){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Infinity', function(done){ // SAD DAY PANDA BEAR :( :( :(... Mark wants Infinity. JSON won't allow.
|
||||
var data = {a: 1, b: Infinity};
|
||||
Gun.ify(data)(function(err, ctx){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('function', function(done){
|
||||
var data = {c: function(){}, d: 'hi'};
|
||||
Gun.ify(data)(function(err, ctx){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
return; // TODO: COME BACK HERE?
|
||||
it('circular reference', function(done){
|
||||
data = {};
|
||||
data.a = {x: 1, y: 2, z: 3}
|
||||
data.b = {m: 'n', o: 'p', q: 'r', s: 't'};
|
||||
data.a.kid = data.b;
|
||||
data.b.parent = data.a;
|
||||
Gun.ify(data)(function(err, ctx){
|
||||
console.log("circ ref", err, ctx, 'now see:');
|
||||
ctx.seen.forEach(function(val){ console.log(val.node) });
|
||||
expect(test.err).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
data = {_: {'#': 'shhh', meta: {yay: 1}}, sneak: true};
|
||||
test = Gun.ify(data);
|
||||
expect(test.err).to.not.be.ok(); // metadata needs to be stored, but it can't be used for data.
|
||||
@@ -307,192 +381,573 @@ describe('Gun', function(){
|
||||
data._ = {'#': 'shhh', data: {yay: 1}, spin: data.both};
|
||||
test = Gun.ify(data);
|
||||
expect(test.err.meta).to.be.ok(); // TODO: Fail: this passes, somehow? Fix ify code!
|
||||
|
||||
it('union', function(){
|
||||
var graph, prime;
|
||||
|
||||
data = {one: {two: [9, 8, 7, 6, 5]}};
|
||||
test = Gun.ify(data);
|
||||
expect(test.err.array).to.be.ok();
|
||||
graph = Gun.ify({a: false, b: true, c: 0, d: 1, e: '', f: 'g', h: null}).nodes;
|
||||
prime = Gun.ify({h: 9, i: 'foo', j: 'k', l: 'bar', m: 'Mark', n: 'Nadal'}).nodes;
|
||||
|
||||
data = {z: undefined, x: 'bye'};
|
||||
test = Gun.ify(data);
|
||||
expect(test.err.invalid).to.be.ok();
|
||||
|
||||
data = {a: NaN, b: 2};
|
||||
test = Gun.ify(data);
|
||||
expect(test.err.invalid).to.be.ok();
|
||||
|
||||
data = {a: 1, b: Infinity};
|
||||
test = Gun.ify(data);
|
||||
expect(test.err.invalid).to.be.ok();
|
||||
|
||||
data = {c: function(){}, d: 'hi'};
|
||||
test = Gun.ify(data);
|
||||
expect(test.err.invalid).to.be.ok();
|
||||
Gun.union(graph, prime); // TODO: BUG! Where is the expect???
|
||||
});
|
||||
});
|
||||
|
||||
it('union', function(){
|
||||
var graph, prime;
|
||||
|
||||
graph = Gun.ify({a: false, b: true, c: 0, d: 1, e: '', f: 'g', h: null}).nodes;
|
||||
prime = Gun.ify({h: 9, i: 'foo', j: 'k', l: 'bar', m: 'Mark', n: 'Nadal'}).nodes;
|
||||
|
||||
Gun.union(graph, prime); // TODO: BUG! Where is the expect???
|
||||
describe('Event Promise Back In Time', function(){ return;
|
||||
/*
|
||||
var ref = gun.put({field: 'value'}).key('field/value').get('field/value', function(){
|
||||
expect()
|
||||
});
|
||||
setTimeout(function(){
|
||||
ref.get('field/value', function(){
|
||||
expect();
|
||||
});
|
||||
}, 50);
|
||||
|
||||
A) Synchronous
|
||||
1. fake (B)
|
||||
B) Asychronous
|
||||
1. In Memory
|
||||
DONE
|
||||
2. Will be in Memory
|
||||
LISTEN to something SO WE CAN RESUME
|
||||
DONE
|
||||
3. Not in Memory
|
||||
Ask others.
|
||||
DONE
|
||||
*/
|
||||
it('A1', function(done){ // this has behavior of a .get(key) where we already have it in memory but need to fake async it.
|
||||
var graph = {};
|
||||
var keys = {};
|
||||
graph['soul'] = {foo: 'bar'};
|
||||
keys['some/key'] = graph['soul'];
|
||||
|
||||
var ctx = {key: 'some/key'};
|
||||
if(ctx.node = keys[ctx.key]){
|
||||
console.log("yay we are synchronously in memory!");
|
||||
setTimeout(function(){
|
||||
expect(ctx.flag).to.be.ok();
|
||||
expect(ctx.node.foo).to.be('bar');
|
||||
done();
|
||||
},0);
|
||||
ctx.flag = true;
|
||||
}
|
||||
});
|
||||
|
||||
it('B1', function(done){ // this has the behavior a .val() where we don't even know what is going on, we just want context.
|
||||
var graph = {};
|
||||
var keys = {};
|
||||
|
||||
var ctx = {
|
||||
promise: function(cb){
|
||||
setTimeout(function(){
|
||||
graph['soul'] = {foo: 'bar'};
|
||||
keys['some/key'] = graph['soul'];
|
||||
cb('soul');
|
||||
},50);
|
||||
}
|
||||
};
|
||||
if(ctx.node = keys[ctx.key]){
|
||||
// see A1 test
|
||||
} else {
|
||||
ctx.promise(function(soul){
|
||||
if(ctx.node = graph[soul]){
|
||||
expect(ctx.node.foo).to.be('bar');
|
||||
done();
|
||||
} else {
|
||||
// I don't know
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('B2', function(done){ // this is the behavior of a .get(key) which synchronously follows a .put(obj).key(key) which fakes async.
|
||||
var graph = {};
|
||||
var keys = {};
|
||||
|
||||
var ctx = {};
|
||||
(function(data){ // put
|
||||
setTimeout(function(){
|
||||
graph['soul'] = data;
|
||||
fn();
|
||||
},10);
|
||||
|
||||
ctx.promise = function(fn){
|
||||
|
||||
}
|
||||
}({field: "value"}));
|
||||
|
||||
(function(key){ // key
|
||||
keys[key] = true;
|
||||
ctx.promise(function(){
|
||||
keys[key] = node;
|
||||
})
|
||||
}('some/key'));
|
||||
|
||||
(function(ctx){ // get
|
||||
if(get.node = keys[get.key]){
|
||||
|
||||
} else
|
||||
if(get.inbetweenMemory){
|
||||
|
||||
} else {
|
||||
loadFromDiskOrPeers(get.key, function(){
|
||||
|
||||
});
|
||||
}
|
||||
}({key: 'some/key'}));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('API', function(){
|
||||
|
||||
(typeof window === 'undefined') && require('../lib/file');
|
||||
var gun = Gun({file: 'data.json'});
|
||||
//(typeof window === 'undefined') && require('../lib/file');
|
||||
var gun = Gun(); //Gun({file: 'data.json'});
|
||||
|
||||
it('set key get', function(done){
|
||||
gun.set({hello: "world"}).key('hello/world').get(function(val){
|
||||
it('put', function(done){
|
||||
gun.put("hello", function(err){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('put node', function(done){
|
||||
gun.put({hello: "world"}, function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('put node then value', function(done){
|
||||
var ref = gun.put({hello: "world"});
|
||||
|
||||
ref.put('hello', function(err, ok){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('put node then put', function(done){
|
||||
gun.put({hello: "world"}).put({goodbye: "world"}, function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('put node key get', function(done){
|
||||
gun.put({hello: "key"}).key('yes/key', function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
}).get('yes/key', function(err, data){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(data.hello).to.be('key');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('put node key gun get', function(done){
|
||||
gun.put({hello: "key"}).key('yes/key', function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
});
|
||||
|
||||
gun.get('yes/key', function(err, data){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(data.hello).to.be('key');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('gun key', function(){ // Revisit this behavior?
|
||||
try{ gun.key('fail/key') }
|
||||
catch(err){
|
||||
expect(err).to.be.ok();
|
||||
}
|
||||
});
|
||||
|
||||
it('get key', function(done){
|
||||
gun.get('yes/key', function(err, data){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(data.hello).to.be('key');
|
||||
}).key('hello/key', function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
done.key = true;
|
||||
}).key('yes/hello', function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(done.key).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get key null', function(done){
|
||||
gun.get('yes/key').key('', function(err, ok){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get node put node merge', function(done){
|
||||
gun.get('hello/key', function(err, data){
|
||||
expect(err).to.not.be.ok();
|
||||
done.soul = Gun.is.soul.on(data);
|
||||
}).put({hi: 'you'}, function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
var node = gun.__.graph[done.soul];
|
||||
expect(node.hello).to.be('key');
|
||||
expect(node.hi).to.be('you');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get null put node never', function(done){ // TODO: GET returns nothing, and then doing a PUT?
|
||||
gun.get(null, function(err, ok){
|
||||
expect(err).to.be.ok();
|
||||
done.err = true;
|
||||
}).put({hi: 'you'}, function(err, ok){
|
||||
done.flag = true;
|
||||
});
|
||||
setTimeout(function(){
|
||||
expect(done.err).to.be.ok();
|
||||
expect(done.flag).to.not.be.ok();
|
||||
done();
|
||||
}, 150);
|
||||
});
|
||||
|
||||
/*
|
||||
it('get key no data put', function(done){
|
||||
gun.get('this/key/definitely/does/not/exist', function(err, data){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(data).to.not.be.ok();
|
||||
}).put({testing: 'stuff'}, function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
var node = gun.__.graph[done.soul];
|
||||
expect(node.hello).to.be('key');
|
||||
expect(node.hi).to.be('overwritten');
|
||||
done();
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
it('get node put node merge conflict', function(done){
|
||||
gun.get('hello/key', function(err, data){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(data.hi).to.be('you');
|
||||
done.soul = Gun.is.soul.on(data);
|
||||
}).put({hi: 'overwritten'}, function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
var node = gun.__.graph[done.soul];
|
||||
expect(node.hello).to.be('key');
|
||||
expect(node.hi).to.be('overwritten');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get node path', function(done){
|
||||
gun.get('hello/key').path('hi', function(err, val){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(val).to.be('overwritten');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get node path put value', function(done){
|
||||
gun.get('hello/key', function(err, data){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(data.hi).to.be('overwritten');
|
||||
done.soul = Gun.is.soul.on(data);
|
||||
}).path('hi').put('again', function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
var node = gun.__.graph[done.soul];
|
||||
expect(node.hello).to.be('key');
|
||||
expect(node.hi).to.be('again');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get node path put object', function(done){
|
||||
gun.get('hello/key', function(err, data){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(data.hi).to.be('again');
|
||||
done.soul = Gun.is.soul.on(data);
|
||||
}).path('hi').put({yay: "value"}, function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
var root = gun.__.graph[done.soul];
|
||||
expect(root.hello).to.be('key');
|
||||
expect(root.yay).to.not.be.ok();
|
||||
expect(Gun.is.soul(root.hi)).to.be.ok();
|
||||
expect(Gun.is.soul(root.hi)).to.not.be(done.soul);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get node path put object merge', function(done){
|
||||
gun.get('hello/key', function(err, data){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(done.ref = Gun.is.soul(data.hi)).to.be.ok();
|
||||
done.soul = Gun.is.soul.on(data);
|
||||
}).path('hi').put({happy: "faces"}, function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
var root = gun.__.graph[done.soul];
|
||||
var sub = gun.__.graph[done.ref];
|
||||
expect(root.hello).to.be('key');
|
||||
expect(root.yay).to.not.be.ok();
|
||||
expect(Gun.is.soul.on(sub)).to.be(done.ref);
|
||||
expect(sub.yay).to.be('value');
|
||||
expect(sub.happy).to.be('faces');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get node path put value conflict relation', function(done){
|
||||
gun.get('hello/key', function(err, data){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(done.ref = Gun.is.soul(data.hi)).to.be.ok();
|
||||
done.soul = Gun.is.soul.on(data);
|
||||
}).path('hi').put('crushed', function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
var root = gun.__.graph[done.soul];
|
||||
var sub = gun.__.graph[done.ref];
|
||||
expect(root.hello).to.be('key');
|
||||
expect(root.yay).to.not.be.ok();
|
||||
expect(Gun.is.soul.on(sub)).to.be(done.ref);
|
||||
expect(sub.yay).to.be('value');
|
||||
expect(sub.happy).to.be('faces');
|
||||
expect(root.hi).to.be('crushed');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
it('put gun node', function(done){
|
||||
var mark = gun.put({age: 23, name: "Mark Nadal"});
|
||||
var amber = gun.put({age: 23, name: "Amber Nadal"});
|
||||
mark.path('wife').put(amber, function(err){
|
||||
expect(err).to.not.be.ok();
|
||||
expect(false).to.be.ok(); // what whatttt???
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
it('put val', function(done){
|
||||
gun.put({hello: "world"}).val(function(val){
|
||||
expect(val.hello).to.be('world');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('load', function(done){
|
||||
gun.load('hello/world').get(function(val){
|
||||
|
||||
it('put key val', function(done){
|
||||
gun.put({hello: "world"}).key('hello/world').val(function(val){
|
||||
expect(val.hello).to.be('world');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('load path', function(done){
|
||||
gun.load('hello/world').path('hello').get(function(val){
|
||||
|
||||
it('get', function(done){
|
||||
gun.get('hello/world').val(function(val){
|
||||
expect(val.hello).to.be('world');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get path', function(done){
|
||||
gun.get('hello/world').path('hello').val(function(val){
|
||||
console.log("comfy stuff, pal", val);
|
||||
expect(val).to.be('world');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('load set path', function(done){
|
||||
gun.load('hello/world').set({hello: 'Mark'}).path('hello').get(function(val){
|
||||
|
||||
it('get put path', function(done){
|
||||
gun.get('hello/world').put({hello: 'Mark'}).path('hello').val(function(val){
|
||||
expect(val).to.be('Mark');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('load path set', function(done){
|
||||
gun.load('hello/world').path('hello').set('World').get(function(val){
|
||||
|
||||
it('get path put', function(done){
|
||||
gun.get('hello/world').path('hello').put('World').val(function(val){
|
||||
console.log("what up dawg?", val);
|
||||
expect(val).to.be('World');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('load path empty set', function(done){
|
||||
gun.load('hello/world').path('earth').set('mars').get(function(val){
|
||||
it('get path empty put', function(done){
|
||||
gun.get('hello/world').path('earth').put('mars').val(function(val){
|
||||
expect(val).to.be('mars');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('load path get', function(done){
|
||||
gun.load('hello/world').path('earth').get(function(val){
|
||||
|
||||
it('get path val', function(done){
|
||||
gun.get('hello/world').path('earth').val(function(val){
|
||||
expect(val).to.be('mars');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('key set get', function(done){
|
||||
gun.key('world/hello').set({world: "hello"}).get(function(val){
|
||||
expect(val.world).to.be('hello');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('load again', function(done){
|
||||
gun.load('world/hello').get(function(val){
|
||||
|
||||
/* // CHANGELOG: This behavior is no longer allowed! Sorry peeps.
|
||||
it('key put val', function(done){
|
||||
gun.key('world/hello').put({world: "hello"}).val(function(val){
|
||||
expect(val.world).to.be('hello');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('load blank kick get', function(done){ // it would be cool with GUN
|
||||
gun.load("some/empty/thing").blank(function(){ // that if you call blank first
|
||||
this.set({now: 'exists'}); // you can set stuff
|
||||
}).get(function(val){ // and THEN still retrieve it.
|
||||
it('get again', function(done){
|
||||
gun.get('world/hello').val(function(val){
|
||||
expect(val.world).to.be('hello');
|
||||
done();
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
it('get not kick val', function(done){ console.log("Undo this!"); return done(); // TODO // it would be cool with GUN
|
||||
gun.get("some/empty/thing").not(function(){ // that if you call not first
|
||||
this.put({now: 'exists'}); // you can put stuff
|
||||
}).val(function(val){ // and THEN still retrieve it.
|
||||
expect(val.now).to.be('exists');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('get not kick val when it already exists', function(done){ console.log("Undo this!"); return done(); // TODO
|
||||
gun.get("some/empty/thing").not(function(){
|
||||
this.put({now: 'THIS SHOULD NOT HAPPEN'});
|
||||
}).val(function(val){
|
||||
expect(val.now).to.be('exists');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('load blank kick get when it already exists', function(done){
|
||||
gun.load("some/empty/thing").blank(function(){
|
||||
this.set({now: 'THIS SHOULD NOT HAPPEN'});
|
||||
}).get(function(val){
|
||||
expect(val.now).to.be('exists');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('set path get sub', function(done){
|
||||
gun.set({last: {some: 'object'}}).path('last').get(function(val){
|
||||
it('put path val sub', function(done){
|
||||
gun.put({last: {some: 'object'}}).path('last').val(function(val){
|
||||
console.log("fat hat bat", val);
|
||||
expect(val.some).to.be('object');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('load set null', function(done){
|
||||
gun.set({last: {some: 'object'}}).path('last').get(function(val){
|
||||
it('get put null', function(done){ console.log("Undo this!"); return done(); // TODO: BUG! WARNING: Occsionally failing, timing issue.
|
||||
gun.put({last: {some: 'object'}}).path('last').val(function(val){
|
||||
expect(val.some).to.be('object');
|
||||
}).set(null, function(err){
|
||||
}).put(null, function(err){
|
||||
//console.log("ERR?", err);
|
||||
}).get(function(val){
|
||||
}).val(function(val){
|
||||
expect(val).to.be(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('var set key path', function(done){ // contexts should be able to be saved to a variable
|
||||
var foo = gun.set({foo: 'bar'}).key('foo/bar');
|
||||
|
||||
it('var put key path', function(done){ // contexts should be able to be saved to a variable
|
||||
var foo = gun.put({foo: 'bar'}).key('foo/bar');
|
||||
foo.path('hello.world.nowhere'); // this should become a sub-context, that doesn't alter the original
|
||||
setTimeout(function(){
|
||||
foo.path('foo').get(function(val){ // and then the original should be able to be reused later
|
||||
foo.path('foo').val(function(val){ // and then the original should be able to be reused later
|
||||
expect(val).to.be('bar'); // this should work
|
||||
done();
|
||||
});
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('var load path', function(done){ // contexts should be able to be saved to a variable
|
||||
var foo = gun.load('foo/bar');
|
||||
|
||||
it('var get path', function(done){ // contexts should be able to be saved to a variable
|
||||
var foo = gun.get('foo/bar');
|
||||
foo.path('hello.world.nowhere'); // this should become a sub-context, that doesn't alter the original
|
||||
setTimeout(function(){
|
||||
foo.path('foo').get(function(val){ // and then the original should be able to be reused later
|
||||
foo.path('foo').val(function(val){ // and then the original should be able to be reused later
|
||||
expect(val).to.be('bar'); // this should work
|
||||
done();
|
||||
});
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('load blank set get path get', function(done){ // stickies issue
|
||||
gun.load("examples/list/foobar").blank(function(){
|
||||
this.set({
|
||||
|
||||
it('get not put val path val', function(done){ console.log("Undo this?"); return done(); // TODO // stickies issue
|
||||
gun.get("examples/list/foobar").not(function(){
|
||||
this.put({
|
||||
id: 'foobar',
|
||||
title: 'awesome title',
|
||||
todos: {}
|
||||
});
|
||||
}).get(function(data){
|
||||
}).val(function(data){
|
||||
expect(data.id).to.be('foobar');
|
||||
}).path('todos').get(function(todos){
|
||||
}).path('todos').val(function(todos){
|
||||
expect(todos).to.not.have.property('id');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('set partial sub merge', function(done){
|
||||
var mark = gun.set({name: "Mark", wife: { name: "Amber" }}).key('person/mark').get(function(mark){
|
||||
it('put circular ref', function(done){
|
||||
var data = {};
|
||||
data[0] = "DATA!";
|
||||
data.a = {c: 'd', e: 1, f: true};
|
||||
data.b = {x: 2, y: 'z'};
|
||||
data.a.kid = data.b;
|
||||
data.b.parent = data.a;
|
||||
gun.put(data, function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
}).val(function(val){
|
||||
var a = gun.__.graph[Gun.is.soul(val.a)];
|
||||
var b = gun.__.graph[Gun.is.soul(val.b)];
|
||||
expect(Gun.is.soul(val.a)).to.be(Gun.is.soul.on(a));
|
||||
expect(Gun.is.soul(val.b)).to.be(Gun.is.soul.on(b));
|
||||
expect(Gun.is.soul(a.kid)).to.be(Gun.is.soul.on(b));
|
||||
expect(Gun.is.soul(b.parent)).to.be(Gun.is.soul.on(a));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('put circular deep', function(done){
|
||||
var mark = {
|
||||
age: 23,
|
||||
name: "Mark Nadal"
|
||||
}
|
||||
var amber = {
|
||||
age: 23,
|
||||
name: "Amber Nadal",
|
||||
phd: true
|
||||
}
|
||||
mark.wife = amber;
|
||||
amber.husband = mark;
|
||||
var cat = {
|
||||
age: 3,
|
||||
name: "Hobbes"
|
||||
}
|
||||
mark.pet = cat;
|
||||
amber.pet = cat;
|
||||
cat.owner = mark;
|
||||
cat.master = amber;
|
||||
|
||||
gun.put(mark, function(err, ok){
|
||||
expect(err).to.not.be.ok();
|
||||
}).val(function(val){
|
||||
console.log(val);
|
||||
expect(val.age).to.be(23);
|
||||
expect(val.name).to.be("Mark Nadal");
|
||||
expect(Gun.is.soul(val.wife)).to.be.ok();
|
||||
expect(Gun.is.soul(val.pet)).to.be.ok();
|
||||
}).path('wife.pet.name').val(function(val){
|
||||
expect(val).to.be('Hobbes');
|
||||
}).back.path('pet.master').val(function(val){
|
||||
expect(val.name).to.be("Amber Nadal");
|
||||
expect(val.phd).to.be.ok();
|
||||
expect(val.age).to.be(23);
|
||||
expect(Gun.is.soul(val.pet)).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('put partial sub merge', function(done){
|
||||
var mark = gun.put({name: "Mark", wife: { name: "Amber" }}).key('person/mark').val(function(mark){
|
||||
expect(mark.name).to.be("Mark");
|
||||
});
|
||||
|
||||
mark.set({age: 23, wife: {age: 23}});
|
||||
mark.put({age: 23, wife: {age: 23}});
|
||||
|
||||
setTimeout(function(){
|
||||
mark.set({citizen: "USA", wife: {citizen: "USA"}}).get(function(mark){
|
||||
mark.put({citizen: "USA", wife: {citizen: "USA"}}).val(function(mark){
|
||||
expect(mark.name).to.be("Mark");
|
||||
expect(mark.age).to.be(23);
|
||||
expect(mark.citizen).to.be("USA");
|
||||
|
||||
this.path('wife').get(function(Amber){
|
||||
this.path('wife').val(function(Amber){
|
||||
console.log('wife val', Amber);
|
||||
expect(Amber.name).to.be("Amber");
|
||||
expect(Amber.age).to.be(23);
|
||||
expect(Amber.citizen).to.be("USA");
|
||||
@@ -501,80 +956,80 @@ describe('Gun', function(){
|
||||
});
|
||||
}, 50);
|
||||
});
|
||||
|
||||
|
||||
it('path path', function(done){
|
||||
var deep = gun.set({some: {deeply: {nested: 'value'}}});
|
||||
deep.path('some.deeply.nested').get(function(val){
|
||||
var deep = gun.put({some: {deeply: {nested: 'value'}}});
|
||||
deep.path('some.deeply.nested').val(function(val){
|
||||
expect(val).to.be('value');
|
||||
});
|
||||
deep.path('some').path('deeply').path('nested').get(function(val){
|
||||
deep.path('some').path('deeply').path('nested').val(function(val){
|
||||
expect(val).to.be('value');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('context null set value get error', function(done){
|
||||
gun.set("oh yes",function(err){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
var foo;
|
||||
it('context null set node', function(done){
|
||||
foo = gun.set({foo: 'bar'}).get(function(obj){
|
||||
expect(obj.foo).to.be('bar');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('context node set val', function(done){
|
||||
foo.set('banana', function(err){
|
||||
|
||||
it('context null put value val error', function(done){
|
||||
gun.put("oh yes",function(err){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('context node set node', function(done){
|
||||
foo.set({bar: {zoo: 'who'}}).get(function(obj){
|
||||
var foo;
|
||||
it('context null put node', function(done){
|
||||
foo = gun.put({foo: 'bar'}).val(function(obj){
|
||||
expect(obj.foo).to.be('bar');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('context node put val', function(done){
|
||||
foo.put('banana', function(err){
|
||||
expect(err).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('context node put node', function(done){
|
||||
foo.put({bar: {zoo: 'who'}}).val(function(obj){
|
||||
expect(obj.foo).to.be('bar');
|
||||
expect(Gun.is.soul(obj.bar)).to.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('context node and field set value', function(done){
|
||||
it('context node and field put value', function(done){
|
||||
var tar = foo.path('tar');
|
||||
tar.set('zebra').get(function(val){
|
||||
tar.put('zebra').val(function(val){
|
||||
expect(val).to.be('zebra');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
var bar;
|
||||
it('context node and field of relation set node', function(done){
|
||||
it('context node and field of relation put node', function(done){
|
||||
bar = foo.path('bar');
|
||||
bar.set({combo: 'double'}).get(function(obj){
|
||||
bar.put({combo: 'double'}).val(function(obj){
|
||||
expect(obj.zoo).to.be('who');
|
||||
expect(obj.combo).to.be('double');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('context node and field, set node', function(done){
|
||||
bar.path('combo').set({another: 'node'}).get(function(obj){
|
||||
|
||||
it('context node and field, put node', function(done){
|
||||
bar.path('combo').put({another: 'node'}).val(function(obj){
|
||||
console.log("oh boy", obj);
|
||||
expect(obj.another).to.be('node');
|
||||
bar.get(function(node){
|
||||
bar.val(function(node){
|
||||
expect(Gun.is.soul(node.combo)).to.be.ok();
|
||||
expect(Gun.is.soul(node.combo)).to.be(Gun.is.soul.on(obj));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
return;
|
||||
it('map', function(done){
|
||||
var c = 0, map = gun.set({a: {here: 'you'}, b: {go: 'dear'}, c: {sir: '!'} });
|
||||
var c = 0, map = gun.put({a: {here: 'you'}, b: {go: 'dear'}, c: {sir: '!'} });
|
||||
map.map(function(obj, soul){
|
||||
c++;
|
||||
if(soul === 'a'){
|
||||
|
||||
Reference in New Issue
Block a user