mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Added logic to chek for changes in org variable in msg object
This commit is contained in:
25
test/unit/fixtures/data/orgEvent.js
Normal file
25
test/unit/fixtures/data/orgEvent.js
Normal file
@@ -0,0 +1,25 @@
|
||||
module.exports = (org) => ({
|
||||
logger: {
|
||||
metadata: {
|
||||
organization: org
|
||||
}
|
||||
},
|
||||
payload: {
|
||||
system: {
|
||||
organization: org,
|
||||
region: 'eu-test-1',
|
||||
conversationId: 'convo-id',
|
||||
bot: 'my-bot'
|
||||
},
|
||||
},
|
||||
event: {
|
||||
event: {
|
||||
organization: org,
|
||||
token: {
|
||||
contents: {
|
||||
organization: org
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
74
test/unit/test-stopTheBleed.js
Normal file
74
test/unit/test-stopTheBleed.js
Normal file
@@ -0,0 +1,74 @@
|
||||
const StopTheBleed = require('../../nodes/StopTheBleed')
|
||||
const orgEvent = require('./fixtures/data/orgEvent')
|
||||
const sinon = require('sinon');
|
||||
const assert = require('assert');
|
||||
|
||||
describe.only('Unit: StopTheBleed', () => {
|
||||
it('Should not log when no changes', () => {
|
||||
const beforeEvent = orgEvent('before');
|
||||
const stopTheBleed = new StopTheBleed(beforeEvent);
|
||||
stopTheBleed.verify(beforeEvent);
|
||||
});
|
||||
|
||||
it('Should warn when org is overwritten', () => {
|
||||
const beforeEvent = orgEvent('before');
|
||||
errorLogStub = sinon.stub();
|
||||
appLogStub = sinon.stub();
|
||||
beforeEvent.logger.error = errorLogStub;
|
||||
beforeEvent.logger.app = {
|
||||
platform:{
|
||||
organization: appLogStub
|
||||
}
|
||||
};
|
||||
|
||||
const stopTheBleed = new StopTheBleed(beforeEvent);
|
||||
|
||||
const modifiedEvent = orgEvent('after');
|
||||
|
||||
stopTheBleed.verify(modifiedEvent);
|
||||
assert(errorLogStub.callCount === 4)
|
||||
assert(appLogStub.callCount === 4)
|
||||
const [[log1], [log2], [log3], [log4]] = appLogStub.args
|
||||
assert(log1.details.message.includes('logger.metadata.organization'))
|
||||
assert(log2.details.message.includes('payload.system.organization'))
|
||||
assert(log3.details.message.includes('event.event.organization'))
|
||||
assert(log4.details.message.includes('event.event.token.contents.organization'))
|
||||
});
|
||||
|
||||
|
||||
it('Should warn when org is deleted', () => {
|
||||
const beforeEvent = orgEvent('before');
|
||||
errorLogStub = sinon.stub();
|
||||
appLogStub = sinon.stub();
|
||||
beforeEvent.logger.error = errorLogStub;
|
||||
beforeEvent.logger.app = {
|
||||
platform:{
|
||||
organization: appLogStub
|
||||
}
|
||||
};
|
||||
|
||||
const stopTheBleed = new StopTheBleed(beforeEvent);
|
||||
|
||||
delete beforeEvent.logger.metadata.organization;
|
||||
delete beforeEvent.payload.system.organization;
|
||||
delete beforeEvent.event.event.organization;
|
||||
delete beforeEvent.event.event.token.contents.organization;
|
||||
stopTheBleed.verify(beforeEvent);
|
||||
assert(errorLogStub.callCount === 4)
|
||||
assert(appLogStub.callCount === 4)
|
||||
const [[log1], [log2], [log3], [log4]] = appLogStub.args
|
||||
assert(log1.details.message.includes('logger.metadata.organization'))
|
||||
assert(log2.details.message.includes('payload.system.organization'))
|
||||
assert(log3.details.message.includes('event.event.organization'))
|
||||
assert(log4.details.message.includes('event.event.token.contents.organization'))
|
||||
});
|
||||
|
||||
it('Should not die when error', () => {
|
||||
const beforeEvent = orgEvent('before');
|
||||
const stopTheBleed = new StopTheBleed(beforeEvent);
|
||||
|
||||
const modifiedEvent = orgEvent('after');
|
||||
|
||||
stopTheBleed.verify(modifiedEvent);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user