mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-13 06:42:23 +00:00
test(news): take Jordan as the sample country
This commit is contained in:
1 parent
2fe0110f8d
commit
525543d08a
3 files changed
+38
-38
No files matched your search
@@ -70,13 +70,13 @@ test('without GEV_NEWS_ORIGIN Core answers itself: Conflicts from GDELT, Local s
|
|||||||
const hotspots = await call('/hotspots');
|
const hotspots = await call('/hotspots');
|
||||||
assert.equal(hotspots.status, 502);
|
assert.equal(hotspots.status, 502);
|
||||||
assert.deepEqual(hotspots.json, { error: 'news_upstream_error' });
|
assert.deepEqual(hotspots.json, { error: 'news_upstream_error' });
|
||||||
const local = await call('/feed?hotspot=all&at=51.13,71.43');
|
const local = await call('/feed?hotspot=all&at=31.95,35.93');
|
||||||
assert.equal(local.status, 503);
|
assert.equal(local.status, 503);
|
||||||
assert.deepEqual(local.json, { error: 'no_key', key: 'worldnewsapi' });
|
assert.deepEqual(local.json, { error: 'no_key', key: 'worldnewsapi' });
|
||||||
// The area is read from the bundled countries, with no key.
|
// The area is read from the bundled countries, with no key.
|
||||||
const area = await call('/outline?at=51.13,71.43&v=4');
|
const area = await call('/outline?at=31.95,35.93&v=4');
|
||||||
assert.equal(area.status, 200);
|
assert.equal(area.status, 200);
|
||||||
assert.equal(area.json.area.name, 'Kazakhstan');
|
assert.equal(area.json.area.name, 'Jordan');
|
||||||
// The client's allowlist still holds.
|
// The client's allowlist still holds.
|
||||||
assert.equal((await call('/feed?side=UA')).status, 400);
|
assert.equal((await call('/feed?side=UA')).status, 400);
|
||||||
assert.ok(hosts.length > 0);
|
assert.ok(hosts.length > 0);
|
||||||
@@ -206,7 +206,7 @@ test('a host that serves news only from its own server turns the built-in backen
|
|||||||
for (const url of [
|
for (const url of [
|
||||||
'/hotspots',
|
'/hotspots',
|
||||||
'/feed?hotspot=all',
|
'/feed?hotspot=all',
|
||||||
'/outline?at=51.13,71.43&v=4',
|
'/outline?at=31.95,35.93&v=4',
|
||||||
]) {
|
]) {
|
||||||
const answer = await call(url);
|
const answer = await call(url);
|
||||||
assert.equal(answer.status, 503, url);
|
assert.equal(answer.status, 503, url);
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ const RULES = {
|
|||||||
['president', 0.5],
|
['president', 0.5],
|
||||||
['minister', 0.5],
|
['minister', 0.5],
|
||||||
['statement', 0.5],
|
['statement', 0.5],
|
||||||
// A state visit ("King of Jordan arrives in Astana").
|
// A state visit ("Emir of Qatar arrives in Amman").
|
||||||
['visit', 0.5],
|
['visit', 0.5],
|
||||||
['delegation', 0.5],
|
['delegation', 0.5],
|
||||||
['agreement', 0.5],
|
['agreement', 0.5],
|
||||||
@@ -345,7 +345,7 @@ const RULES = {
|
|||||||
|
|
||||||
// Business, trade, industry and energy, counted only when nothing physical
|
// Business, trade, industry and energy, counted only when nothing physical
|
||||||
// happened (categorizeText): an oil depot struck is a strike. English,
|
// happened (categorizeText): an oil depot struck is a strike. English,
|
||||||
// Russian, Ukrainian, Kazakh-press Russian, Turkish and the European stems.
|
// Russian, Ukrainian, Turkish and the European stems.
|
||||||
RULES.economy = [
|
RULES.economy = [
|
||||||
'econom',
|
'econom',
|
||||||
'gdp$',
|
'gdp$',
|
||||||
|
|||||||
@@ -37,12 +37,12 @@ const LIVEUAMAP = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 102,
|
id: 102,
|
||||||
name: 'Floods kill dozens in Astana',
|
name: 'Floods kill dozens in Amman',
|
||||||
lat: '51.16940',
|
lat: '31.95390',
|
||||||
lng: '71.44910',
|
lng: '35.91060',
|
||||||
location: 'Astana',
|
location: 'Amman',
|
||||||
timestamp: seconds('2026-11-05T10:00:00Z'),
|
timestamp: seconds('2026-11-05T10:00:00Z'),
|
||||||
link: 'https://asia.liveuamap.com/en/2026/5-november-astana',
|
link: 'https://mideast.liveuamap.com/en/2026/5-november-amman',
|
||||||
img_share: '',
|
img_share: '',
|
||||||
video: '',
|
video: '',
|
||||||
},
|
},
|
||||||
@@ -83,8 +83,8 @@ const WORLD_NEWS = {
|
|||||||
news: [
|
news: [
|
||||||
{
|
{
|
||||||
id: 9001,
|
id: 9001,
|
||||||
title: 'Visiting minister arrives in Astana for talks',
|
title: 'Visiting minister arrives in Amman for talks',
|
||||||
url: 'https://www.daily.example/en/minister-astana-talks',
|
url: 'https://www.daily.example/en/minister-amman-talks',
|
||||||
image: 'https://www.daily.example/pics/visit.jpg',
|
image: 'https://www.daily.example/pics/visit.jpg',
|
||||||
publish_date: '2026-11-05 08:30:00',
|
publish_date: '2026-11-05 08:30:00',
|
||||||
language: 'en',
|
language: 'en',
|
||||||
@@ -102,7 +102,7 @@ const WORLD_NEWS = {
|
|||||||
// Sport is left out.
|
// Sport is left out.
|
||||||
{
|
{
|
||||||
id: 9004,
|
id: 9004,
|
||||||
title: 'Astana Arlan win the cup final',
|
title: 'Al-Faisaly win the cup final',
|
||||||
url: 'https://sport.example/cup',
|
url: 'https://sport.example/cup',
|
||||||
publish_date: '2026-11-05 09:00:00',
|
publish_date: '2026-11-05 09:00:00',
|
||||||
category: 'sports',
|
category: 'sports',
|
||||||
@@ -452,13 +452,13 @@ test('an export not published yet is looked for again, and the day is kept a day
|
|||||||
|
|
||||||
test('Local names the country at the point and outlines it, with no key', async () => {
|
test('Local names the country at the point and outlines it, with no key', async () => {
|
||||||
const { ask, calls } = keyed({ env: {} });
|
const { ask, calls } = keyed({ env: {} });
|
||||||
const answer = await ask('/outline', 'at=51.13,71.43&v=4');
|
const answer = await ask('/outline', 'at=31.95,35.93&v=4');
|
||||||
const outline = normalizeOutlinePayload(answer.body);
|
const outline = normalizeOutlinePayload(answer.body);
|
||||||
assert.deepEqual(outline.area, {
|
assert.deepEqual(outline.area, {
|
||||||
key: 'KZ',
|
key: 'JO',
|
||||||
name: 'Kazakhstan',
|
name: 'Jordan',
|
||||||
kind: 'country',
|
kind: 'country',
|
||||||
country: 'KZ',
|
country: 'JO',
|
||||||
});
|
});
|
||||||
assert.ok(outline.polygons.length > 0);
|
assert.ok(outline.polygons.length > 0);
|
||||||
const sea = await ask('/outline', 'at=0,-30&v=4');
|
const sea = await ask('/outline', 'at=0,-30&v=4');
|
||||||
@@ -472,12 +472,12 @@ test("Local in a country is its outlets' everyday news, pinned inside it, plus t
|
|||||||
const { ask, calls } = keyed();
|
const { ask, calls } = keyed();
|
||||||
const answer = await ask(
|
const answer = await ask(
|
||||||
'/feed',
|
'/feed',
|
||||||
'hotspot=all&geo=1&today=1&events=1&limit=40&at=51.13,71.43',
|
'hotspot=all&geo=1&today=1&events=1&limit=40&at=31.95,35.93',
|
||||||
);
|
);
|
||||||
assert.equal(answer.status, 200);
|
assert.equal(answer.status, 200);
|
||||||
const search = calls.find((c) => host(c) === 'api.worldnewsapi.com');
|
const search = calls.find((c) => host(c) === 'api.worldnewsapi.com');
|
||||||
assert.equal(search.url.pathname, '/search-news');
|
assert.equal(search.url.pathname, '/search-news');
|
||||||
assert.equal(search.url.searchParams.get('source-country'), 'kz');
|
assert.equal(search.url.searchParams.get('source-country'), 'jo');
|
||||||
assert.equal(search.url.searchParams.has('categories'), false);
|
assert.equal(search.url.searchParams.has('categories'), false);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
search.url.searchParams.get('earliest-publish-date'),
|
search.url.searchParams.get('earliest-publish-date'),
|
||||||
@@ -497,13 +497,13 @@ test("Local in a country is its outlets' everyday news, pinned inside it, plus t
|
|||||||
assert.equal(visit.publisher, 'daily.example');
|
assert.equal(visit.publisher, 'daily.example');
|
||||||
assert.equal(visit.snippet, null, 'titles and links only');
|
assert.equal(visit.snippet, null, 'titles and links only');
|
||||||
assert.equal(visit.geo.precision, 'country');
|
assert.equal(visit.geo.precision, 'country');
|
||||||
assert.equal(visit.geo.place, 'Kazakhstan');
|
assert.equal(visit.geo.place, 'Jordan');
|
||||||
assert.equal(visit.event.image.publisher, 'daily.example');
|
assert.equal(visit.event.image.publisher, 'daily.example');
|
||||||
assert.equal(exploration.category, 'economy');
|
assert.equal(exploration.category, 'economy');
|
||||||
|
|
||||||
// The point each is pinned at lies in the area Local outlines.
|
// The point each is pinned at lies in the area Local outlines.
|
||||||
const outline = normalizeOutlinePayload(
|
const outline = normalizeOutlinePayload(
|
||||||
(await ask('/outline', 'at=51.13,71.43&v=4')).body,
|
(await ask('/outline', 'at=31.95,35.93&v=4')).body,
|
||||||
);
|
);
|
||||||
const { inPolygons } = await import('../../../src/layers/news/model.js');
|
const { inPolygons } = await import('../../../src/layers/news/model.js');
|
||||||
for (const report of reports)
|
for (const report of reports)
|
||||||
@@ -555,7 +555,7 @@ test("GDELT's places are named by their town and the area there, not its old reg
|
|||||||
|
|
||||||
test("a country's news is read once per half hour and Liveuamap's feed once per five minutes", async () => {
|
test("a country's news is read once per half hour and Liveuamap's feed once per five minutes", async () => {
|
||||||
const { ask, calls, clock } = keyed();
|
const { ask, calls, clock } = keyed();
|
||||||
const local = 'hotspot=all&at=51.13,71.43';
|
const local = 'hotspot=all&at=31.95,35.93';
|
||||||
await ask('/feed', local);
|
await ask('/feed', local);
|
||||||
await ask('/feed', local);
|
await ask('/feed', local);
|
||||||
await ask('/hotspots');
|
await ask('/hotspots');
|
||||||
@@ -573,7 +573,7 @@ test("a country's news is read once per half hour and Liveuamap's feed once per
|
|||||||
|
|
||||||
test('Local without its key says which key it needs and reads nothing', async () => {
|
test('Local without its key says which key it needs and reads nothing', async () => {
|
||||||
const noLocal = keyed({ env: { LIVEUAMAP_API_KEY: 'live-key' } });
|
const noLocal = keyed({ env: { LIVEUAMAP_API_KEY: 'live-key' } });
|
||||||
assert.deepEqual(await noLocal.ask('/feed', 'at=51.13,71.43'), {
|
assert.deepEqual(await noLocal.ask('/feed', 'at=31.95,35.93'), {
|
||||||
status: 503,
|
status: 503,
|
||||||
body: { error: 'no_key', key: 'worldnewsapi' },
|
body: { error: 'no_key', key: 'worldnewsapi' },
|
||||||
});
|
});
|
||||||
@@ -589,7 +589,7 @@ test('a refused Liveuamap key leaves GDELT; World News API refusing names its ke
|
|||||||
const conflicts = await refused.ask('/hotspots');
|
const conflicts = await refused.ask('/hotspots');
|
||||||
assert.equal(conflicts.status, 200);
|
assert.equal(conflicts.status, 200);
|
||||||
assert.equal(conflicts.body.hotspots[0].counts.last24h, 4);
|
assert.equal(conflicts.body.hotspots[0].counts.last24h, 4);
|
||||||
assert.deepEqual(await refused.ask('/feed', 'at=51.13,71.43'), {
|
assert.deepEqual(await refused.ask('/feed', 'at=31.95,35.93'), {
|
||||||
status: 503,
|
status: 503,
|
||||||
body: { error: 'key_rejected', key: 'worldnewsapi' },
|
body: { error: 'key_rejected', key: 'worldnewsapi' },
|
||||||
});
|
});
|
||||||
@@ -766,10 +766,10 @@ test('Local where only Conflicts reports speak answers 502 when they fail; in a
|
|||||||
UPSTREAM_ERROR,
|
UPSTREAM_ERROR,
|
||||||
);
|
);
|
||||||
assert.equal(count(calls, 'api.worldnewsapi.com'), 0);
|
assert.equal(count(calls, 'api.worldnewsapi.com'), 0);
|
||||||
const kazakhstan = await ask('/feed', 'hotspot=all&at=51.13,71.43');
|
const jordan = await ask('/feed', 'hotspot=all&at=31.95,35.93');
|
||||||
assert.equal(kazakhstan.status, 200);
|
assert.equal(jordan.status, 200);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
kazakhstan.body.reports.map((r) => r.id),
|
jordan.body.reports.map((r) => r.id),
|
||||||
['wna-9001', 'wna-9002'],
|
['wna-9001', 'wna-9002'],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -809,7 +809,7 @@ test('a territory without a code is named as itself, not read as sea', async ()
|
|||||||
test('a stale Liveuamap or World News API read is served while it is read again', async () => {
|
test('a stale Liveuamap or World News API read is served while it is read again', async () => {
|
||||||
const answers = {};
|
const answers = {};
|
||||||
const { ask, calls, clock, settle } = keyed({ answers });
|
const { ask, calls, clock, settle } = keyed({ answers });
|
||||||
const local = 'hotspot=all&at=51.13,71.43';
|
const local = 'hotspot=all&at=31.95,35.93';
|
||||||
const ids = (answer) => answer.body.reports.map((r) => r.id);
|
const ids = (answer) => answer.body.reports.map((r) => r.id);
|
||||||
assert.deepEqual(ids(await ask('/feed', local)), [
|
assert.deepEqual(ids(await ask('/feed', local)), [
|
||||||
'lum-102',
|
'lum-102',
|
||||||
@@ -877,14 +877,14 @@ test("World News API's reads are a daily budget: spent, Local says key_quota and
|
|||||||
env: { WORLDNEWSAPI_KEY: 'wna-key', WORLDNEWSAPI_DAILY_READS: '2' },
|
env: { WORLDNEWSAPI_KEY: 'wna-key', WORLDNEWSAPI_DAILY_READS: '2' },
|
||||||
});
|
});
|
||||||
const at = (point) => ask('/feed', `hotspot=all&at=${point}`);
|
const at = (point) => ask('/feed', `hotspot=all&at=${point}`);
|
||||||
assert.equal((await at('51.13,71.43')).status, 200);
|
assert.equal((await at('31.95,35.93')).status, 200);
|
||||||
assert.equal((await at('48.85,2.35')).status, 200);
|
assert.equal((await at('48.85,2.35')).status, 200);
|
||||||
// Germany would be the third read today.
|
// Germany would be the third read today.
|
||||||
assert.deepEqual(await at('52.52,13.4'), KEY_QUOTA);
|
assert.deepEqual(await at('52.52,13.4'), KEY_QUOTA);
|
||||||
assert.equal(count(calls, 'api.worldnewsapi.com'), 2);
|
assert.equal(count(calls, 'api.worldnewsapi.com'), 2);
|
||||||
// Kazakhstan, read earlier, is served from what was read.
|
// Jordan, read earlier, is served from what was read.
|
||||||
clock.now += 31 * MINUTE;
|
clock.now += 31 * MINUTE;
|
||||||
const kept = await at('51.13,71.43');
|
const kept = await at('31.95,35.93');
|
||||||
assert.equal(kept.status, 200);
|
assert.equal(kept.status, 200);
|
||||||
assert.equal(kept.body.reports.length, 2);
|
assert.equal(kept.body.reports.length, 2);
|
||||||
assert.equal(count(calls, 'api.worldnewsapi.com'), 2);
|
assert.equal(count(calls, 'api.worldnewsapi.com'), 2);
|
||||||
@@ -901,13 +901,13 @@ test("World News API's reads are a daily budget: spent, Local says key_quota and
|
|||||||
|
|
||||||
test('World News API answering 402 is key_quota, and nothing more is asked today; a 429 is no quota', async () => {
|
test('World News API answering 402 is key_quota, and nothing more is asked today; a 429 is no quota', async () => {
|
||||||
const paid = keyed({ answers: { worldnews: 402 } });
|
const paid = keyed({ answers: { worldnews: 402 } });
|
||||||
assert.deepEqual(await paid.ask('/feed', 'at=51.13,71.43'), KEY_QUOTA);
|
assert.deepEqual(await paid.ask('/feed', 'at=31.95,35.93'), KEY_QUOTA);
|
||||||
paid.clock.now += 2 * MINUTE;
|
paid.clock.now += 2 * MINUTE;
|
||||||
assert.deepEqual(await paid.ask('/feed', 'at=48.85,2.35'), KEY_QUOTA);
|
assert.deepEqual(await paid.ask('/feed', 'at=48.85,2.35'), KEY_QUOTA);
|
||||||
assert.equal(count(paid.calls, 'api.worldnewsapi.com'), 1);
|
assert.equal(count(paid.calls, 'api.worldnewsapi.com'), 1);
|
||||||
// A 429 is its per-second limit: an ordinary failure, tried again soon.
|
// A 429 is its per-second limit: an ordinary failure, tried again soon.
|
||||||
const busy = keyed({ answers: { worldnews: 429 } });
|
const busy = keyed({ answers: { worldnews: 429 } });
|
||||||
assert.deepEqual(await busy.ask('/feed', 'at=51.13,71.43'), UPSTREAM_ERROR);
|
assert.deepEqual(await busy.ask('/feed', 'at=31.95,35.93'), UPSTREAM_ERROR);
|
||||||
await paid.settle();
|
await paid.settle();
|
||||||
await busy.settle();
|
await busy.settle();
|
||||||
});
|
});
|
||||||
@@ -965,7 +965,7 @@ test('a town a disputed area is named after is named as the town alone', () => {
|
|||||||
test('World News API is credited on each of its reports', async () => {
|
test('World News API is credited on each of its reports', async () => {
|
||||||
const { ask, settle } = keyed();
|
const { ask, settle } = keyed();
|
||||||
const { reports } = normalizeFeedPayload(
|
const { reports } = normalizeFeedPayload(
|
||||||
(await ask('/feed', 'hotspot=all&at=51.13,71.43')).body,
|
(await ask('/feed', 'hotspot=all&at=31.95,35.93')).body,
|
||||||
);
|
);
|
||||||
const national = reports.filter((r) => r.kind === 'worldnewsapi');
|
const national = reports.filter((r) => r.kind === 'worldnewsapi');
|
||||||
assert.ok(national.length > 0);
|
assert.ok(national.length > 0);
|
||||||
@@ -1056,7 +1056,7 @@ test('a failing file gets one strike a round, not three within seconds', async (
|
|||||||
test("a country's own news keeps World News API's category and no severity, whatever its words", async () => {
|
test("a country's own news keeps World News API's category and no severity, whatever its words", async () => {
|
||||||
const { worldNewsReport } = await import('./keyed.js');
|
const { worldNewsReport } = await import('./keyed.js');
|
||||||
const { countryByCode } = await import('./areas.js');
|
const { countryByCode } = await import('./areas.js');
|
||||||
const country = countryByCode('KZ');
|
const country = countryByCode('JO');
|
||||||
const read = (title, category) =>
|
const read = (title, category) =>
|
||||||
worldNewsReport(
|
worldNewsReport(
|
||||||
{
|
{
|
||||||
@@ -1070,7 +1070,7 @@ test("a country's own news keeps World News API's category and no severity, what
|
|||||||
country,
|
country,
|
||||||
);
|
);
|
||||||
const rankings = read(
|
const rankings = read(
|
||||||
'Kazakhstan Advances in Global Digital Rankings as AI Infrastructure Expands',
|
'Jordan Advances in Global Digital Rankings as AI Infrastructure Expands',
|
||||||
'technology',
|
'technology',
|
||||||
);
|
);
|
||||||
assert.equal(rankings.category, 'other');
|
assert.equal(rankings.category, 'other');
|
||||||
@@ -1079,6 +1079,6 @@ test("a country's own news keeps World News API's category and no severity, what
|
|||||||
read('Startup advances to the next funding round', 'business').category,
|
read('Startup advances to the next funding round', 'business').category,
|
||||||
'economy',
|
'economy',
|
||||||
);
|
);
|
||||||
assert.equal(read('King visits Astana', 'politics').category, 'political');
|
assert.equal(read('King visits Amman', 'politics').category, 'political');
|
||||||
assert.equal(read('Parliament session opens', null).category, 'other');
|
assert.equal(read('Parliament session opens', null).category, 'other');
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user