-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Update configuration stores in ConfigurationRequestor
when they are changed on the client
#257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
IUniversalFlagConfigResponse, | ||
} from './http-client'; | ||
import { StoreBackedConfiguration } from './i-configuration'; | ||
import { BanditParameters, BanditVariation, Flag } from './interfaces'; | ||
import { BanditParameters, BanditVariation, Flag, VariationType } from './interfaces'; | ||
|
||
describe('ConfigurationRequestor', () => { | ||
let flagStore: IConfigurationStore<Flag>; | ||
|
@@ -610,7 +610,7 @@ | |
banditModelStore, | ||
); | ||
|
||
const ufcResponse = { | ||
Check warning on line 613 in src/configuration-requestor.spec.ts
|
||
flags: { test_flag: { key: 'test_flag', value: true } }, | ||
banditReferences: { | ||
bandit: { | ||
|
@@ -641,5 +641,72 @@ | |
// expect(fetchSpy.mock.calls.length).toBe(initialFetchCount + 1); | ||
}); | ||
}); | ||
|
||
describe('IConfigurationStore updates', () => { | ||
it('should update configuration when stores are changed', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
// Create new stores | ||
const newFlagStore = new MemoryOnlyConfigurationStore<Flag>(); | ||
const newBanditVariationStore = new MemoryOnlyConfigurationStore<BanditVariation[]>(); | ||
const newBanditModelStore = new MemoryOnlyConfigurationStore<BanditParameters>(); | ||
|
||
// Add a test flag to the new flag store | ||
await newFlagStore.setEntries({ | ||
'test-flag': { | ||
key: 'test-flag', | ||
enabled: true, | ||
variationType: VariationType.STRING, | ||
variations: { | ||
control: { key: 'control', value: 'control-value' }, | ||
treatment: { key: 'treatment', value: 'treatment-value' }, | ||
}, | ||
allocations: [ | ||
{ | ||
key: 'allocation-1', | ||
rules: [], | ||
splits: [ | ||
{ | ||
shards: [{ salt: '', ranges: [{ start: 0, end: 10000 }] }], | ||
variationKey: 'treatment', | ||
}, | ||
], | ||
doLog: true, | ||
}, | ||
], | ||
totalShards: 10000, | ||
}, | ||
}); | ||
|
||
await newBanditModelStore.setEntries({ | ||
'test-bandit': { | ||
banditKey: 'test-bandt', | ||
modelVersion: 'v123', | ||
modelName: 'falcon', | ||
modelData: { | ||
coefficients: {}, | ||
gamma: 0, | ||
defaultActionScore: 0, | ||
actionProbabilityFloor: 0, | ||
}, | ||
}, | ||
}); | ||
|
||
// Get the configuration and verify it has the test flag | ||
const initialConfig = configurationRequestor.getConfiguration(); | ||
expect(initialConfig.getFlagKeys()).toEqual([]); | ||
expect(Object.keys(initialConfig.getBandits())).toEqual([]); | ||
|
||
// Update the stores | ||
configurationRequestor.setConfigurationStores( | ||
newFlagStore, | ||
newBanditVariationStore, | ||
newBanditModelStore, | ||
); | ||
|
||
// Get the configuration and verify it has the test flag | ||
const config = configurationRequestor.getConfiguration(); | ||
expect(config.getFlagKeys()).toEqual(['test-flag']); | ||
expect(Object.keys(config.getBandits())).toEqual(['test-bandit']); | ||
}); | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.