mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #303 from hbeeken/test-registerType-with-credentials
Adding test for index.registerType with credentials defined
This commit is contained in:
commit
b1f14031a9
@ -195,5 +195,14 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
save: function () {
|
save: function () {
|
||||||
return storage.saveCredentials(credentialCache);
|
return storage.saveCredentials(credentialCache);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the credential definition for the given node type
|
||||||
|
* @param type the node type
|
||||||
|
* @return the credential definition
|
||||||
|
*/
|
||||||
|
getDefinition: function (type) {
|
||||||
|
return credentialsDef[type];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,15 +13,16 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
var should = require("should");
|
|
||||||
var should = require("should");
|
var should = require("should");
|
||||||
var fs = require('fs-extra');
|
var fs = require('fs-extra');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var when = require("when");
|
var when = require("when");
|
||||||
var defer = when.defer();
|
var defer = when.defer();
|
||||||
var RedNode = require("../../../red/nodes/Node");
|
|
||||||
var index = require("../../../red/nodes/index");
|
var index = require("../../../red/nodes/index");
|
||||||
var server = require("../../../red/server");
|
|
||||||
|
describe("red/nodes/index", function() {
|
||||||
|
|
||||||
var testFlows = [{"type":"test","id":"tab1","label":"Sheet 1"}];
|
var testFlows = [{"type":"test","id":"tab1","label":"Sheet 1"}];
|
||||||
var storage = {
|
var storage = {
|
||||||
@ -46,23 +47,16 @@ var storage = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("red/nodes/index", function() {
|
|
||||||
|
|
||||||
it('nodes are initialised with credentials',function(done) {
|
|
||||||
|
|
||||||
function TestNode(n) {
|
function TestNode(n) {
|
||||||
index.createNode(this, n);
|
index.createNode(this, n);
|
||||||
|
|
||||||
this.id = 'tab1';
|
|
||||||
this.type = 'test';
|
|
||||||
this.name = 'barney';
|
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
this.on("log", function() {
|
this.on("log", function() {
|
||||||
// do nothing
|
// do nothing
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it('nodes are initialised with credentials',function(done) {
|
||||||
|
|
||||||
index.init({}, storage);
|
index.init({}, storage);
|
||||||
index.registerType('test', TestNode);
|
index.registerType('test', TestNode);
|
||||||
index.loadFlows().then(function() {
|
index.loadFlows().then(function() {
|
||||||
@ -110,4 +104,57 @@ describe("red/nodes/index", function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("registerType should register credentials definition", function() {
|
||||||
|
var http = require('http');
|
||||||
|
var express = require('express');
|
||||||
|
var sinon = require('sinon');
|
||||||
|
var app = express();
|
||||||
|
var server = require("../../../red/server");
|
||||||
|
var credentials = require("../../../red/nodes/credentials");
|
||||||
|
var localfilesystem = require("../../../red/storage/localfilesystem");
|
||||||
|
var RED = require("../../../red/red.js");
|
||||||
|
|
||||||
|
var userDir = path.join(__dirname,".testUserHome");
|
||||||
|
before(function(done) {
|
||||||
|
fs.remove(userDir,function(err) {
|
||||||
|
fs.mkdir(userDir,function() {
|
||||||
|
sinon.stub(index, 'load', function() {
|
||||||
|
return when.promise(function(resolve,reject){
|
||||||
|
resolve([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
sinon.stub(localfilesystem, 'getCredentials', function() {
|
||||||
|
return when.promise(function(resolve,reject) {
|
||||||
|
resolve({"tab1":{"b":1,"c":2}});
|
||||||
|
});
|
||||||
|
}) ;
|
||||||
|
RED.init(http.createServer(function(req,res){app(req,res)}),
|
||||||
|
{userDir: userDir});
|
||||||
|
server.start().then(function () {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
fs.remove(userDir,done);
|
||||||
|
server.stop();
|
||||||
|
index.load.restore();
|
||||||
|
localfilesystem.getCredentials.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it(': definition defined',function(done) {
|
||||||
|
index.registerType('test', TestNode, {
|
||||||
|
credentials: {
|
||||||
|
foo: {type:"test"}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
|
||||||
|
credentials.getDefinition("test").should.have.property('foo');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user