import { expect, test } from 'vitest'; import { isSaveConflict, parseBase } from './projectSync.js'; test('a save is fine when the server copy is no newer than what the device last saw', () => { expect(isSaveConflict({ stored: 100, base: 100 })).toBe(false); expect(isSaveConflict({ stored: 90, base: 100 })).toBe(false); }); test('a save conflicts when another device saved after the one this device last saw', () => { expect(isSaveConflict({ stored: 200, base: 100 })).toBe(true); }); test('first saves, unknown bases and "keep mine" never conflict', () => { expect(isSaveConflict({ stored: null, base: 100 })).toBe(false); expect(isSaveConflict({ stored: 200, base: null })).toBe(false); expect(isSaveConflict({ stored: 200, base: 100, force: true })).toBe(false); }); test('reads the base header', () => { expect(parseBase('1700000000000')).toBe(1700000000000); expect(parseBase('')).toBeNull(); expect(parseBase(undefined)).toBeNull(); expect(parseBase('abc')).toBeNull(); });