Files
Meeting-Mixer/tests/utils.test.mjs
T
ferdi2goandClaude Opus 4.8 fd9870871b refactor: centralize shared date/name helpers in utils.js (#12)
New js/utils.js exports toISO, monthPrefix, getWeekday, formatDateDE and
buildNameMap. algorithm.js, calendar.js, excel.js and history.js now import
these instead of re-implementing ISO construction, weekday math, DD.MM.YYYY
formatting and the id→name map inline. Adds tests/utils.test.mjs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-03 13:01:28 +00:00

27 lines
1.0 KiB
JavaScript

import assert from 'node:assert/strict';
import { toISO, monthPrefix, getWeekday, formatDateDE, buildNameMap } from '../js/utils.js';
// toISO: zero-pads month and day
assert.equal(toISO(2026, 4, 1), '2026-04-01', 'toISO pads single digits');
assert.equal(toISO(2026, 12, 31), '2026-12-31', 'toISO keeps two-digit parts');
// monthPrefix: YYYY-MM
assert.equal(monthPrefix(2026, 5), '2026-05', 'monthPrefix pads month');
// getWeekday: 1=Mon … 7=Sun (2026-04-01 is a Wednesday → 3; 2026-04-05 Sunday → 7)
assert.equal(getWeekday('2026-04-01'), 3, 'Wednesday → 3');
assert.equal(getWeekday('2026-04-05'), 7, 'Sunday → 7');
assert.equal(getWeekday('2026-04-06'), 1, 'Monday → 1');
// formatDateDE: ISO → DD.MM.YYYY
assert.equal(formatDateDE('2026-04-01'), '01.04.2026', 'formatDateDE DD.MM.YYYY');
// buildNameMap: id → name lookup
assert.deepEqual(
buildNameMap([{ id: 'a', name: 'Alice' }, { id: 'b', name: 'Bob' }]),
{ a: 'Alice', b: 'Bob' },
'buildNameMap maps id to name'
);
console.log('All utils tests passed.');