35 lines
2.1 KiB
TypeScript
35 lines
2.1 KiB
TypeScript
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('default post shows sunrise time rather than the five-minute-later capture time', () => {
|
|
const config = loadCaptions(new URL('../.threads-captions.sample.json', import.meta.url));
|
|
const result = renderCaption(config, { weather: { ...sample, cloudCover: 90 }, capturedAt: '2026-11-01T21:58:00Z',
|
|
sunrise: '2026-11-01T21:53:00Z', url: 'https://sunrise.horoli.kr', test: false });
|
|
assert.equal(result.text, '오늘의 관악산 일출이에요\n2026.11.02 · 일출 06:53\n날씨: 흐림\nsunrise.horoli.kr');
|
|
});
|
|
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');
|
|
});
|