MCPcopy Index your code
hub / github.com/OneNoteDev/WebClipper / MockStorage

Class MockStorage

src/tests/storage/mockStorage.ts:5–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import {Storage} from "../../scripts/storage/storage";
4
5export class MockStorage implements Storage {
6 public static existingKey = "exist";
7 public static nonLocalData = { myKey: "nonLocal" };
8 public static localData = { myKey: "local" };
9 public static fetchNonLocalData: () => Promise<ResponsePackage<string>> = () => {
10 return new Promise<ResponsePackage<string>>((resolve, reject) => {
11 resolve({ parsedResponse: JSON.stringify(MockStorage.nonLocalData), request: undefined });
12 });
13 };
14
15 private storedValues: { [key: string]: string } = { };
16
17 constructor() {
18 // We set lastUpdated this way so that our tests are consistent
19 let existingValue = { data: MockStorage.localData, lastUpdated: Date.now() - 1 };
20 this.setValue(MockStorage.existingKey, JSON.stringify(existingValue));
21 }
22
23 public getValue(key: string): string {
24 return this.storedValues[key];
25 }
26
27 public getValues(keys: string[]): {} {
28 let values = {};
29 for (let i = 0; i < keys.length; i++) {
30 values[keys[i]] = this.storedValues[keys[i]];
31 }
32 return values;
33 }
34
35 public setValue(key: string, value: string): void {
36 this.storedValues[key] = value;
37 }
38
39 public removeKey(key): boolean {
40 this.storedValues[key] = undefined;
41 return true;
42 }
43}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected