Skip to content

Commit c2efad9

Browse files
authored
chore: adding max contexts validator (#537)
**Additional context** Forgot to add the max cached context to the validator and realized when bench testing.
1 parent 8ab2ee4 commit c2efad9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/shared/sdk-client/src/configuration/Configuration.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('Configuration', () => {
2626
logLevel: 1,
2727
name: 'LaunchDarkly',
2828
},
29+
maxCachedContexts: 5,
2930
privateAttributes: [],
3031
sendEvents: true,
3132
sendLDHeaders: true,
@@ -69,7 +70,7 @@ describe('Configuration', () => {
6970
);
7071
});
7172

72-
test('enforce minimum', () => {
73+
test('enforce minimum flushInterval', () => {
7374
const config = new Configuration({ flushInterval: 1 });
7475

7576
expect(config.flushInterval).toEqual(2);
@@ -89,4 +90,21 @@ describe('Configuration', () => {
8990
expect.stringMatching(/should be of type LDFlagSet, got string/i),
9091
);
9192
});
93+
94+
test('recognize maxCachedContexts', () => {
95+
const config = new Configuration({ maxCachedContexts: 3 });
96+
97+
expect(config.maxCachedContexts).toBeDefined();
98+
expect(console.error).not.toHaveBeenCalled();
99+
});
100+
101+
test('enforce minimum maxCachedContext', () => {
102+
const config = new Configuration({ maxCachedContexts: -1 });
103+
104+
expect(config.maxCachedContexts).toBeDefined();
105+
expect(console.error).toHaveBeenNthCalledWith(
106+
1,
107+
expect.stringContaining('had invalid value of -1'),
108+
);
109+
});
92110
});

packages/shared/sdk-client/src/configuration/validators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ConnectionModeValidator implements TypeValidator {
2727
const validators: Record<keyof LDOptions, TypeValidator> = {
2828
initialConnectionMode: new ConnectionModeValidator(),
2929
logger: TypeValidators.Object,
30+
maxCachedContexts: TypeValidators.numberWithMin(0),
3031

3132
baseUri: TypeValidators.String,
3233
streamUri: TypeValidators.String,

0 commit comments

Comments
 (0)