// Тесты слияния и очистки прогресса (запуск: node --test tests/) 'use strict'; const test = require('node:test'); const assert = require('node:assert/strict'); const { sanitize, merge, pick, emptyState } = require('../public/sync.js'); const row = (t, over = {}) => ({ t, id: 'ru-A1', k: 'lesson', lang: 'ru', cpm: 100, acc: 95, err: 1, len: 60, sec: 30, ...over }); const state = (over = {}) => ({ progress: {}, history: [], keys: { ru: {}, en: {} }, ...over }); test('emptyState has the expected shape', () => { assert.deepEqual(emptyState(), { progress: {}, history: [], keys: { ru: {}, en: {} } }); }); test('sanitize: garbage input gives an empty state', () => { for (const bad of [null, undefined, 5, 'x', [], true]) assert.deepEqual(sanitize(bad), emptyState()); }); test('sanitize: drops unknown fields and coerces numbers', () => { const out = sanitize({ evil: '