Skip to content

Commit

Permalink
Merge pull request #295 from hbeeken/test-node-index
Browse files Browse the repository at this point in the history
Adding unit test for nodes/index.js
  • Loading branch information
knolleary committed Jul 24, 2014
2 parents 166a798 + 2e86a41 commit b50b233
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions test/red/nodes/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,103 @@
* limitations under the License.
**/
var should = require("should");
var should = require("should");
var fs = require('fs-extra');
var path = require('path');
var when = require("when");
var defer = when.defer();
var RedNode = require("../../../red/nodes/Node");
var index = require("../../../red/nodes/index");
var server = require("../../../red/server");

var testFlows = [{"type":"test","id":"tab1","label":"Sheet 1"}];
var storage = {
getFlows: function() {
var defer = when.defer();
defer.resolve(testFlows);
return defer.promise;
},
getCredentials: function() {
return when.promise(function(resolve,reject) {
resolve({"tab1":{"b":1,"c":2}});
});
},
saveFlows: function(conf) {
var defer = when.defer();
defer.resolve();
should.deepEqual(testFlows, conf);
return defer.promise;
},
saveCredentials: function(creds) {
return when(true);
}
};

describe("red/nodes/index", function() {
it('can be required without errors', function() {
require("../../../red/nodes/index");
});

it('nodes are initialised with credentials',function(done) {

function TestNode(n) {
index.createNode(this, n);

this.id = 'tab1';
this.type = 'test';
this.name = 'barney';
var node = this;

this.on("log", function() {
// do nothing
});
}

index.init({}, storage);
index.registerType('test', TestNode);
index.loadFlows().then(function() {
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
testnode.credentials.should.have.property('b',1);
testnode.credentials.should.have.property('c',2);
done();
}).otherwise(function(err) {
done(err);
});

});

it('flows should be initialised',function(done) {
var testFlows = [{"type":"test","id":"tab1","label":"Sheet 1"}];
var storage = {
getFlows: function() {
var defer = when.defer();
defer.resolve(testFlows);
return defer.promise;
},
getCredentials: function() {
return when.promise(function(resolve,reject) {
resolve({"tab1":{"b":1,"c":2}});
});
},
saveFlows: function(conf) {
var defer = when.defer();
defer.resolve();
should.deepEqual(testFlows, conf);
return defer.promise;
},
saveCredentials: function(creds) {
return when(true);
}
};

index.init({}, storage);
index.loadFlows().then(function() {
should.deepEqual(testFlows, index.getFlows());
done();
}).otherwise(function(err) {
done(err);
});

});

});

0 comments on commit b50b233

Please sign in to comment.