Skip to content

Commit e40e862

Browse files
committed
[FSSDK-12075] fix odp logging
1 parent a14d1bf commit e40e862

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

lib/message/error_message.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const NO_VARIATION_FOR_EXPERIMENT_KEY = 'No variation key %s defined in d
3939
export const ODP_CONFIG_NOT_AVAILABLE = 'ODP config is not available.';
4040
export const ODP_EVENT_FAILED = 'ODP event send failed.';
4141
export const ODP_EVENTS_SHOULD_HAVE_ATLEAST_ONE_KEY_VALUE = 'ODP events should have at least one key-value pair in identifiers.';
42-
export const ODP_EVENT_FAILED_ODP_MANAGER_MISSING = 'ODP Event failed to send. (ODP Manager not available).';
42+
export const ODP_MANAGER_MISSING = 'ODP Manager is missing. %s failed.';
4343
export const ODP_NOT_INTEGRATED = 'ODP is not integrated';
4444
export const UNDEFINED_ATTRIBUTE = 'Provided attribute: %s has an undefined value.';
4545
export const UNRECOGNIZED_ATTRIBUTE =

lib/optimizely/index.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { newErrorDecision } from '../optimizely_decision';
3131
import { ImpressionEvent } from '../event_processor/event_builder/user_event';
3232
import { OptimizelyDecideOption } from '../shared_types';
3333
import { NOTIFICATION_TYPES, DECISION_NOTIFICATION_TYPES } from '../notification_center/type';
34+
import { ODP_MANAGER_MISSING } from '../message/error_message';
3435

3536

3637
const holdoutData = [
@@ -905,4 +906,49 @@ describe('Optimizely', () => {
905906

906907
expect(optimizely.isRunning()).toBe(true);
907908
});
909+
910+
it('should log error when sendOdpEvent is called without odpManager', () => {
911+
const projectConfigManager = getMockProjectConfigManager({
912+
initConfig: createProjectConfig(testData.getTestProjectConfig()),
913+
});
914+
915+
const mockLogger = getMockLogger();
916+
const optimizely = new Optimizely({
917+
clientEngine: 'node-sdk',
918+
projectConfigManager,
919+
jsonSchemaValidator,
920+
logger: mockLogger,
921+
eventProcessor,
922+
disposable: true,
923+
cmabService: {} as any
924+
// odpManager is not provided
925+
});
926+
927+
optimizely.sendOdpEvent('test_action', 'test_type');
928+
929+
expect(mockLogger.error).toHaveBeenCalledWith(ODP_MANAGER_MISSING, 'sendOdpEvent');
930+
});
931+
932+
it('should log error when fetchQualifiedSegments is called without odpManager', async () => {
933+
const projectConfigManager = getMockProjectConfigManager({
934+
initConfig: createProjectConfig(testData.getTestProjectConfig()),
935+
});
936+
937+
const mockLogger = getMockLogger();
938+
const optimizely = new Optimizely({
939+
clientEngine: 'node-sdk',
940+
projectConfigManager,
941+
jsonSchemaValidator,
942+
logger: mockLogger,
943+
eventProcessor,
944+
disposable: true,
945+
cmabService: {} as any
946+
// odpManager is not provided
947+
});
948+
949+
const result = await optimizely.fetchQualifiedSegments('test_user');
950+
951+
expect(result).toBeNull();
952+
expect(mockLogger.error).toHaveBeenCalledWith(ODP_MANAGER_MISSING, 'fetchQualifiedSegments');
953+
});
908954
});

lib/optimizely/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import {
6969
INVALID_INPUT_FORMAT,
7070
NO_EVENT_PROCESSOR,
7171
ODP_EVENT_FAILED,
72-
ODP_EVENT_FAILED_ODP_MANAGER_MISSING,
72+
ODP_MANAGER_MISSING,
7373
UNABLE_TO_GET_VUID_VUID_MANAGER_NOT_AVAILABLE,
7474
UNRECOGNIZED_DECIDE_OPTION,
7575
NO_PROJECT_CONFIG_FAILURE,
@@ -1750,7 +1750,7 @@ export default class Optimizely extends BaseService implements Client {
17501750
data?: Map<string, unknown>
17511751
): void {
17521752
if (!this.odpManager) {
1753-
this.logger?.error(ODP_EVENT_FAILED_ODP_MANAGER_MISSING);
1753+
this.logger?.error(ODP_MANAGER_MISSING, 'sendOdpEvent');
17541754
return;
17551755
}
17561756

@@ -1780,6 +1780,7 @@ export default class Optimizely extends BaseService implements Client {
17801780
options?: Array<OptimizelySegmentOption>
17811781
): Promise<string[] | null> {
17821782
if (!this.odpManager) {
1783+
this.logger?.error(ODP_MANAGER_MISSING, 'fetchQualifiedSegments');
17831784
return null;
17841785
}
17851786

0 commit comments

Comments
 (0)