MCPcopy
hub / github.com/tinyplex/tinybase / getMockedStorage

Function getMockedStorage

test/unit/persisters/common/mocks.ts:179–222  ·  view source on GitHub ↗
(
  storage: Storage,
  getPersister: (store: Store, location: string) => AnyPersister,
)

Source from the content-addressed store, hash-verified

177});
178
179const getMockedStorage = (
180 storage: Storage,
181 getPersister: (store: Store, location: string) => AnyPersister,
182): Persistable => {
183 const mockStorage = {
184 getLocation: async (): Promise<string> => 'test' + Math.random(),
185 getLocationMethod: [
186 'getStorageName',
187 (location) => location,
188 ] as GetLocationMethod<string>,
189 getPersister,
190 get: async (location: string): Promise<Content | void> => {
191 try {
192 return JSON.parse(storage.getItem(location) ?? '');
193 } catch {}
194 },
195 set: async (
196 location: string,
197 content: Content | MergeableContent,
198 ): Promise<void> =>
199 await mockStorage.write(location, JSON.stringify(content)),
200 write: async (location: string, rawContent: any): Promise<void> => {
201 storage.setItem(location, rawContent);
202 window.dispatchEvent(
203 new StorageEvent('storage', {
204 storageArea: storage,
205 key: location,
206 newValue: rawContent,
207 }),
208 );
209 window.dispatchEvent(
210 new StorageEvent('storage', {
211 storageArea: storage,
212 key: location + 'another',
213 }),
214 );
215 },
216 del: async (location: string): Promise<void> =>
217 storage.removeItem(location),
218 testMissing: true,
219 testAutoLoad: true,
220 };
221 return mockStorage;
222};
223
224const getMockedDatabase = <Location>(
225 getLocation: () => Promise<Location>,

Callers 1

mocks.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…