fix(scraper): verify complete article evidence (#40)
This commit is contained in:
31
scraper-service/tests/completeness-ticket40.test.js
Normal file
31
scraper-service/tests/completeness-ticket40.test.js
Normal file
@ -0,0 +1,31 @@
|
||||
const { test } = require('node:test')
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const { extractArticle } = require('../article-content')
|
||||
const url = 'https://www.bloomberg.com/news/articles/fixture'
|
||||
const full = `<link rel="canonical" href="${url}"><article class="articleLayout_basic__gcpQk"><div class="body-content"><p class="ArticleBodyText_articleBodyContent__17wqE">Synthetic first paragraph.</p><p class="ArticleBodyText_articleBodyContent__17wqE">Synthetic final paragraph.</p></div></article>`
|
||||
test('ticket40 GiftArticle with nineteen placeholders never claims complete', () => {
|
||||
const raw = fs.readFileSync(path.join(__dirname, 'fixtures/content-gift-placeholders.html'), 'utf8').replace('</div></article>', '<div class="Placeholder_placeholder__fixture"></div>'.repeat(18) + '</div></article>')
|
||||
assert.equal((raw.match(/Placeholder_placeholder__fixture/g) || []).length, 19)
|
||||
const a = extractArticle(raw, url)
|
||||
assert.equal(a.content_state, 'incomplete')
|
||||
assert.ok(!a.content.includes('Placeholder'))
|
||||
})
|
||||
test('ticket40 completeness requires article identity, a known root and no missing-body markers', () => {
|
||||
assert.equal(extractArticle(full, url).content_state, 'complete')
|
||||
for (const marker of ['<div class="GiftArticle_teaser"></div>', '<div class="Placeholder_placeholder__x"></div>', '<div id="px-captcha"></div>', '<div class="paywall"></div>']) {
|
||||
const raw = full.replace('</div></article>', marker + '</div></article>')
|
||||
assert.equal(extractArticle(raw, url).content_state, 'incomplete')
|
||||
}
|
||||
assert.equal(extractArticle(full.replace(url, url + '-other'), url).content_state, 'unavailable')
|
||||
assert.notEqual(extractArticle(full.replace(/<link[^>]+>/, ''), url).content_state, 'complete')
|
||||
assert.equal(extractArticle('<div id="px-captcha">challenge</div>', url).content_state, 'unavailable')
|
||||
assert.equal(extractArticle(full.replace('body-content', 'unknown-root'), url).content_state, 'unavailable')
|
||||
})
|
||||
|
||||
test('ticket40 hidden or recommendation roots are not the requested visible editorial body', () => {
|
||||
for (const html of [full.replace('class="body-content"', 'class="body-content" hidden'), `<aside>${full}</aside>`]) {
|
||||
assert.notEqual(extractArticle(html, url).content_state, 'complete')
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user