mirror of
https://github.com/bitwarden/browser
synced 2026-02-21 20:04:02 +00:00
* refactor: introduce @bitwarden/serialization * refactor: introduce @bitwarden/guid * refactor: introduce @bitwaren/client-type * refactor: introduce @bitwarden/core-test-utils * refactor: introduce @bitwarden/state and @bitwarden/state-test-utils Creates initial project structure for centralized application state management. Part of modularization effort to extract state code from common. * Added state provider documentation to README. * Changed callouts to Github format. * Fixed linting on file name. * Forced git to accept rename --------- Co-authored-by: Todd Martin <tmartin@bitwarden.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { FakeStorageService } from "@bitwarden/storage-test-utils";
|
|
|
|
import { getStoredValue } from "./util";
|
|
|
|
describe("getStoredValue", () => {
|
|
const key = "key";
|
|
const deserializedValue = { value: 1 };
|
|
const value = JSON.stringify(deserializedValue);
|
|
const deserializer = (v: string) => JSON.parse(v);
|
|
let storageService: FakeStorageService;
|
|
|
|
beforeEach(() => {
|
|
storageService = new FakeStorageService();
|
|
});
|
|
|
|
describe("when the storage service requires deserialization", () => {
|
|
beforeEach(() => {
|
|
storageService.internalUpdateValuesRequireDeserialization(true);
|
|
});
|
|
|
|
it("should deserialize", async () => {
|
|
await storageService.save(key, value);
|
|
|
|
const result = await getStoredValue(key, storageService, deserializer);
|
|
|
|
expect(result).toEqual(deserializedValue);
|
|
});
|
|
});
|
|
describe("when the storage service does not require deserialization", () => {
|
|
beforeEach(() => {
|
|
storageService.internalUpdateValuesRequireDeserialization(false);
|
|
});
|
|
|
|
it("should not deserialize", async () => {
|
|
await storageService.save(key, value);
|
|
|
|
const result = await getStoredValue(key, storageService, deserializer);
|
|
|
|
expect(result).toEqual(value);
|
|
});
|
|
|
|
it("should convert undefined to null", async () => {
|
|
await storageService.save(key, undefined);
|
|
|
|
const result = await getStoredValue(key, storageService, deserializer);
|
|
|
|
expect(result).toEqual(null);
|
|
});
|
|
});
|
|
});
|