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 src/application-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const loggerPrefix = '[Eppo SDK]';

// Create a Pino logger instance
export const logger = pino({
level: process.env.NODE_ENV === 'production' ? 'warn' : 'info',
level: process.env.LOG_LEVEL ?? (process.env.NODE_ENV === 'production' ? 'warn' : 'info'),
// https://getpino.io/#/docs/browser
browser: { disabled: true },
});
14 changes: 7 additions & 7 deletions src/client/eppo-client-assignment-details.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('EppoClient get*AssignmentDetails', () => {
});

it('should set the details for a matched rule', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);
const subjectAttributes = { email: '[email protected]', country: 'US' };
const result = client.getIntegerAssignmentDetails(
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('EppoClient get*AssignmentDetails', () => {
});

it('should set the details for a matched split', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);
const subjectAttributes = { email: '[email protected]', country: 'Brazil' };
const result = client.getIntegerAssignmentDetails(
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('EppoClient get*AssignmentDetails', () => {
});

it('should handle matching a split allocation with a matched rule', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);
const subjectAttributes = { id: 'alice', email: '[email protected]', country: 'Brazil' };
const result = client.getStringAssignmentDetails(
Expand Down Expand Up @@ -190,7 +190,7 @@ describe('EppoClient get*AssignmentDetails', () => {
});

it('should handle unrecognized flags', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);
const result = client.getIntegerAssignmentDetails('asdf', 'alice', {}, 0);
expect(result).toEqual({
Expand All @@ -215,7 +215,7 @@ describe('EppoClient get*AssignmentDetails', () => {
});

it('should handle type mismatches with graceful failure mode enabled', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(true);
const result = client.getBooleanAssignmentDetails('integer-flag', 'alice', {}, true);
expect(result).toEqual({
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('EppoClient get*AssignmentDetails', () => {
});

it('should throw an error for type mismatches with graceful failure mode disabled', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);
expect(() => client.getBooleanAssignmentDetails('integer-flag', 'alice', {}, true)).toThrow();
});
Expand Down Expand Up @@ -302,7 +302,7 @@ describe('EppoClient get*AssignmentDetails', () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const subject = subjects.find((subject) => subject.subjectKey === subjectKey)!;

const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);

const focusOn = {
Expand Down
2 changes: 1 addition & 1 deletion src/client/eppo-client-experiment-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('getExperimentContainerEntry', () => {
beforeEach(async () => {
const storage = new MemoryOnlyConfigurationStore<Flag | ObfuscatedFlag>();
await initConfiguration(storage);
client = new EppoClient(storage);
client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(true);
flagExperiment = {
flagKey: 'my-key',
Expand Down
7 changes: 6 additions & 1 deletion src/client/eppo-client-with-bandits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ describe('EppoClient Bandits E2E test', () => {
});

beforeEach(() => {
client = new EppoClient(flagStore, banditVariationStore, banditModelStore, undefined, false);
client = new EppoClient({
flagConfigurationStore: flagStore,
banditVariationConfigurationStore: banditVariationStore,
banditModelConfigurationStore: banditModelStore,
isObfuscated: false,
});
client.setIsGracefulFailureMode(false);
client.setAssignmentLogger({ logAssignment: mockLogAssignment });
client.setBanditLogger({ logBanditAction: mockLogBanditAction });
Expand Down
57 changes: 37 additions & 20 deletions src/client/eppo-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('EppoClient E2E test', () => {

beforeAll(() => {
storage.setEntries({ [flagKey]: mockFlag });
client = new EppoClient(storage);
client = new EppoClient({ flagConfigurationStore: storage });

td.replace(EppoClient.prototype, 'getAssignmentDetail', function () {
throw new Error('Mock test error');
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('EppoClient E2E test', () => {
it('Invokes logger for queued events', () => {
const mockLogger = td.object<IAssignmentLogger>();

const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.getStringAssignment(flagKey, 'subject-to-be-logged', {}, 'default-value');
client.setAssignmentLogger(mockLogger);

Expand All @@ -150,7 +150,7 @@ describe('EppoClient E2E test', () => {
it('Does not log same queued event twice', () => {
const mockLogger = td.object<IAssignmentLogger>();

const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });

client.getStringAssignment(flagKey, 'subject-to-be-logged', {}, 'default-value');
client.setAssignmentLogger(mockLogger);
Expand All @@ -161,7 +161,7 @@ describe('EppoClient E2E test', () => {

it('Does not invoke logger for events that exceed queue size', () => {
const mockLogger = td.object<IAssignmentLogger>();
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });

times(MAX_EVENT_QUEUE_SIZE + 100, (i) =>
client.getStringAssignment(flagKey, `subject-to-be-logged-${i}`, {}, 'default-value'),
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('EppoClient E2E test', () => {

it.each(Object.keys(testCases))('test variation assignment splits - %s', async (fileName) => {
const { flag, variationType, defaultValue, subjects } = testCases[fileName];
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);

let assignments: {
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('EppoClient E2E test', () => {

it.each(Object.keys(testCases))('test variation assignment splits - %s', async (fileName) => {
const { flag, variationType, defaultValue, subjects } = testCases[fileName];
const client = new EppoClient(storage, undefined, undefined, undefined, true);
const client = new EppoClient({ flagConfigurationStore: storage, isObfuscated: true });
client.setIsGracefulFailureMode(false);

const typeAssignmentFunctions = {
Expand Down Expand Up @@ -285,15 +285,17 @@ describe('EppoClient E2E test', () => {
});

it('returns null if getStringAssignment was called for the subject before any UFC was loaded', () => {
const localClient = new EppoClient(new MemoryOnlyConfigurationStore());
const localClient = new EppoClient({
flagConfigurationStore: new MemoryOnlyConfigurationStore(),
});
expect(localClient.getStringAssignment(flagKey, 'subject-1', {}, 'hello world')).toEqual(
'hello world',
);
expect(localClient.isInitialized()).toBe(false);
});

it('returns default value when key does not exist', async () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });

const nonExistentFlag = 'non-existent-flag';

Expand All @@ -310,7 +312,7 @@ describe('EppoClient E2E test', () => {
const mockLogger = td.object<IAssignmentLogger>();

storage.setEntries({ [flagKey]: mockFlag });
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setAssignmentLogger(mockLogger);

const subjectAttributes = { foo: 3 };
Expand All @@ -336,7 +338,7 @@ describe('EppoClient E2E test', () => {
td.when(mockLogger.logAssignment(td.matchers.anything())).thenThrow(new Error('logging error'));

storage.setEntries({ [flagKey]: mockFlag });
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setAssignmentLogger(mockLogger);

const subjectAttributes = { foo: 3 };
Expand All @@ -352,7 +354,7 @@ describe('EppoClient E2E test', () => {

it('exports flag configuration', () => {
storage.setEntries({ [flagKey]: mockFlag });
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
expect(client.getFlagConfigurations()).toEqual({ [flagKey]: mockFlag });
});

Expand All @@ -364,7 +366,7 @@ describe('EppoClient E2E test', () => {
mockLogger = td.object<IAssignmentLogger>();

storage.setEntries({ [flagKey]: mockFlag });
client = new EppoClient(storage);
client = new EppoClient({ flagConfigurationStore: storage });
client.setAssignmentLogger(mockLogger);
});

Expand Down Expand Up @@ -617,7 +619,10 @@ describe('EppoClient E2E test', () => {
});

it('Fetches initial configuration with parameters in constructor', async () => {
client = new EppoClient(thisFlagStorage, undefined, undefined, requestConfiguration);
client = new EppoClient({
flagConfigurationStore: thisFlagStorage,
configurationRequestParameters: requestConfiguration,
});
client.setIsGracefulFailureMode(false);
// no configuration loaded
let variation = client.getNumericAssignment(flagKey, subject, {}, 123.4);
Expand All @@ -629,7 +634,7 @@ describe('EppoClient E2E test', () => {
});

it('Fetches initial configuration with parameters provided later', async () => {
client = new EppoClient(thisFlagStorage);
client = new EppoClient({ flagConfigurationStore: thisFlagStorage });
client.setIsGracefulFailureMode(false);
client.setConfigurationRequestParameters(requestConfiguration);
// no configuration loaded
Expand All @@ -651,9 +656,12 @@ describe('EppoClient E2E test', () => {
}
}

client = new EppoClient(new MockStore(), undefined, undefined, {
...requestConfiguration,
pollAfterSuccessfulInitialization: true,
client = new EppoClient({
flagConfigurationStore: new MockStore(),
configurationRequestParameters: {
...requestConfiguration,
pollAfterSuccessfulInitialization: true,
},
});
client.setIsGracefulFailureMode(false);
// no configuration loaded
Expand All @@ -680,7 +688,10 @@ describe('EppoClient E2E test', () => {
}
}

client = new EppoClient(new MockStore(), undefined, undefined, requestConfiguration);
client = new EppoClient({
flagConfigurationStore: new MockStore(),
configurationRequestParameters: requestConfiguration,
});
client.setIsGracefulFailureMode(false);
// no configuration loaded
let variation = client.getNumericAssignment(flagKey, subject, {}, 0.0);
Expand Down Expand Up @@ -722,7 +733,10 @@ describe('EppoClient E2E test', () => {
...requestConfiguration,
pollAfterSuccessfulInitialization,
};
client = new EppoClient(thisFlagStorage, undefined, undefined, requestConfiguration);
client = new EppoClient({
flagConfigurationStore: thisFlagStorage,
configurationRequestParameters: requestConfiguration,
});
client.setIsGracefulFailureMode(false);
// no configuration loaded
let variation = client.getNumericAssignment(flagKey, subject, {}, 0.0);
Expand Down Expand Up @@ -787,7 +801,10 @@ describe('EppoClient E2E test', () => {
throwOnFailedInitialization,
pollAfterFailedInitialization,
};
client = new EppoClient(thisFlagStorage, undefined, undefined, requestConfiguration);
client = new EppoClient({
flagConfigurationStore: thisFlagStorage,
configurationRequestParameters: requestConfiguration,
});
client.setIsGracefulFailureMode(false);
// no configuration loaded
expect(client.getNumericAssignment(flagKey, subject, {}, 0.0)).toBe(0.0);
Expand Down
Loading
Loading