mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
Fix SingleUserStateProvider (#7593)
* Fix SingleUserStateProvider - Fix cache key to be unique per instance per user * Add Specific State Provider Tests * Add Missing await
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { Opaque } from "type-fest";
|
||||
|
||||
import { UserId } from "../../types/guid";
|
||||
|
||||
import { KeyDefinition } from "./key-definition";
|
||||
import { StateDefinition } from "./state-definition";
|
||||
|
||||
@@ -109,4 +111,24 @@ describe("KeyDefinition", () => {
|
||||
expect(deserializedValue[1]).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildCacheKey", () => {
|
||||
const keyDefinition = new KeyDefinition(fakeStateDefinition, "fake", {
|
||||
deserializer: (s) => s,
|
||||
});
|
||||
|
||||
it("builds unique cache key for each user", () => {
|
||||
const cacheKeys: string[] = [];
|
||||
|
||||
// single user keys
|
||||
cacheKeys.push(keyDefinition.buildCacheKey("user", "1" as UserId));
|
||||
cacheKeys.push(keyDefinition.buildCacheKey("user", "2" as UserId));
|
||||
|
||||
expect(new Set(cacheKeys).size).toBe(cacheKeys.length);
|
||||
});
|
||||
|
||||
it("throws with bad usage", () => {
|
||||
expect(() => keyDefinition.buildCacheKey("user", null)).toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user