Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/message/error_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const NO_VARIATION_FOR_EXPERIMENT_KEY = 'No variation key %s defined in d
export const ODP_CONFIG_NOT_AVAILABLE = 'ODP config is not available.';
export const ODP_EVENT_FAILED = 'ODP event send failed.';
export const ODP_EVENTS_SHOULD_HAVE_ATLEAST_ONE_KEY_VALUE = 'ODP events should have at least one key-value pair in identifiers.';
export const ODP_EVENT_FAILED_ODP_MANAGER_MISSING = 'ODP Event failed to send. (ODP Manager not available).';
export const ODP_MANAGER_MISSING = 'ODP Manager is missing. %s failed.';
export const ODP_NOT_INTEGRATED = 'ODP is not integrated';
export const UNDEFINED_ATTRIBUTE = 'Provided attribute: %s has an undefined value.';
export const UNRECOGNIZED_ATTRIBUTE =
Expand Down
46 changes: 46 additions & 0 deletions lib/optimizely/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { newErrorDecision } from '../optimizely_decision';
import { ImpressionEvent } from '../event_processor/event_builder/user_event';
import { OptimizelyDecideOption } from '../shared_types';
import { NOTIFICATION_TYPES, DECISION_NOTIFICATION_TYPES } from '../notification_center/type';
import { ODP_MANAGER_MISSING } from 'error_message';


const holdoutData = [
Expand Down Expand Up @@ -905,4 +906,49 @@ describe('Optimizely', () => {

expect(optimizely.isRunning()).toBe(true);
});

it('should log error when sendOdpEvent is called without odpManager', () => {
const projectConfigManager = getMockProjectConfigManager({
initConfig: createProjectConfig(testData.getTestProjectConfig()),
});

const mockLogger = getMockLogger();
const optimizely = new Optimizely({
clientEngine: 'node-sdk',
projectConfigManager,
jsonSchemaValidator,
logger: mockLogger,
eventProcessor,
disposable: true,
cmabService: {} as any
// odpManager is not provided
});

optimizely.sendOdpEvent('test_action', 'test_type');

expect(mockLogger.error).toHaveBeenCalledWith(ODP_MANAGER_MISSING, 'sendOdpEvent');
});

it('should log error when fetchQualifiedSegments is called without odpManager', async () => {
const projectConfigManager = getMockProjectConfigManager({
initConfig: createProjectConfig(testData.getTestProjectConfig()),
});

const mockLogger = getMockLogger();
const optimizely = new Optimizely({
clientEngine: 'node-sdk',
projectConfigManager,
jsonSchemaValidator,
logger: mockLogger,
eventProcessor,
disposable: true,
cmabService: {} as any
// odpManager is not provided
});

const result = await optimizely.fetchQualifiedSegments('test_user');

expect(result).toBeNull();
expect(mockLogger.error).toHaveBeenCalledWith(ODP_MANAGER_MISSING, 'fetchQualifiedSegments');
});
});
5 changes: 3 additions & 2 deletions lib/optimizely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import {
INVALID_INPUT_FORMAT,
NO_EVENT_PROCESSOR,
ODP_EVENT_FAILED,
ODP_EVENT_FAILED_ODP_MANAGER_MISSING,
ODP_MANAGER_MISSING,
UNABLE_TO_GET_VUID_VUID_MANAGER_NOT_AVAILABLE,
UNRECOGNIZED_DECIDE_OPTION,
NO_PROJECT_CONFIG_FAILURE,
Expand Down Expand Up @@ -1750,7 +1750,7 @@ export default class Optimizely extends BaseService implements Client {
data?: Map<string, unknown>
): void {
if (!this.odpManager) {
this.logger?.error(ODP_EVENT_FAILED_ODP_MANAGER_MISSING);
this.logger?.error(ODP_MANAGER_MISSING, 'sendOdpEvent');
return;
}

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

Expand Down
Loading