mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Move multiple-get/set logic into individual context stores
This commit is contained in:
@@ -386,7 +386,7 @@ describe('context', function() {
|
||||
context.get("foo","test",cb);
|
||||
context.keys("test",cb);
|
||||
stubSet.calledWithExactly("1:flow","foo","bar",cb).should.be.true();
|
||||
stubGet.calledWithExactly("1:flow","foo",cb).should.be.true();
|
||||
stubGet.calledWith("1:flow","foo").should.be.true();
|
||||
stubKeys.calledWithExactly("1:flow",cb).should.be.true();
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -400,7 +400,7 @@ describe('context', function() {
|
||||
context.flow.get("foo","test",cb);
|
||||
context.flow.keys("test",cb);
|
||||
stubSet.calledWithExactly("flow","foo","bar",cb).should.be.true();
|
||||
stubGet.calledWithExactly("flow","foo",cb).should.be.true();
|
||||
stubGet.calledWith("flow","foo").should.be.true();
|
||||
stubKeys.calledWithExactly("flow",cb).should.be.true();
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -431,7 +431,7 @@ describe('context', function() {
|
||||
stubSet.called.should.be.false();
|
||||
stubKeys.called.should.be.false();
|
||||
stubSet2.calledWithExactly("1:flow","foo","bar",cb).should.be.true();
|
||||
stubGet2.calledWithExactly("1:flow","foo",cb).should.be.true();
|
||||
stubGet2.calledWith("1:flow","foo").should.be.true();
|
||||
stubKeys2.calledWithExactly("1:flow",cb).should.be.true();
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -448,7 +448,7 @@ describe('context', function() {
|
||||
stubSet.called.should.be.false();
|
||||
stubKeys.called.should.be.false();
|
||||
stubSet2.calledWithExactly("1:flow","foo","bar",cb).should.be.true();
|
||||
stubGet2.calledWithExactly("1:flow","foo",cb).should.be.true();
|
||||
stubGet2.calledWith("1:flow","foo").should.be.true();
|
||||
stubKeys2.calledWithExactly("1:flow",cb).should.be.true();
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -465,7 +465,7 @@ describe('context', function() {
|
||||
stubSet.called.should.be.false();
|
||||
stubKeys.called.should.be.false();
|
||||
stubSet2.calledWithExactly("1:flow","foo","alias",cb).should.be.true();
|
||||
stubGet2.calledWithExactly("1:flow","foo",cb).should.be.true();
|
||||
stubGet2.calledWith("1:flow","foo").should.be.true();
|
||||
stubKeys2.calledWithExactly("1:flow",cb).should.be.true();
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -479,7 +479,7 @@ describe('context', function() {
|
||||
context.get("foo",cb);
|
||||
context.keys(cb);
|
||||
stubSet.calledWithExactly("1:flow","foo","alias",cb).should.be.true();
|
||||
stubGet.calledWithExactly("1:flow","foo",cb).should.be.true();
|
||||
stubGet.calledWith("1:flow","foo").should.be.true();
|
||||
stubKeys.calledWithExactly("1:flow",cb).should.be.true();
|
||||
done();
|
||||
}).catch(done);
|
||||
@@ -595,9 +595,7 @@ describe('context', function() {
|
||||
|
||||
it('should return an error if an error occurs in getting multiple store values', function(done) {
|
||||
Context.init({contextStorage:contextStorage});
|
||||
stubGet.onFirstCall().callsArgWith(2, null, "bar1");
|
||||
stubGet.onSecondCall().callsArgWith(2, "error2");
|
||||
stubGet.onThirdCall().callsArgWith(2, null, "bar3");
|
||||
stubGet.onFirstCall().callsArgWith(2, "error2", "bar1");
|
||||
Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
context.global.get(["foo1","foo2","foo3"], "memory", function(err,foo1,foo2,foo3){
|
||||
@@ -771,9 +769,7 @@ describe('context', function() {
|
||||
|
||||
it('should return an error if an error occurs in storing multiple values', function(done) {
|
||||
Context.init({contextStorage:contextStorage});
|
||||
stubSet.onFirstCall().callsArgWith(3, null);
|
||||
stubSet.onSecondCall().callsArgWith(3, "error2");
|
||||
stubSet.onThirdCall().callsArgWith(3, null);
|
||||
stubSet.onFirstCall().callsArgWith(3, "error2");
|
||||
Context.load().then(function(){
|
||||
var context = Context.get("1","flow");
|
||||
context.set(["foo1","foo2","foo3"], ["bar1","bar2","bar3"], "memory", function(err){
|
||||
|
@@ -106,7 +106,7 @@ describe('localfilesystem',function() {
|
||||
context.set("nodeX","foo","testX",function(err){
|
||||
context.set("nodeY","foo","testY",function(err){
|
||||
context.get("nodeX","foo",function(err, value){
|
||||
value.should.be.equal("testX"),
|
||||
value.should.be.equal("testX");
|
||||
context.get("nodeY","foo",function(err, value){
|
||||
value.should.be.equal("testY");
|
||||
done();
|
||||
@@ -250,6 +250,51 @@ describe('localfilesystem',function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should set/get multiple values', function(done) {
|
||||
context.set("nodeX",["one","two","three"],["test1","test2","test3"], function(err) {
|
||||
context.get("nodeX",["one","two"], function() {
|
||||
Array.prototype.slice.apply(arguments).should.eql([undefined,"test1","test2"])
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
it('should set/get multiple values - get unknown', function(done) {
|
||||
context.set("nodeX",["one","two","three"],["test1","test2","test3"], function(err) {
|
||||
context.get("nodeX",["one","two","unknown"], function() {
|
||||
Array.prototype.slice.apply(arguments).should.eql([undefined,"test1","test2",undefined])
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
it('should set/get multiple values - single value providd', function(done) {
|
||||
context.set("nodeX",["one","two","three"],"test1", function(err) {
|
||||
context.get("nodeX",["one","two"], function() {
|
||||
Array.prototype.slice.apply(arguments).should.eql([undefined,"test1",null])
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
it('should throw error if bad key included in multiple keys - get', function(done) {
|
||||
context.set("nodeX",["one","two","three"],["test1","test2","test3"], function(err) {
|
||||
context.get("nodeX",["one",".foo","three"], function(err) {
|
||||
should.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
it('should throw error if bad key included in multiple keys - set', function(done) {
|
||||
context.set("nodeX",["one",".foo","three"],["test1","test2","test3"], function(err) {
|
||||
should.exist(err);
|
||||
// Check 'one' didn't get set as a result
|
||||
context.get("nodeX","one",function(err,one) {
|
||||
should.not.exist(one);
|
||||
done();
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
it('should throw an error when getting a value with invalid key', function (done) {
|
||||
context.set("nodeX","foo","bar",function(err) {
|
||||
context.get("nodeX"," ",function(err,value) {
|
||||
@@ -272,7 +317,7 @@ describe('localfilesystem',function() {
|
||||
done("should throw an error.");
|
||||
} catch (err) {
|
||||
done();
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error when callback of get() is not specified',function (done) {
|
||||
@@ -281,7 +326,7 @@ describe('localfilesystem',function() {
|
||||
done("should throw an error.");
|
||||
} catch (err) {
|
||||
done();
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error when callback of set() is not a function',function (done) {
|
||||
@@ -290,7 +335,7 @@ describe('localfilesystem',function() {
|
||||
done("should throw an error.");
|
||||
} catch (err) {
|
||||
done();
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
it('should not throw an error when callback of set() is not specified', function (done) {
|
||||
@@ -299,7 +344,7 @@ describe('localfilesystem',function() {
|
||||
done();
|
||||
} catch (err) {
|
||||
done("should not throw an error.");
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle empty context file', function (done) {
|
||||
@@ -377,7 +422,7 @@ describe('localfilesystem',function() {
|
||||
done("should throw an error.");
|
||||
} catch (err) {
|
||||
done();
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error when callback of keys() is not specified', function (done) {
|
||||
@@ -386,7 +431,7 @@ describe('localfilesystem',function() {
|
||||
done("should throw an error.");
|
||||
} catch (err) {
|
||||
done();
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -66,7 +66,7 @@ describe('memory',function() {
|
||||
context.get("nodeY","foo").should.equal("testY");
|
||||
});
|
||||
|
||||
it('should thorw the error if the error occurs', function() {
|
||||
it('should throw the error if the error occurs', function() {
|
||||
try{
|
||||
context.set("nodeX",".foo","test");
|
||||
should.fail("Error was not thrown");
|
||||
@@ -80,6 +80,40 @@ describe('memory',function() {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should get multiple values - all known', function() {
|
||||
context.set("nodeX","one","test1");
|
||||
context.set("nodeX","two","test2");
|
||||
context.set("nodeX","three","test3");
|
||||
context.set("nodeX","four","test4");
|
||||
|
||||
var values = context.get("nodeX",["one","two","four"]);
|
||||
values.should.eql(["test1","test2","test4"])
|
||||
})
|
||||
it('should get multiple values - include unknown', function() {
|
||||
context.set("nodeX","one","test1");
|
||||
context.set("nodeX","two","test2");
|
||||
context.set("nodeX","three","test3");
|
||||
context.set("nodeX","four","test4");
|
||||
|
||||
var values = context.get("nodeX",["one","unknown"]);
|
||||
values.should.eql(["test1",undefined])
|
||||
})
|
||||
it('should throw error if bad key included in multiple keys', function() {
|
||||
context.set("nodeX","one","test1");
|
||||
context.set("nodeX","two","test2");
|
||||
context.set("nodeX","three","test3");
|
||||
context.set("nodeX","four","test4");
|
||||
|
||||
try{
|
||||
var values = context.get("nodeX",["one",".foo","three"]);
|
||||
should.fail("Error was not thrown");
|
||||
}catch(err){
|
||||
should.exist(err);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('async',function() {
|
||||
@@ -104,6 +138,40 @@ describe('memory',function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get multiple values - all known', function(done) {
|
||||
context.set("nodeX","one","test1");
|
||||
context.set("nodeX","two","test2");
|
||||
context.set("nodeX","three","test3");
|
||||
context.set("nodeX","four","test4");
|
||||
|
||||
context.get("nodeX",["one","two","four"],function() {
|
||||
Array.prototype.slice.apply(arguments).should.eql([undefined,"test1","test2","test4"])
|
||||
done();
|
||||
});
|
||||
})
|
||||
it('should get multiple values - include unknown', function(done) {
|
||||
context.set("nodeX","one","test1");
|
||||
context.set("nodeX","two","test2");
|
||||
context.set("nodeX","three","test3");
|
||||
context.set("nodeX","four","test4");
|
||||
|
||||
context.get("nodeX",["one","unknown"],function() {
|
||||
Array.prototype.slice.apply(arguments).should.eql([undefined,"test1",undefined])
|
||||
done();
|
||||
});
|
||||
})
|
||||
it('should throw error if bad key included in multiple keys', function(done) {
|
||||
context.set("nodeX","one","test1");
|
||||
context.set("nodeX","two","test2");
|
||||
context.set("nodeX","three","test3");
|
||||
context.set("nodeX","four","test4");
|
||||
|
||||
context.get("nodeX",["one",".foo","three"], function(err) {
|
||||
should.exist(err);
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user