Skip to content

Commit

Permalink
Added check for event handler presense to getCaseParties
Browse files Browse the repository at this point in the history
* Added check for event handler presense to getCaseParties
* Added unit test
  • Loading branch information
chriswsh committed Sep 2, 2017
1 parent e5286bb commit 9cc42ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export function getCaseParties(casenumber, options) {
options
);

if (!(emitter.listenerCount(`retrieve-parties`))) {
logger.warn(`No listener is attached to emitter.retrieve-parties. Did you remember to include a data source?`);
}

// emit runs synchronously because I/O is not involved, so result will always be populated
// before further functions are called.
emitter.emit(`retrieve-parties`, casenumber, result);
Expand Down
7 changes: 7 additions & 0 deletions test/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ describe(`events`, () => {
});

describe(`log4js`, () => {
it(`should send something to log4js if no handlers are attached to retrieve-parties`, () => {
return testee.getCaseParties(dummyCase).then(() => {
let logged = traceStub.called || debugStub.called || infoStub.called || logStub.called || warnStub.called || errorStub.called || fatalStub.called;
expect(logged).to.equal(true);
});
});

it(`should send something to log4js when handling a rejected promise`, () => {
emitter.on(`retrieve-parties`, (casenumber, result) => {
result.promises.push(Promise.reject(`failed`));
Expand Down

0 comments on commit 9cc42ac

Please sign in to comment.