mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 03:42:37 +02:00
chore(sync): Add message-dispatcher unit tests
This commit is contained in:
parent
74a1670c9d
commit
92676e03ae
3 changed files with 47 additions and 7 deletions
|
@ -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}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 () {
|
Loading…
Reference in a new issue