feat(sources): retire Yahoo and CNBC feeds (#42)

This commit is contained in:
2026-11-25 02:00:25 +01:00
parent 7a342f240d
commit 0503c2653f
41 changed files with 603 additions and 173 deletions

View File

@ -0,0 +1,80 @@
import { cleanup, render, screen, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
import { Sources } from '../src/pages/admin/Sources'
import { GenerationDetails } from '../src/components/GenerationDetails'
import type { GenerationOutcome } from '../src/api/summaries'
const { listSources, listSettings, updateSource, updateSettings, updateSourceFeeds } = vi.hoisted(() => ({
listSources: vi.fn(), listSettings: vi.fn(), updateSource: vi.fn(), updateSettings: vi.fn(), updateSourceFeeds: vi.fn(),
}))
vi.mock('@/api/admin', () => ({ adminApi: { listSources, listSettings, updateSource, updateSettings, updateSourceFeeds } }))
const sources = [
{ id: 'b', source_key: 'bloomberg', name: 'Bloomberg', type: 'rss', supported: true, operational: true, enabled: true, article_limit: 20, feed_urls: ['https://feed.quanwenrss.com/feed/bloomberg-latest.xml'] },
{ id: 'i', source_key: 'investing_com', name: 'Investing.com', type: 'rss', supported: true, operational: false, enabled: false, article_limit: 40, feed_urls: ['https://feed.quanwenrss.com/feed/investing-news.xml'] },
{ id: 'y', source_key: 'yahoo_finance', name: 'Stocktwits', type: 'stocktwits', supported: false, operational: false, enabled: false, article_limit: 83 },
{ id: 'c', source_key: 'cnbc_business', name: 'legacy', type: 'cnbc_business', supported: false, operational: false, enabled: false, article_limit: 37 },
]
beforeEach(() => {
vi.clearAllMocks()
listSources.mockResolvedValue(sources)
listSettings.mockResolvedValue([{ key: 'summary_max_articles', value: '50' }])
updateSource.mockResolvedValue(undefined); updateSettings.mockResolvedValue(undefined); updateSourceFeeds.mockResolvedValue(undefined)
})
afterEach(cleanup)
it('ne propose que les deux sources RSS configurables et conserve leurs plafonds, flux et activation', async () => {
render(<Sources />)
await screen.findByRole('heading', { name: 'Bloomberg' })
expect(screen.getAllByRole('button', { name: /^(Activer|Désactiver) / })).toHaveLength(2)
for (const name of ['Bloomberg', 'Investing.com']) {
expect(screen.getByLabelText(`Plafond ${name}`)).toBeInTheDocument()
expect(screen.getByRole('form', { name: `Flux RSS ${name}` })).toBeInTheDocument()
}
expect(screen.getByLabelText('Articles max par résumé')).toHaveValue(50)
expect(screen.getByText(/Seules Bloomberg et Investing.com/)).toBeInTheDocument()
})
it('présente Yahoo/CNBC dans Sources retirées repliée et en lecture seule, avec leurs anciens plafonds', async () => {
const before = JSON.stringify(sources)
render(<Sources />)
const region = await screen.findByRole('region', { name: 'Sources retirées' })
const details = region.querySelector('details')!
expect(details).not.toHaveAttribute('open')
await userEvent.click(within(region).getByText('Consulter les sources retirées (2)'))
expect(details).toHaveAttribute('open')
expect(within(region).getByText('Yahoo Finance')).toBeVisible()
expect(within(region).getByText('CNBC Business')).toBeVisible()
expect(within(region).getByText('Exclue des synthèses · Plafond historique : 83')).toBeVisible()
expect(within(region).getByText('Exclue des synthèses · Plafond historique : 37')).toBeVisible()
expect(region.querySelectorAll('button,input,select,form,a')).toHaveLength(0)
expect(screen.queryByLabelText('Plafond Yahoo Finance')).not.toBeInTheDocument()
expect(screen.queryByLabelText('Plafond CNBC Business')).not.toBeInTheDocument()
expect(screen.queryByText('Stocktwits')).not.toBeInTheDocument()
expect(updateSource).not.toHaveBeenCalled()
expect(updateSettings).not.toHaveBeenCalled()
expect(updateSourceFeeds).not.toHaveBeenCalled()
expect(JSON.stringify(sources)).toBe(before)
})
it('ne réactive pas Yahoo/CNBC même avec un ancien DTO déclarant ces lignes activées et prises en charge', async () => {
listSources.mockResolvedValue(sources.map(source => ({ ...source, enabled: true, supported: true, operational: true })))
render(<Sources />)
await screen.findByRole('heading', { name: 'Bloomberg' })
expect(screen.queryByRole('button', { name: /^(Activer|Désactiver) (Yahoo Finance|CNBC Business)$/ })).not.toBeInTheDocument()
expect(screen.queryByRole('form', { name: /Réglages de (Yahoo Finance|CNBC Business)/ })).not.toBeInTheDocument()
const retired = screen.getByRole('region', { name: 'Sources retirées' })
expect(within(retired).getByText('Yahoo Finance')).toBeInTheDocument()
expect(within(retired).getByText('CNBC Business')).toBeInTheDocument()
})
it.each([['yahoo_finance', 'Yahoo Finance'], ['cnbc_business', 'CNBC Business']])('conserve le libellé du bilan historique %s et ses agrégats', (source_key, name) => {
const outcome: GenerationOutcome = { id: 'historic', status: 'partial', language: 'fr', ranking_mode: 'title', total_candidates: 4, selected: 2, laya_selected: 2, content_fallbacks: 0, global_limit: 50,
source_stats: [{ source_id: 'old', source_key, source_type: 'stocktwits', status: 'failed', candidates: 4, selected: 2, laya_selected: 2, article_limit: 83, content_fallbacks: 0 }] }
const before = JSON.stringify(outcome)
render(<GenerationDetails outcome={outcome} />)
expect(screen.getByText(`Cette synthèse a été générée sans ${name}, indisponible lors du traitement.`)).toBeInTheDocument()
expect(screen.getByText(name, { exact: true })).toBeInTheDocument()
expect(screen.getByText('4 articles examinés · 2 sélectionnés par Laya · 2 retenus après plafonds')).toBeInTheDocument()
expect(JSON.stringify(outcome)).toBe(before)
})