Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import { resolveConflict } from '@/lib/sync-conflict-resolver'
|
|
import { BibleHighlight } from '@/types'
|
|
|
|
describe('SyncConflictResolver', () => {
|
|
it('should prefer server version if newer', () => {
|
|
const clientVersion: BibleHighlight = {
|
|
id: 'h-1',
|
|
verseId: 'v-1',
|
|
color: 'yellow',
|
|
createdAt: 1000,
|
|
updatedAt: 1000,
|
|
syncStatus: 'pending'
|
|
}
|
|
|
|
const serverVersion: BibleHighlight = {
|
|
id: 'h-1',
|
|
verseId: 'v-1',
|
|
color: 'blue',
|
|
createdAt: 1000,
|
|
updatedAt: 2000, // newer
|
|
syncStatus: 'synced'
|
|
}
|
|
|
|
const result = resolveConflict(clientVersion, serverVersion)
|
|
expect(result.color).toBe('blue')
|
|
expect(result.updatedAt).toBe(2000)
|
|
})
|
|
|
|
it('should prefer client version if newer', () => {
|
|
const clientVersion: BibleHighlight = {
|
|
id: 'h-1',
|
|
verseId: 'v-1',
|
|
color: 'blue',
|
|
createdAt: 1000,
|
|
updatedAt: 3000, // newer
|
|
syncStatus: 'pending'
|
|
}
|
|
|
|
const serverVersion: BibleHighlight = {
|
|
id: 'h-1',
|
|
verseId: 'v-1',
|
|
color: 'yellow',
|
|
createdAt: 1000,
|
|
updatedAt: 2000,
|
|
syncStatus: 'synced'
|
|
}
|
|
|
|
const result = resolveConflict(clientVersion, serverVersion)
|
|
expect(result.color).toBe('blue')
|
|
expect(result.updatedAt).toBe(3000)
|
|
})
|
|
|
|
it('should mark as synced after resolution', () => {
|
|
const clientVersion: BibleHighlight = {
|
|
id: 'h-1',
|
|
verseId: 'v-1',
|
|
color: 'yellow',
|
|
createdAt: 1000,
|
|
updatedAt: 2000,
|
|
syncStatus: 'pending'
|
|
}
|
|
|
|
const serverVersion: BibleHighlight = {
|
|
id: 'h-1',
|
|
verseId: 'v-1',
|
|
color: 'yellow',
|
|
createdAt: 1000,
|
|
updatedAt: 2000,
|
|
syncStatus: 'synced'
|
|
}
|
|
|
|
const result = resolveConflict(clientVersion, serverVersion)
|
|
expect(result.syncStatus).toBe('synced')
|
|
})
|
|
})
|