1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #419 from hindessm/add-credentials-to-test-helper

Add credentials support to node test helper.
This commit is contained in:
Nick O'Leary 2014-10-01 11:13:28 +01:00
commit 322a6ebed3

View File

@ -20,6 +20,7 @@ var request = require('supertest');
var RED = require("../../red/red.js"); var RED = require("../../red/red.js");
var redNodes = require("../../red/nodes"); var redNodes = require("../../red/nodes");
var flows = require("../../red/nodes/flows"); var flows = require("../../red/nodes/flows");
var credentials = require("../../red/nodes/credentials");
var comms = require("../../red/comms.js"); var comms = require("../../red/comms.js");
var http = require('http'); var http = require('http');
@ -38,7 +39,12 @@ function helperNode(n) {
} }
module.exports = { module.exports = {
load: function(testNode, testFlows, cb) { load: function(testNode, testFlows, testCredentials, cb) {
if (typeof testCredentials === 'function') {
cb = testCredentials;
testCredentials = {};
}
var storage = { var storage = {
getFlows: function() { getFlows: function() {
var defer = when.defer(); var defer = when.defer();
@ -47,15 +53,19 @@ module.exports = {
}, },
getCredentials: function() { getCredentials: function() {
var defer = when.defer(); var defer = when.defer();
defer.resolve({}); defer.resolve(testCredentials);
return defer.promise; return defer.promise;
}, },
saveCredentials: function() {
// do nothing
},
}; };
var settings = { var settings = {
available: function() { return false; } available: function() { return false; }
} }
redNodes.init(settings, storage); redNodes.init(settings, storage);
credentials.init(storage);
RED.nodes.registerType("helper", helperNode); RED.nodes.registerType("helper", helperNode);
testNode(RED); testNode(RED);
flows.load().then(function() { flows.load().then(function() {
@ -73,6 +83,8 @@ module.exports = {
return flows.get(id); return flows.get(id);
}, },
credentials: credentials,
clearFlows: function() { clearFlows: function() {
return flows.clear(); return flows.clear();
}, },