From dbf8e11786ad931da1d4cd8170de69691d17ad79 Mon Sep 17 00:00:00 2001 From: Koza Date: Sun, 22 Oct 2023 13:19:45 +0200 Subject: [PATCH] :bug: :white_check_mark: Fix caching for "Dismiss this Version" in pulsar-updater --- packages/pulsar-updater/spec/cache-spec.js | 33 ++++++++++++++++++---- packages/pulsar-updater/src/cache.js | 2 +- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/packages/pulsar-updater/spec/cache-spec.js b/packages/pulsar-updater/spec/cache-spec.js index 19baf8ed41..e5e42eb130 100644 --- a/packages/pulsar-updater/spec/cache-spec.js +++ b/packages/pulsar-updater/spec/cache-spec.js @@ -1,20 +1,41 @@ const cache = require("../src/cache.js"); describe("pulsar-updater cache", () => { + beforeEach(() => { + jasmine.useRealClock(); + }); + it("returns key for path", () => { let key = cache.cacheKeyForPath("test"); expect(key).toBe("pulsar-updater:test"); }); - it("returns expired properly according to date", () => { - let expiry = cache.isItemExpired({ createdOn: Date.now() }); + it("returns not expired properly according to date", () => { + let expiry = cache.isItemExpired({ createdOn: Date.now() }, 'some-key'); expect(expiry).toBe(false); }); - it("returns not expired if offline", () => { - spyOn(cache, "online").andReturn(true); + it("returns expired properly according to date", () => { + let expiry = cache.isItemExpired({ createdOn: 0 }, 'some-key'); + expect(expiry).toBe(true); + }); - let expiry = cache.isItemExpired({ createdOn: 0 }); + it("returns not expired properly for last-update-check", () => { + let expiry = cache.isItemExpired({ createdOn: 0 }, 'last-update-check'); expect(expiry).toBe(false); - }) + }); + + if(jasmine.version_.major > 1) { + // TODO: The current version right now is 1.3.1 of jasmine-node + // https://github.com/kevinsawicki/jasmine-node + // + // This is an unmaintained package that tried to implement jasmine for node, + // however we have an official jasmine implementation since then + it("returns not expired if offline", () => { + spyOnProperty(window.navigator, 'onLine').and.returnValue(false); + + let expiry = cache.isItemExpired({ createdOn: 0 }, 'some-key'); + expect(expiry).toBe(false); + }); + } }); diff --git a/packages/pulsar-updater/src/cache.js b/packages/pulsar-updater/src/cache.js index 02520d6db6..6f80c051ee 100644 --- a/packages/pulsar-updater/src/cache.js +++ b/packages/pulsar-updater/src/cache.js @@ -23,7 +23,7 @@ function getCacheItem(key) { let cached = JSON.parse(obj); - if (typeof cached === "object" && !isItemExpired(cached)) { + if (typeof cached === "object" && !isItemExpired(cached, key)) { return JSON.parse(cached.data); }