mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
revert/redo tests for api/index, log and Node_spec
This commit is contained in:
parent
ff093d98c6
commit
10277aa956
@ -27,7 +27,7 @@ describe("api index", function() {
|
|||||||
|
|
||||||
describe("disables editor", function() {
|
describe("disables editor", function() {
|
||||||
before(function() {
|
before(function() {
|
||||||
settings.init({disableEditor:true,adminAuth:{type: "credentials",users:[],default:{permissions:"read"}}});
|
settings.init({disableEditor:true});
|
||||||
app = express();
|
app = express();
|
||||||
api.init(app);
|
api.init(app);
|
||||||
});
|
});
|
||||||
@ -50,6 +50,34 @@ describe("api index", function() {
|
|||||||
.get("/settings")
|
.get("/settings")
|
||||||
.expect(200,done)
|
.expect(200,done)
|
||||||
});
|
});
|
||||||
|
it('does not serve auth', function(done) {
|
||||||
|
request(app)
|
||||||
|
.get("/auth/login")
|
||||||
|
.expect(404,done)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("can serve auth", function() {
|
||||||
|
before(function() {
|
||||||
|
//settings.init({disableEditor:true});
|
||||||
|
settings.init({adminAuth:{type: "credentials",users:[],default:{permissions:"read"}}});
|
||||||
|
app = express();
|
||||||
|
api.init(app);
|
||||||
|
});
|
||||||
|
after(function() {
|
||||||
|
settings.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('it now serves auth', function(done) {
|
||||||
|
request(app)
|
||||||
|
.get("/auth/login")
|
||||||
|
.expect(200)
|
||||||
|
.end(function(err,res) {
|
||||||
|
if (err) { return done(err); }
|
||||||
|
res.body.type.should.equal("credentials");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("enables editor", function() {
|
describe("enables editor", function() {
|
||||||
|
@ -49,10 +49,14 @@ describe("red/log", function() {
|
|||||||
sinon.assert.calledWithMatch(util.log,"");
|
sinon.assert.calledWithMatch(util.log,"");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('it checks level of metrics', function() {
|
it('it checks metrics are enabled', function() {
|
||||||
log.metric().should.equal(true);
|
log.metric().should.equal(true);
|
||||||
var sett = {logging: { console: { level: 'info', metrics: false } } };
|
var sett = {logging: { console: { level: 'info', metrics: false } } };
|
||||||
log.init(sett);
|
log.init(sett);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('it checks metrics are disabled', function() {
|
||||||
|
log.metric().should.equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -72,7 +72,7 @@ describe('Node', function() {
|
|||||||
testdone();
|
testdone();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows multiple close handlers to be registered',function(testdone) {
|
it('allows multiple close handlers to be registered',function(testdone) {
|
||||||
var n = new RedNode({id:'123',type:'abc'});
|
var n = new RedNode({id:'123',type:'abc'});
|
||||||
var callbacksClosed = 0;
|
var callbacksClosed = 0;
|
||||||
@ -113,7 +113,7 @@ describe('Node', function() {
|
|||||||
});
|
});
|
||||||
n.receive(message);
|
n.receive(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('writes metric info with undefined msg', function(done){
|
it('writes metric info with undefined msg', function(done){
|
||||||
var n = new RedNode({id:'123',type:'abc'});
|
var n = new RedNode({id:'123',type:'abc'});
|
||||||
n.on('input',function(msg) {
|
n.on('input',function(msg) {
|
||||||
@ -123,7 +123,7 @@ describe('Node', function() {
|
|||||||
});
|
});
|
||||||
n.receive();
|
n.receive();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('writes metric info with null msg', function(done){
|
it('writes metric info with null msg', function(done){
|
||||||
var n = new RedNode({id:'123',type:'abc'});
|
var n = new RedNode({id:'123',type:'abc'});
|
||||||
n.on('input',function(msg) {
|
n.on('input',function(msg) {
|
||||||
@ -170,7 +170,7 @@ describe('Node', function() {
|
|||||||
|
|
||||||
var rcvdCount = 0;
|
var rcvdCount = 0;
|
||||||
|
|
||||||
n2.on('input',function(msg) {
|
n2.on('input',function(msg) {
|
||||||
if (rcvdCount === 0) {
|
if (rcvdCount === 0) {
|
||||||
// first msg sent, don't clone
|
// first msg sent, don't clone
|
||||||
should.deepEqual(msg,messages[rcvdCount]);
|
should.deepEqual(msg,messages[rcvdCount]);
|
||||||
@ -205,7 +205,7 @@ describe('Node', function() {
|
|||||||
|
|
||||||
var rcvdCount = 0;
|
var rcvdCount = 0;
|
||||||
|
|
||||||
// first message sent, don't clone
|
// first message sent, don't clone
|
||||||
// message uuids should match
|
// message uuids should match
|
||||||
n2.on('input',function(msg) {
|
n2.on('input',function(msg) {
|
||||||
should.deepEqual(msg,messages[0]);
|
should.deepEqual(msg,messages[0]);
|
||||||
@ -273,7 +273,7 @@ describe('Node', function() {
|
|||||||
var flowGet = sinon.stub(flows,"get",function(id) {
|
var flowGet = sinon.stub(flows,"get",function(id) {
|
||||||
return {'n1':n1,'n2':n2}[id];
|
return {'n1':n1,'n2':n2}[id];
|
||||||
});
|
});
|
||||||
|
|
||||||
var messages = [
|
var messages = [
|
||||||
{payload:"hello world"},
|
{payload:"hello world"},
|
||||||
{payload:"hello world again"}
|
{payload:"hello world again"}
|
||||||
@ -304,7 +304,7 @@ describe('Node', function() {
|
|||||||
var message = {payload: "foo", cloned: cloned, req: req, res: res};
|
var message = {payload: "foo", cloned: cloned, req: req, res: res};
|
||||||
|
|
||||||
var rcvdCount = 0;
|
var rcvdCount = 0;
|
||||||
|
|
||||||
// first message to be sent, so should not be cloned
|
// first message to be sent, so should not be cloned
|
||||||
n2.on('input',function(msg) {
|
n2.on('input',function(msg) {
|
||||||
should.deepEqual(msg, message);
|
should.deepEqual(msg, message);
|
||||||
@ -404,7 +404,7 @@ describe('Node', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#error', function() {
|
describe('#error', function() {
|
||||||
it('produces an error message', function(done) {
|
it('handles a null error message', function(done) {
|
||||||
var n = new RedNode({id:'123',type:'abc'});
|
var n = new RedNode({id:'123',type:'abc'});
|
||||||
var loginfo = {};
|
var loginfo = {};
|
||||||
sinon.stub(Log, 'log', function(msg) {
|
sinon.stub(Log, 'log', function(msg) {
|
||||||
@ -412,7 +412,7 @@ describe('Node', function() {
|
|||||||
});
|
});
|
||||||
sinon.stub(flows,"handleError", function(node,message,msg) {
|
sinon.stub(flows,"handleError", function(node,message,msg) {
|
||||||
});
|
});
|
||||||
|
|
||||||
var message = {a:1};
|
var message = {a:1};
|
||||||
|
|
||||||
n.error(null,message);
|
n.error(null,message);
|
||||||
@ -422,11 +422,36 @@ describe('Node', function() {
|
|||||||
flows.handleError.args[0][0].should.eql(n);
|
flows.handleError.args[0][0].should.eql(n);
|
||||||
flows.handleError.args[0][1].should.eql("");
|
flows.handleError.args[0][1].should.eql("");
|
||||||
flows.handleError.args[0][2].should.eql(message);
|
flows.handleError.args[0][2].should.eql(message);
|
||||||
|
|
||||||
Log.log.restore();
|
Log.log.restore();
|
||||||
flows.handleError.restore();
|
flows.handleError.restore();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('produces an error message', function(done) {
|
||||||
|
var n = new RedNode({id:'123',type:'abc'});
|
||||||
|
var loginfo = {};
|
||||||
|
sinon.stub(Log, 'log', function(msg) {
|
||||||
|
loginfo = msg;
|
||||||
|
});
|
||||||
|
sinon.stub(flows,"handleError", function(node,message,msg) {
|
||||||
|
});
|
||||||
|
|
||||||
|
var message = {a:2};
|
||||||
|
|
||||||
|
n.error("This is an error",message);
|
||||||
|
should.deepEqual({level:Log.ERROR, id:n.id, type:n.type, msg:"This is an error"}, loginfo);
|
||||||
|
|
||||||
|
flows.handleError.called.should.be.true;
|
||||||
|
flows.handleError.args[0][0].should.eql(n);
|
||||||
|
flows.handleError.args[0][1].should.eql("This is an error");
|
||||||
|
flows.handleError.args[0][2].should.eql(message);
|
||||||
|
|
||||||
|
Log.log.restore();
|
||||||
|
flows.handleError.restore();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#metric', function() {
|
describe('#metric', function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user