import { test } from 'node:test'; import assert from 'node:assert/strict'; import { loadCaptions, weatherKey, renderCaption } from '../server/threads/captions.ts'; const sample = { cloudCover: 10, visibility: 10000, rain: 0, snowfall: 0 }; test('caption weather uses precipitation first and does not assume missing data means clear', () => { const config = loadCaptions(); assert.equal(weatherKey({ ...sample, rain: 1, snowfall: 1 }, config), 'snow'); assert.equal(weatherKey({ ...sample, rain: 1, visibility: 100 }, config), 'rain'); assert.equal(weatherKey({ ...sample, visibility: 500 }, config), 'fog'); assert.equal(weatherKey({ ...sample, cloudCover: 90 }, config), 'cloudy'); assert.equal(weatherKey({ ...sample, cloudCover: 50 }, config), 'partlyCloudy'); assert.equal(weatherKey(sample, config), 'clear'); assert.equal(weatherKey(null, config), 'unknown'); assert.equal(weatherKey({ ...sample, rain: null }, config), 'unknown'); }); test('editable caption expands Korean date/time and test marker without publishing', () => { const config = loadCaptions(); config.template = ['{message}', '{date} {time} / {sunrise}', '{url}']; config.messages.rain = ['비 오는 날이야 ☔']; const result = renderCaption(config, { weather: { ...sample, rain: 1 }, capturedAt: '2026-11-01T18:00:00Z', sunrise: '2026-11-01T21:53:00Z', url: 'https://sunrise.horoli.kr', test: true }); assert.ok(result.text.includes('비 오는 날이야 ☔')); assert.ok(result.text.includes('2026-11-02 03:00 / 06:53')); assert.ok(result.text.startsWith(config.testPrefix)); assert.equal(result.condition, 'rain'); });