forked from launchdarkly/js-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Flag store should not access values from prototype. (launchdarkl…
…y#567) This should be merged after the test organization PR.
- Loading branch information
1 parent
ed7b27a
commit fca4d92
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
packages/shared/sdk-client/__tests__/flag-manager/FlagStore.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { DefaultFlagStore } from '../../src/flag-manager/FlagStore'; | ||
|
||
describe('given an empty flag store', () => { | ||
let store: DefaultFlagStore; | ||
|
||
beforeEach(() => { | ||
store = new DefaultFlagStore(); | ||
}); | ||
|
||
it.each(['unknown', 'toString', 'length'])( | ||
'gets undefined for a feature that does not exist', | ||
(key) => { | ||
expect(store.get(key)).toBeUndefined(); | ||
}, | ||
); | ||
|
||
it('can set and get key', () => { | ||
store.insertOrUpdate('toString', { | ||
version: 1, | ||
flag: { | ||
version: 1, | ||
flagVersion: 1, | ||
value: 'test-value', | ||
variation: 0, | ||
trackEvents: false, | ||
}, | ||
}); | ||
|
||
expect(store.get('toString')?.flag.value).toEqual('test-value'); | ||
}); | ||
|
||
it('replaces flags on init', () => { | ||
store.insertOrUpdate('potato', { | ||
version: 1, | ||
flag: { | ||
version: 1, | ||
flagVersion: 1, | ||
value: 'test-value', | ||
variation: 0, | ||
trackEvents: false, | ||
}, | ||
}); | ||
|
||
store.init({ | ||
newFlag: { | ||
version: 1, | ||
flag: { | ||
version: 1, | ||
flagVersion: 1, | ||
value: 'new-test-value', | ||
variation: 0, | ||
trackEvents: false, | ||
}, | ||
}, | ||
}); | ||
|
||
const all = store.getAll(); | ||
expect(Object.keys(all)).toEqual(['newFlag']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters