1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-20 23:31:30 +03:00
leon/test/unit/server/core/synchronizer.spec.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-02-10 15:26:50 +03:00
import Synchronizer from '@/core/synchronizer'
describe('synchronizer', () => {
describe('constructor()', () => {
test('creates a new instance of Synchronizer', () => {
2022-09-03 14:12:41 +03:00
const sync = new Synchronizer({}, {}, {})
2019-02-10 15:26:50 +03:00
expect(sync).toBeInstanceOf(Synchronizer)
})
})
describe('synchronize()', () => {
test('executes direct synchronization method', () => {
2022-09-03 14:12:41 +03:00
const brain = { socket: {} }
2019-02-10 15:26:50 +03:00
brain.talk = brain.socket.emit = brain.wernicke = jest.fn()
2022-09-03 14:12:41 +03:00
const sync = new Synchronizer(brain, {}, { method: 'direct' })
2019-02-10 15:26:50 +03:00
sync.direct = jest.fn()
sync.synchronize(() => {
expect(sync.direct).toHaveBeenCalledTimes(1)
})
})
test('executes Google Drive synchronization method', () => {
2022-09-03 14:12:41 +03:00
const brain = { socket: {} }
2019-02-10 15:26:50 +03:00
brain.talk = brain.socket.emit = brain.wernicke = jest.fn()
2022-09-03 14:12:41 +03:00
const sync = new Synchronizer(brain, {}, { method: 'google-drive' })
2019-02-10 15:26:50 +03:00
sync.googleDrive = jest.fn()
sync.synchronize(() => {
expect(sync.googleDrive).toHaveBeenCalledTimes(1)
})
})
})
describe('direct()', () => {
test('emits the download', () => {
const brain = { socket: { emit: jest.fn() } }
2022-09-03 14:12:41 +03:00
const sync = new Synchronizer(brain, {}, {})
2019-02-10 15:26:50 +03:00
sync.direct()
expect(sync.brain.socket.emit.mock.calls[0][0]).toBe('download')
})
})
})