mirror of
				https://github.com/node-red/node-red.git
				synced 2025-03-01 10:36:34 +00:00 
			
		
		
		
	Allow arrays of different lengths to be passed to set.
				
					
				
			This commit is contained in:
		@@ -639,6 +639,125 @@ describe('context', function() {
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            it('should deletes multiple properties', function(done) {
 | 
			
		||||
                Context.init({contextStorage:memoryStorage});
 | 
			
		||||
                Context.load().then(function(){
 | 
			
		||||
                    var context =  Context.get("1","flow");
 | 
			
		||||
                    context.set(["foo1","foo2","foo3"], ["bar1","bar2","bar3"], "memory", function(err){
 | 
			
		||||
                        if (err) {
 | 
			
		||||
                            done(err);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            context.get(["foo1","foo2","foo3"], "memory", function(err,foo1,foo2,foo3){
 | 
			
		||||
                                if (err) {
 | 
			
		||||
                                    done(err);
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    foo1.should.be.equal("bar1");
 | 
			
		||||
                                    foo2.should.be.equal("bar2");
 | 
			
		||||
                                    foo3.should.be.equal("bar3");
 | 
			
		||||
                                    context.set(["foo1","foo2","foo3"], new Array(3), "memory", function(err){
 | 
			
		||||
                                        if (err) {
 | 
			
		||||
                                            done(err);
 | 
			
		||||
                                        } else {
 | 
			
		||||
                                            context.get(["foo1","foo2","foo3"], "memory", function(err,foo1,foo2,foo3){
 | 
			
		||||
                                                if (err) {
 | 
			
		||||
                                                    done(err);
 | 
			
		||||
                                                } else {
 | 
			
		||||
                                                    should.not.exist(foo1);
 | 
			
		||||
                                                    should.not.exist(foo2);
 | 
			
		||||
                                                    should.not.exist(foo3);
 | 
			
		||||
                                                    done();
 | 
			
		||||
                                                }
 | 
			
		||||
                                            });
 | 
			
		||||
                                        }
 | 
			
		||||
                                    });
 | 
			
		||||
                                }
 | 
			
		||||
                            });
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            it('should use null for missing values if the value array is shorter than the key array', function(done) {
 | 
			
		||||
                Context.init({contextStorage:memoryStorage});
 | 
			
		||||
                Context.load().then(function(){
 | 
			
		||||
                    var context =  Context.get("1","flow");
 | 
			
		||||
                    context.set(["foo1","foo2","foo3"], ["bar1","bar2"], "memory", function(err){
 | 
			
		||||
                        if (err) {
 | 
			
		||||
                            done(err);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            context.keys(function(err, keys){
 | 
			
		||||
                                keys.should.have.length(3);
 | 
			
		||||
                                keys.should.eql(["foo1","foo2","foo3"]);
 | 
			
		||||
                                context.get(["foo1","foo2","foo3"], "memory", function(err,foo1,foo2,foo3){
 | 
			
		||||
                                    if (err) {
 | 
			
		||||
                                        done(err);
 | 
			
		||||
                                    } else {
 | 
			
		||||
                                        foo1.should.be.equal("bar1");
 | 
			
		||||
                                        foo2.should.be.equal("bar2");
 | 
			
		||||
                                        should(foo3).be.null();
 | 
			
		||||
                                        done();
 | 
			
		||||
                                    }
 | 
			
		||||
                                });
 | 
			
		||||
                            });
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            it('should use null for missing values if the value is not array', function(done) {
 | 
			
		||||
                Context.init({contextStorage:memoryStorage});
 | 
			
		||||
                Context.load().then(function(){
 | 
			
		||||
                    var context =  Context.get("1","flow");
 | 
			
		||||
                    context.set(["foo1","foo2","foo3"], "bar1", "memory", function(err){
 | 
			
		||||
                        if (err) {
 | 
			
		||||
                            done(err);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            context.keys(function(err, keys){
 | 
			
		||||
                                keys.should.have.length(3);
 | 
			
		||||
                                keys.should.eql(["foo1","foo2","foo3"]);
 | 
			
		||||
                                context.get(["foo1","foo2","foo3"], "memory", function(err,foo1,foo2,foo3){
 | 
			
		||||
                                    if (err) {
 | 
			
		||||
                                        done(err);
 | 
			
		||||
                                    } else {
 | 
			
		||||
                                        foo1.should.be.equal("bar1");
 | 
			
		||||
                                        should(foo2).be.null();
 | 
			
		||||
                                        should(foo3).be.null();
 | 
			
		||||
                                        done();
 | 
			
		||||
                                    }
 | 
			
		||||
                                });
 | 
			
		||||
                            });
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            it('should ignore the extra values if the value array is longer than the key array', function(done) {
 | 
			
		||||
                Context.init({contextStorage:memoryStorage});
 | 
			
		||||
                Context.load().then(function(){
 | 
			
		||||
                    var context =  Context.get("1","flow");
 | 
			
		||||
                    context.set(["foo1","foo2","foo3"], ["bar1","bar2","bar3","ignored"], "memory", function(err){
 | 
			
		||||
                        if (err) {
 | 
			
		||||
                            done(err);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            context.keys(function(err, keys){
 | 
			
		||||
                                keys.should.have.length(3);
 | 
			
		||||
                                keys.should.eql(["foo1","foo2","foo3"]);
 | 
			
		||||
                                context.get(["foo1","foo2","foo3"], "memory", function(err,foo1,foo2,foo3){
 | 
			
		||||
                                    if (err) {
 | 
			
		||||
                                        done(err);
 | 
			
		||||
                                    } else {
 | 
			
		||||
                                        foo1.should.be.equal("bar1");
 | 
			
		||||
                                        foo2.should.be.equal("bar2");
 | 
			
		||||
                                        foo3.should.be.equal("bar3");
 | 
			
		||||
                                        done();
 | 
			
		||||
                                    }
 | 
			
		||||
                                });
 | 
			
		||||
                            });
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            it('should return an error if an error occurs in storing multiple values', function(done) {
 | 
			
		||||
                Context.init({contextStorage:contextStorage});
 | 
			
		||||
                stubSet.onFirstCall().callsArgWith(3, null);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user