Skip to content

Commit 891fee6

Browse files
authored
fix: logOnlyEventDispatcher matches expected type and calls done callback (#81)
Summary: - Update logOnlyEventDispatcher to be compatible with new type definition for EventDispatcher, introduced in optimizely-sdk 4.3.4 - Make logOnlyEventDispatcher call the done callback Test Plan: Added unit test
1 parent b0f52b9 commit 891fee6

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Bug fixes
11+
- Fix `logOnlyEventDispatcher` to conform to `EventDispatcher` type from @optimizely/optimizely-sdk ([#81](https://github.com/optimizely/react-sdk/pull/81))
12+
1013
## [2.3.2] - October 9th, 2020
1114
Upgrade `@optimizely/optimizely-sdk` to [4.3.4](https://github.com/optimizely/javascript-sdk/releases/tag/v4.3.4):
1215
- Exported Optimizely Config Entities types from TypeScript type definitions. See [@optimizely/optimizely-sdk Release 4.3.3](https://github.com/optimizely/javascript-sdk/releases/tag/v4.3.3) for more details.

src/logOnlyEventDispatcher.spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
jest.mock('@optimizely/js-sdk-logging', () => ({
2+
getLogger: jest.fn().mockReturnValue({ debug: jest.fn() }),
3+
}));
4+
5+
import logOnlyEventDispatcher from './logOnlyEventDispatcher';
6+
import * as logging from '@optimizely/js-sdk-logging';
7+
8+
const logger = logging.getLogger('ReactSDK');
9+
10+
describe('logOnlyEventDispatcher', () => {
11+
it('logs a message', () => {
12+
const callback = jest.fn();
13+
logOnlyEventDispatcher.dispatchEvent({ url: 'https://localhost:8080', httpVerb: 'POST', params: {} }, callback);
14+
expect(callback).toHaveBeenCalled();
15+
expect(logger.debug).toHaveBeenCalled();
16+
});
17+
});

src/logOnlyEventDispatcher.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const logger = logging.getLogger('ReactSDK');
2525
* all event dispatching.
2626
*/
2727
const logOnlyEventDispatcher: optimizely.EventDispatcher = {
28-
dispatchEvent(event: optimizely.Event, callback: () => void): void {
28+
dispatchEvent(event: optimizely.Event, callback: (response: { statusCode: number }) => void): void {
2929
logger.debug('Event not dispatched by disabled event dispatcher: %s', () => {
3030
let eventStr: string;
3131
try {
@@ -35,6 +35,7 @@ const logOnlyEventDispatcher: optimizely.EventDispatcher = {
3535
}
3636
return eventStr;
3737
});
38+
callback({ statusCode: 204 });
3839
},
3940
};
4041

0 commit comments

Comments
 (0)