-
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.
feat: Read entries out of
AbstractAssignmentCache
(#89)
* feat: Read entries out of `AbstractAssignmentCache` * make these protected * comments * new Set-based assignment cache * fix imports * update tests to reflect new logic * extract key to string method * export symbols * update comments * go back to map implementation * fix tests * expose map store * fix assignment cache key/value handling * export this fn * fix nits
- Loading branch information
Showing
7 changed files
with
102 additions
and
41 deletions.
There are no files selected for viewing
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,27 @@ | ||
import { | ||
assignmentCacheKeyToString, | ||
assignmentCacheValueToString, | ||
NonExpiringInMemoryAssignmentCache, | ||
} from './abstract-assignment-cache'; | ||
|
||
describe('NonExpiringInMemoryAssignmentCache', () => { | ||
it('read and write entries', () => { | ||
const cache = new NonExpiringInMemoryAssignmentCache(); | ||
const key1 = { subjectKey: 'a', flagKey: 'b', allocationKey: 'c', variationKey: 'd' }; | ||
const key2 = { subjectKey: '1', flagKey: '2', allocationKey: '3', variationKey: '4' }; | ||
cache.set(key1); | ||
expect(cache.has(key1)).toBeTruthy(); | ||
expect(cache.has(key2)).toBeFalsy(); | ||
cache.set(key2); | ||
expect(cache.has(key2)).toBeTruthy(); | ||
// this makes an assumption about the internal implementation of the cache, which is not ideal | ||
// but it's the only way to test the cache without exposing the internal state | ||
expect(Array.from(cache.entries())).toEqual([ | ||
[assignmentCacheKeyToString(key1), assignmentCacheValueToString(key1)], | ||
[assignmentCacheKeyToString(key2), assignmentCacheValueToString(key2)], | ||
]); | ||
|
||
expect(cache.has({ ...key1, allocationKey: 'c1' })).toBeFalsy(); | ||
expect(cache.has({ ...key2, variationKey: 'd1' })).toBeFalsy(); | ||
}); | ||
}); |
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
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
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
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
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
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