Add automatic Threads link replies and sunrise preview card

This commit is contained in:
2026-11-02 04:46:17 +09:00
parent 39374cea05
commit 586e59608e
12 changed files with 168 additions and 8 deletions
+19 -1
View File
@@ -2,7 +2,25 @@ import { test } from 'node:test';
import assert from 'node:assert/strict';
import { calculateSun } from '../src/astronomy/sunCalculator.ts';
import { observer } from '../src/config/observer.ts';
import { dailySchedule, publishImage, publishCarousel } from '../server/threads/publisher.ts';
import { dailySchedule, publishImage, publishCarousel, publishReply } from '../server/threads/publisher.ts';
test('reply targets the published parent and attaches a preview link, claiming before publish', async () => {
const replies = [{ id: 'reply-container' }, { status: 'FINISHED' }, { id: 'reply' }];
let claimed = false;
const id = await publishReply('token', 'parent-post', 'Visit us', 'https://sunrise.horoli.kr', async () => {
claimed = true;
}, async (url, init) => {
const params = init?.body as URLSearchParams;
if (String(url).endsWith('/me/threads')) {
assert.equal(params.get('reply_to_id'), 'parent-post');
assert.equal(params.get('link_attachment'), 'https://sunrise.horoli.kr');
assert.equal(params.get('media_type'), 'TEXT');
}
if (String(url).endsWith('/me/threads_publish')) assert.ok(claimed);
return new Response(JSON.stringify(replies.shift()));
}, async () => {});
assert.equal(id, 'reply');
});
test('schedule uses the Korean date and existing SunCalc sunrise', () => {
const now = new Date('2026-11-01T18:00:00Z');