Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
80 lines
2.0 KiB
TypeScript
80 lines
2.0 KiB
TypeScript
import { HighlightSyncManager } from '@/lib/highlight-sync-manager'
|
|
import { BibleHighlight } from '@/types'
|
|
|
|
describe('HighlightSyncManager', () => {
|
|
let manager: HighlightSyncManager
|
|
|
|
beforeEach(() => {
|
|
manager = new HighlightSyncManager()
|
|
})
|
|
|
|
it('should add highlight to sync queue', async () => {
|
|
const highlight: BibleHighlight = {
|
|
id: 'h-1',
|
|
verseId: 'v-1',
|
|
color: 'yellow',
|
|
createdAt: Date.now(),
|
|
updatedAt: Date.now(),
|
|
syncStatus: 'pending'
|
|
}
|
|
|
|
await manager.queueHighlight(highlight)
|
|
const pending = await manager.getPendingSyncItems()
|
|
|
|
expect(pending.length).toBe(1)
|
|
expect(pending[0].id).toBe('h-1')
|
|
})
|
|
|
|
it('should mark highlight as syncing', async () => {
|
|
const highlight: BibleHighlight = {
|
|
id: 'h-1',
|
|
verseId: 'v-1',
|
|
color: 'yellow',
|
|
createdAt: Date.now(),
|
|
updatedAt: Date.now(),
|
|
syncStatus: 'pending'
|
|
}
|
|
|
|
await manager.queueHighlight(highlight)
|
|
await manager.markSyncing(['h-1'])
|
|
|
|
const syncing = await manager.getSyncingItems()
|
|
expect(syncing.length).toBe(1)
|
|
})
|
|
|
|
it('should mark highlight as synced', async () => {
|
|
const highlight: BibleHighlight = {
|
|
id: 'h-1',
|
|
verseId: 'v-1',
|
|
color: 'yellow',
|
|
createdAt: Date.now(),
|
|
updatedAt: Date.now(),
|
|
syncStatus: 'pending'
|
|
}
|
|
|
|
await manager.queueHighlight(highlight)
|
|
await manager.markSynced(['h-1'])
|
|
|
|
const pending = await manager.getPendingSyncItems()
|
|
expect(pending.length).toBe(0)
|
|
})
|
|
|
|
it('should retry sync on error', async () => {
|
|
const highlight: BibleHighlight = {
|
|
id: 'h-1',
|
|
verseId: 'v-1',
|
|
color: 'yellow',
|
|
createdAt: Date.now(),
|
|
updatedAt: Date.now(),
|
|
syncStatus: 'pending'
|
|
}
|
|
|
|
await manager.queueHighlight(highlight)
|
|
await manager.markError(['h-1'], 'Network error')
|
|
await manager.markSyncing(['h-1'])
|
|
|
|
const syncing = await manager.getSyncingItems()
|
|
expect(syncing.length).toBe(1)
|
|
})
|
|
})
|