Skip to content

Commit

Permalink
Invalidate Comunica caches after update queries
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Feb 22, 2019
1 parent a892996 commit b95888d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ComunicaUpdateEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export default class ComunicaUpdateEngine extends ComunicaEngine {
if (!response.ok)
throw new Error(`Update query failed (${response.status}): ${response.statusText}`);

// Invalidate Comunica's internal caches, as they may have changed because of the update
await this._engine.invalidateHttpCache(document);

// Mock Comunica's response for bindings as a Immutable.js object.
return { value: { size: 1, values: () => ({ next: () => ({ value: { ok: true } }) }) } };
}
Expand Down
6 changes: 6 additions & 0 deletions test/ComunicaUpdateEngine-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ describe('a ComunicaUpdateEngine instance', () => {
expect(args[1]).toHaveProperty('body');
expect(args[1].body).toEqual('INSERT DATA { <> <> <> }');
});

it('invalidates the document cache', () => {
expect(engine._engine.invalidateHttpCache).toHaveBeenCalledTimes(1);
const args = engine._engine.invalidateHttpCache.mock.calls[0];
expect(args[0]).toEqual('https://example.org/');
});
});

describe('Inserting an invalid query', () => {
Expand Down
3 changes: 3 additions & 0 deletions test/__mocks__/ldflex-comunica.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export default class ComunicaEngineMock {
constructor(subject, source) {
this._source = source;
this._engine = {
invalidateHttpCache: jest.fn(() => Promise.resolve(true)),
};
}

getDocument() {
Expand Down

0 comments on commit b95888d

Please sign in to comment.