diff --git a/umap/static/umap/js/modules/sync/engine.js b/umap/static/umap/js/modules/sync/engine.js index 5009d53f..9c4f15e6 100644 --- a/umap/static/umap/js/modules/sync/engine.js +++ b/umap/static/umap/js/modules/sync/engine.js @@ -47,10 +47,11 @@ export class MessagesDispatcher { } dispatch({ kind, ...payload }) { - console.log('received message', kind, payload) if (kind == 'operation') { let updater = this.getUpdater(payload.subject, payload.metadata) updater.applyMessage(payload) + } else { + throw new Error(`Unknown dispatch kind: ${kind}`) } } } diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js index e934434b..d7a45492 100644 --- a/umap/static/umap/js/modules/sync/updaters.js +++ b/umap/static/umap/js/modules/sync/updaters.js @@ -20,7 +20,7 @@ class BaseUpdater { if (part in currentObj) return currentObj[part] }, obj) - // In case the given path doesn't exist, bail out + // In case the given path doesn't exist, stop here if (objectToSet === undefined) return // Set the value (or delete it) diff --git a/umap/static/umap/unittests/updaters.js b/umap/static/umap/unittests/sync.js similarity index 61% rename from umap/static/umap/unittests/updaters.js rename to umap/static/umap/unittests/sync.js index 7a60a544..a7eb464b 100644 --- a/umap/static/umap/unittests/updaters.js +++ b/umap/static/umap/unittests/sync.js @@ -1,13 +1,52 @@ import { describe, it } from 'mocha' +import sinon from 'sinon' import pkg from 'chai' const { expect } = pkg -import { - MapUpdater, - DataLayerUpdater, - FeatureUpdater, -} from '../js/modules/sync/updaters.js' +import { MapUpdater } from '../js/modules/sync/updaters.js' +import { MessagesDispatcher, SyncEngine } from '../js/modules/sync/engine.js' + +describe('SyncEngine', () => { + it('should initialize methods even before start', function () { + const engine = new SyncEngine({}) + engine.upsert() + engine.update() + engine.delete() + }) +}) + +describe('MessageDispatcher', () => { + describe('#dispatch', function () { + it('should raise an error on unknown updater', function () { + const dispatcher = new MessagesDispatcher({}) + expect(() => { + dispatcher.dispatch({ + kind: 'operation', + subject: 'unknown', + metadata: {}, + }) + }).to.throw(Error) + }) + it('should produce an error on malformated messages', function () { + const dispatcher = new MessagesDispatcher({}) + expect(() => { + dispatcher.dispatch({ + yeah: 'yeah', + payload: { foo: 'bar' }, + }) + }).to.throw(Error) + }) + it('should raise an unknown operations', function () { + const dispatcher = new MessagesDispatcher({}) + expect(() => { + dispatcher.dispatch({ + kind: 'something-else', + }) + }).to.throw(Error) + }) + }) +}) describe('Updaters', () => { describe('BaseUpdater', function () {