Skip to content

Commit 7b77601

Browse files
committed
tests
1 parent 028c2a4 commit 7b77601

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

src/configuration-requestor.spec.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import FetchHttpClient, {
1515
IUniversalFlagConfigResponse,
1616
} from './http-client';
1717
import { StoreBackedConfiguration } from './i-configuration';
18-
import { BanditParameters, BanditVariation, Flag } from './interfaces';
18+
import { BanditParameters, BanditVariation, Flag, VariationType } from './interfaces';
1919

2020
describe('ConfigurationRequestor', () => {
2121
let flagStore: IConfigurationStore<Flag>;
@@ -641,5 +641,72 @@ describe('ConfigurationRequestor', () => {
641641
// expect(fetchSpy.mock.calls.length).toBe(initialFetchCount + 1);
642642
});
643643
});
644+
645+
describe('IConfigurationStore updates', () => {
646+
it('should update configuration when stores are changed', async () => {
647+
// Create new stores
648+
const newFlagStore = new MemoryOnlyConfigurationStore<Flag>();
649+
const newBanditVariationStore = new MemoryOnlyConfigurationStore<BanditVariation[]>();
650+
const newBanditModelStore = new MemoryOnlyConfigurationStore<BanditParameters>();
651+
652+
// Add a test flag to the new flag store
653+
await newFlagStore.setEntries({
654+
'test-flag': {
655+
key: 'test-flag',
656+
enabled: true,
657+
variationType: VariationType.STRING,
658+
variations: {
659+
control: { key: 'control', value: 'control-value' },
660+
treatment: { key: 'treatment', value: 'treatment-value' },
661+
},
662+
allocations: [
663+
{
664+
key: 'allocation-1',
665+
rules: [],
666+
splits: [
667+
{
668+
shards: [{ salt: '', ranges: [{ start: 0, end: 10000 }] }],
669+
variationKey: 'treatment',
670+
},
671+
],
672+
doLog: true,
673+
},
674+
],
675+
totalShards: 10000,
676+
},
677+
});
678+
679+
await newBanditModelStore.setEntries({
680+
'test-bandit': {
681+
banditKey: 'test-bandt',
682+
modelVersion: 'v123',
683+
modelName: 'falcon',
684+
modelData: {
685+
coefficients: {},
686+
gamma: 0,
687+
defaultActionScore: 0,
688+
actionProbabilityFloor: 0,
689+
},
690+
},
691+
});
692+
693+
// Get the configuration and verify it has the test flag
694+
const initialConfig = configurationRequestor.getConfiguration();
695+
expect(initialConfig.getFlagKeys()).toEqual([]);
696+
expect(Object.keys(initialConfig.getBandits())).toEqual([]);
697+
698+
// Update the stores
699+
configurationRequestor.setConfigurationStores(
700+
newFlagStore,
701+
newBanditVariationStore,
702+
newBanditModelStore,
703+
);
704+
705+
// Get the configuration and verify it has the test flag
706+
const config = configurationRequestor.getConfiguration();
707+
expect(config.getFlagKeys()).toEqual(['test-flag']);
708+
expect(Object.keys(config.getBandits())).toEqual(['test-bandit']);
709+
});
710+
});
644711
});
645712
});

0 commit comments

Comments
 (0)