feat: create highlight sync manager with queue logic
Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
79
__tests__/lib/highlight-sync-manager.test.ts
Normal file
79
__tests__/lib/highlight-sync-manager.test.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user