59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { setupTest } from 'dashtab/tests/helpers';
|
|
|
|
function entry(key, type, instanceKey, events = []) {
|
|
return {
|
|
key,
|
|
source: { type, instanceKey, calendarId: key, name: key },
|
|
fetchedAt: 1,
|
|
events,
|
|
};
|
|
}
|
|
|
|
module('Unit | Service | calendar-cache', function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
hooks.beforeEach(async function () {
|
|
const cache = this.owner.lookup('service:calendar-cache');
|
|
await cache.ready;
|
|
await cache.clear();
|
|
});
|
|
|
|
test('it exists', function (assert) {
|
|
assert.ok(this.owner.lookup('service:calendar-cache'));
|
|
});
|
|
|
|
test('put stores an entry and exposes it by key and source', async function (assert) {
|
|
const cache = this.owner.lookup('service:calendar-cache');
|
|
const record = entry('calendar-ics:a', 'calendar-ics', 'a', [{ id: 'e1' }]);
|
|
|
|
await cache.put(record);
|
|
|
|
assert.deepEqual(cache.get(record.key), record);
|
|
assert.strictEqual(cache.all().length, 1);
|
|
assert.strictEqual(cache.forSource('calendar-ics', 'a').length, 1);
|
|
assert.strictEqual(cache.forSource('calendar-caldav', 'a').length, 0);
|
|
});
|
|
|
|
test('removeSource removes only the matching source', async function (assert) {
|
|
const cache = this.owner.lookup('service:calendar-cache');
|
|
|
|
await cache.put(entry('calendar-ics:a', 'calendar-ics', 'a'));
|
|
await cache.put(entry('calendar-ics:b', 'calendar-ics', 'b'));
|
|
|
|
await cache.removeSource('calendar-ics', 'a');
|
|
|
|
assert.strictEqual(cache.get('calendar-ics:a'), null);
|
|
assert.ok(cache.get('calendar-ics:b'));
|
|
});
|
|
|
|
test('load restores persisted entries', async function (assert) {
|
|
const cache = this.owner.lookup('service:calendar-cache');
|
|
await cache.put(entry('calendar-ics:a', 'calendar-ics', 'a'));
|
|
|
|
await cache.load();
|
|
|
|
assert.ok(cache.get('calendar-ics:a'));
|
|
});
|
|
});
|