File tree Expand file tree Collapse file tree 4 files changed +57
-3
lines changed Expand file tree Collapse file tree 4 files changed +57
-3
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ const sinon = require('sinon');
44const { expect } = require ( 'chai' ) ;
55const logger = require ( '../../lib/util/loggerFactory' ) ;
66
7- describe ( 'typeSanity ' , ( ) => {
7+ describe ( '#Instrumentation ' , ( ) => {
88 let instrumentation ;
99 beforeEach ( ( ) => {
1010 instrumentation = new Instrumentation ( ) ;
You can’t perform that action at this time.
0 commit comments