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

Method tests

src/tests/storage/clipperData_tests.ts:21–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19 }
20
21 protected tests() {
22 test("getFreshValue should not store anything if it's retrieving notebooks and no userInformation is in storage", (assert: QUnitAssert) => {
23 let done = assert.async();
24
25 let key = ClipperStorageKeys.cachedNotebooks;
26 let parsedResponse = {};
27 let expectedTimeStampedData = {
28 parsedResponse: JSON.stringify(parsedResponse),
29 request: undefined
30 };
31 let getRemoteValue = () => {
32 return Promise.resolve(expectedTimeStampedData);
33 };
34
35 let clipperData = new ClipperData(this.mockStorage);
36 clipperData.getFreshValue(key, getRemoteValue, 0).then((timeStampedData) => {
37 strictEqual(this.mockStorage.getValue(key), undefined,
38 "Notebooks should not be cached if userInformation does not exist in storage");
39 }, (error) => {
40 ok(false, "reject should not be called");
41 }).then(() => {
42 done();
43 });
44 });
45
46 test("getFreshValue should store notebooks if it's retrieving notebooks and userInformation is in storage", (assert: QUnitAssert) => {
47 let done = assert.async();
48
49 let key = ClipperStorageKeys.cachedNotebooks;
50 let parsedResponse = {};
51 let expectedTimeStampedData = {
52 parsedResponse: JSON.stringify(parsedResponse),
53 request: undefined
54 };
55 let getRemoteValue = () => {
56 return Promise.resolve(expectedTimeStampedData);
57 };
58
59 this.mockStorage.setValue(ClipperStorageKeys.userInformation, "{ name: Leeeeeroy }");
60
61 let clipperData = new ClipperData(this.mockStorage);
62 clipperData.getFreshValue(key, getRemoteValue, 0).then((timeStampedData) => {
63 let actualStored: TimeStampedData = JSON.parse(this.mockStorage.getValue(key));
64 deepEqual(actualStored.data, {},
65 "Notebooks should be cached if userInformation exists in storage");
66 }, (error) => {
67 ok(false, "reject should not be called");
68 }).then(() => {
69 done();
70 });
71 });
72
73 test("getFreshValue should not store anything if it's setting notebooks and no userInformation is in storage", () => {
74 let key = ClipperStorageKeys.cachedNotebooks;
75 let expectedTimeStampedData = JSON.stringify({
76 parsedResponse: "{ notebooks: {} }",
77 request: undefined
78 });

Callers

nothing calls this directly

Calls 5

getFreshValueMethod · 0.95
setValueMethod · 0.95
doneFunction · 0.85
getValueMethod · 0.65
setValueMethod · 0.65

Tested by

no test coverage detected