Skip to content

Commit

Permalink
Merge pull request #785 from kiskoza/fix-pulsar-updater-skip-version-…
Browse files Browse the repository at this point in the history
…cache

🐛 ✅ Fix caching for "Dismiss this Version" in pulsar-updater
  • Loading branch information
confused-Techie authored Oct 25, 2023
2 parents 87bb06b + dbf8e11 commit 27088af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
33 changes: 27 additions & 6 deletions packages/pulsar-updater/spec/cache-spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
});
2 changes: 1 addition & 1 deletion packages/pulsar-updater/src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 27088af

Please sign in to comment.