Skip to content

Commit 01fdc74

Browse files
Archish27francisf
authored andcommitted
🐛 fix for alert manager send alert function
1 parent 418eab6 commit 01fdc74

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

lib/util/AlertManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class AlertManager {
88
* Creates the AlertManager.
99
*/
1010
constructor() {
11-
this.sendAlerts = this.sendAlerts.bind(this);
11+
this.sendAlert = this.sendAlert.bind(this);
1212
}
1313

1414
/**
@@ -19,7 +19,7 @@ class AlertManager {
1919
* @param {String} subject
2020
* @param {String} message
2121
*/
22-
sendAlerts(subject, message) {
22+
sendAlert(subject, message) {
2323
logger.info(`Alert with subject: ${subject} message: ${message}`);
2424
}
2525
}

test/util/alertmanager.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { describe, it, beforeEach } = require('mocha');
2+
const sinon = require('sinon');
3+
const { expect } = require('chai');
4+
const logger = require('../../lib/util/loggerFactory');
5+
const AlertManager = require('../../lib/util/AlertManager');
6+
7+
describe('#AlertManager', () => {
8+
let alertManager;
9+
beforeEach(() => {
10+
alertManager = new AlertManager();
11+
});
12+
13+
describe('#sendAlert', () => {
14+
it('should log & send alert', () => {
15+
const loggerStub = sinon.stub(logger, 'info');
16+
alertManager.sendAlert('SUBJECT', 'MESSAGE');
17+
expect(loggerStub.calledOnce).to.be.equal(true);
18+
loggerStub.restore();
19+
});
20+
});
21+
});

test/util/errorhandler.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const { describe, it, beforeEach } = require('mocha');
2+
const sinon = require('sinon');
3+
const { expect } = require('chai');
4+
const logger = require('../../lib/util/loggerFactory');
5+
const ErrorHandler = require('../../lib/util/ErrorHandler');
6+
const AlertManager = require('../../lib/util/AlertManager');
7+
8+
describe('#ErrorHandler', () => {
9+
let errorHandler;
10+
beforeEach(() => {
11+
errorHandler = new ErrorHandler(new AlertManager());
12+
});
13+
14+
describe('#onError', () => {
15+
it('should log global exception', () => {
16+
const loggerStub = sinon.stub(logger, 'error');
17+
errorHandler.onError({
18+
stack: 'I am stacktrace!',
19+
});
20+
expect(loggerStub.calledOnce).to.be.equal(true);
21+
loggerStub.restore();
22+
});
23+
24+
it('should send alert', () => {
25+
process.env.NODE_ENV = 'prod';
26+
const loggerStub = sinon.stub(logger, 'error');
27+
errorHandler.onError('I am error');
28+
expect(loggerStub.calledOnce).to.be.equal(true);
29+
loggerStub.restore();
30+
process.env.NODE_ENV = 'test';
31+
});
32+
});
33+
});

test/util/instrumentation.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const sinon = require('sinon');
44
const { expect } = require('chai');
55
const logger = require('../../lib/util/loggerFactory');
66

7-
describe('typeSanity', () => {
7+
describe('#Instrumentation', () => {
88
let instrumentation;
99
beforeEach(() => {
1010
instrumentation = new Instrumentation();

0 commit comments

Comments
 (0)