Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 ✅ Fix caching for "Dismiss this Version" in pulsar-updater #785

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading