55 lines
3.2 KiB
TypeScript
55 lines
3.2 KiB
TypeScript
/**
|
|
* news-sources.ts 파서 — 비공식 출처라 형식이 말없이 바뀐다. 조용히 0건이 되는 게 가장 나쁜 실패라
|
|
* 실제 응답 모양(2026-10-24 채취)으로 고정해 둔다.
|
|
*/
|
|
import { test, describe } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { parseGoogleNewsRss, parseSearxngNews, parseDdgNews, languageForCountry, hasGoogleNewsLocale } from '../src/tools/news-sources';
|
|
|
|
const GOOGLE_ITEM = `<rss><channel><item><title>改正皇室典範 きょう施行 - NHKニュース</title><link>https://news.google.com/rss/articles/AAA?oc=5</link><pubDate>Fri, 23 Oct 2026 20:00:08 GMT</pubDate><description><ol><li><a href="https://news.google.com/rss/articles/AAA" target="_blank">改正皇室典範 きょう施行</a>&nbsp;&nbsp;<font color="#6f6f6f">NHKニュース</font></li><li><a href="https://news.google.com/rss/articles/BBB" target="_blank">女性皇族の身分保持へ</a>&nbsp;&nbsp;<font color="#6f6f6f">読売新聞</font></li></ol></description><source url="https://www3.nhk.or.jp">NHKニュース</source></item></channel></rss>`;
|
|
|
|
describe('parseGoogleNewsRss', () => {
|
|
test('splits outlet off the title, keeps date, uses other outlets as related coverage', () => {
|
|
const [h] = parseGoogleNewsRss(GOOGLE_ITEM);
|
|
assert.equal(h.title, '改正皇室典範 きょう施行');
|
|
assert.equal(h.source, 'NHKニュース');
|
|
assert.equal(h.published, 'Fri, 23 Oct 2026 20:00:08 GMT');
|
|
assert.equal(h.summary, '관련 보도: 女性皇族の身分保持へ (読売新聞)');
|
|
});
|
|
test('garbage → []', () => assert.deepEqual(parseGoogleNewsRss('<html>blocked</html>'), []));
|
|
});
|
|
|
|
describe('parseSearxngNews', () => {
|
|
test('dedupes the same story from naver and bing, strips tags', () => {
|
|
const out = parseSearxngNews({ results: [
|
|
{ title: '무라카미 류 별세', url: 'https://www.hani.co.kr/a/1', content: '<b>무라카미</b> 류가 74세로', engines: ['naver news'] },
|
|
{ title: '무라카미 류 별세', url: 'https://n.news.naver.com/2', content: 'x', engines: ['bing news'] },
|
|
{ title: '', url: 'https://x' },
|
|
] });
|
|
assert.equal(out.length, 1);
|
|
assert.equal(out[0].source, 'hani.co.kr');
|
|
assert.equal(out[0].summary, '무라카미 류가 74세로');
|
|
});
|
|
});
|
|
|
|
describe('parseDdgNews', () => {
|
|
test('maps excerpt/source/unix date', () => {
|
|
const [h] = parseDdgNews({ results: [{ title: "'한없이 투명에 가까운 블루' 무라카미 류 별세", url: 'https://news1.kr/1', source: '뉴스1', excerpt: '<b>무라카미</b> 류가 지난 17일', date: 1792800000 }] });
|
|
assert.equal(h.source, '뉴스1');
|
|
assert.equal(h.summary, '무라카미 류가 지난 17일');
|
|
assert.equal(h.published, new Date(1792800000 * 1000).toISOString());
|
|
});
|
|
});
|
|
|
|
describe('locales', () => {
|
|
test('country → searxng language', () => {
|
|
assert.equal(languageForCountry('jp'), 'ja');
|
|
assert.equal(languageForCountry('br,ar'), 'pt');
|
|
assert.equal(languageForCountry('xx'), '');
|
|
});
|
|
test('multi-country with any known locale counts', () => {
|
|
assert.equal(hasGoogleNewsLocale('qa,jp'), true);
|
|
assert.equal(hasGoogleNewsLocale(''), false);
|
|
});
|
|
});
|