feat(sources): add managed RSS feeds (#41)
This commit is contained in:
@ -38,3 +38,11 @@ it('envoie les plafonds via les endpoints admin et préserve le plafond lors du
|
||||
method: 'PUT', body: JSON.stringify({ enabled: false }),
|
||||
}))
|
||||
})
|
||||
|
||||
it('remplace les flux RSS par PUT sans modifier le plafond et sans appeler les feeds', async () => {
|
||||
const urls = ['https://feed.quanwenrss.com/feed/bloomberg-latest.xml']
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ data: { ok: true } }), { status: 200 }))
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
await adminApi.updateSourceFeeds('source-b', false, urls)
|
||||
expect(fetchMock).toHaveBeenCalledExactlyOnceWith('/api/admin/sources/source-b', expect.objectContaining({ method: 'PUT', body: JSON.stringify({ enabled: false, feed_urls: urls }) }))
|
||||
})
|
||||
|
||||
@ -244,7 +244,27 @@ describe('plafonds d’articles administrateur', () => {
|
||||
await waitFor(() => expect(updateSource).toHaveBeenCalledWith('cnbc-new', true, 42))
|
||||
expect(updateSource).toHaveBeenCalledTimes(1)
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Plafond CNBC Business enregistré pour les prochaines synthèses.')
|
||||
expect(screen.getByText(/Seules Yahoo Finance, Bloomberg et CNBC Business/)).toBeInTheDocument()
|
||||
expect(screen.getByText(/Yahoo Finance, Bloomberg, CNBC Business et Investing.com/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('ticket #41 — sources additives', () => {
|
||||
afterEach(cleanup)
|
||||
it('affiche Investing.com depuis la clé canonique backend et conserve Yahoo Finance et CNBC Business', async () => {
|
||||
listSettings.mockResolvedValue([])
|
||||
listSources.mockResolvedValue([
|
||||
{ id: 'b', source_key: 'bloomberg', name: 'Bloomberg', type: 'rss', supported: true, operational: true, enabled: true, article_limit: 20 },
|
||||
{ id: 'i', source_key: 'investing_com', name: 'Legacy RSS label', type: 'rss', supported: true, operational: false, enabled: false, article_limit: 40 },
|
||||
{ id: 'y', source_key: 'yahoo_finance', name: 'legacy', type: 'stocktwits', supported: true, operational: true, enabled: true, article_limit: 20 },
|
||||
{ id: 'c', source_key: 'cnbc_business', name: 'legacy', type: 'rss', supported: true, operational: true, enabled: true, article_limit: 20 },
|
||||
])
|
||||
render(<Sources />)
|
||||
expect(await screen.findByRole('heading', { name: 'Investing.com' })).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Plafond Investing.com')).toHaveValue(40)
|
||||
expect(screen.getByRole('button', { name: 'Activer Investing.com' })).toBeEnabled()
|
||||
expect(screen.getByRole('button', { name: 'Désactiver Yahoo Finance' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Désactiver CNBC Business' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('heading', { name: 'Legacy RSS label' })).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
72
frontend/tests/admin-source-feeds-ticket41.test.tsx
Normal file
72
frontend/tests/admin-source-feeds-ticket41.test.tsx
Normal file
@ -0,0 +1,72 @@
|
||||
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'
|
||||
|
||||
const latest = 'https://feed.quanwenrss.com/feed/bloomberg-latest.xml'
|
||||
const economics = 'https://feed.quanwenrss.com/feed/bloomberg-economics.xml'
|
||||
const investing = 'https://feed.quanwenrss.com/feed/investing-news.xml'
|
||||
const fetchMock = vi.fn()
|
||||
let sources: object[]
|
||||
beforeEach(() => {
|
||||
sources = [
|
||||
{ id: 'b', source_key: 'bloomberg', name: 'Bloomberg', supported: true, operational: true, enabled: true, article_limit: 20, feed_urls: [latest] },
|
||||
{ id: 'i', source_key: 'investing_com', name: 'Investing.com', supported: true, operational: false, enabled: false, article_limit: 40, feed_urls: [investing] },
|
||||
]
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
fetchMock.mockReset().mockImplementation((url: string) => Promise.resolve(new Response(JSON.stringify({ data: url === '/api/admin/sources' ? sources : [] }), { status: 200 })))
|
||||
})
|
||||
afterEach(() => { cleanup(); vi.unstubAllGlobals() })
|
||||
|
||||
it('charge et sauvegarde plusieurs flux Bloomberg sans déclencher de récupération ni génération', async () => {
|
||||
render(<Sources />)
|
||||
const form = await screen.findByRole('form', { name: 'Flux RSS Bloomberg' })
|
||||
await userEvent.click(within(form).getByRole('button', { name: 'Ajouter un flux RSS Bloomberg' }))
|
||||
await userEvent.type(within(form).getByLabelText('URL du flux RSS Bloomberg 2'), economics)
|
||||
await userEvent.click(within(form).getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(fetchMock).toHaveBeenLastCalledWith('/api/admin/sources/b', expect.objectContaining({ method: 'PUT', body: JSON.stringify({ enabled: true, feed_urls: [latest, economics] }) }))
|
||||
expect(within(form).getByRole('status')).toHaveTextContent('Aucune récupération ni génération n’a été lancée.')
|
||||
expect(fetchMock).toHaveBeenCalledTimes(3)
|
||||
})
|
||||
|
||||
it('enregistre les flux d’une source désactivée sans l’activer et sans modifier son plafond', async () => {
|
||||
render(<Sources />)
|
||||
const form = await screen.findByRole('form', { name: 'Flux RSS Investing.com' })
|
||||
expect(within(form).getByLabelText('URL du flux RSS Investing.com 1')).toHaveValue(investing)
|
||||
await userEvent.click(within(form).getByRole('button', { name: 'Enregistrer les flux RSS Investing.com' }))
|
||||
expect(fetchMock).toHaveBeenLastCalledWith('/api/admin/sources/i', expect.objectContaining({ method: 'PUT', body: JSON.stringify({ enabled: false, feed_urls: [investing] }) }))
|
||||
expect(screen.getByRole('button', { name: 'Activer Investing.com' })).toBeEnabled()
|
||||
expect(screen.getByLabelText('Plafond Investing.com')).toHaveValue(40)
|
||||
})
|
||||
|
||||
it('ne propose pas de configuration supposée quand le DTO ne fournit pas de feeds', async () => {
|
||||
sources = [{ id: 'b', source_key: 'bloomberg', name: 'Bloomberg', supported: true, operational: true, enabled: true, article_limit: 20 }]
|
||||
render(<Sources />)
|
||||
await screen.findByRole('heading', { name: 'Bloomberg' })
|
||||
expect(screen.queryByRole('form', { name: 'Flux RSS Bloomberg' })).not.toBeInTheDocument()
|
||||
expect(screen.getByText(/Configuration des flux RSS indisponible/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('relie les rejets de validation serveur à un message assaini et conserve les saisies', async () => {
|
||||
render(<Sources />)
|
||||
const form = await screen.findByRole('form', { name: 'Flux RSS Bloomberg' })
|
||||
fetchMock.mockResolvedValueOnce(new Response(JSON.stringify({ error: 'source_feeds_invalid', url: 'PRIVATE_URL', content: 'PRIVATE_CONTENT' }), { status: 400 }))
|
||||
await userEvent.click(within(form).getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(within(form).getByRole('alert')).toHaveTextContent('Les flux RSS ont été refusés.')
|
||||
expect(within(form).getByRole('alert')).not.toHaveTextContent(/PRIVATE_/)
|
||||
expect(within(form).getByLabelText('URL du flux RSS Bloomberg 1')).toHaveValue(latest)
|
||||
})
|
||||
|
||||
it('verrouille activation et plafond pendant la sauvegarde des flux de la même source', async () => {
|
||||
render(<Sources />)
|
||||
const form = await screen.findByRole('form', { name: 'Flux RSS Bloomberg' })
|
||||
let complete!: (value: Response) => void
|
||||
fetchMock.mockImplementationOnce(() => new Promise<Response>(resolve => { complete = resolve }))
|
||||
await userEvent.click(within(form).getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(screen.getByRole('button', { name: 'Désactiver Bloomberg' })).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: 'Enregistrer le plafond Bloomberg' })).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: 'Activer Investing.com' })).toBeEnabled()
|
||||
complete(new Response(JSON.stringify({ data: { ok: true } }), { status: 200 }))
|
||||
expect(await within(form).findByText(/Flux RSS enregistrés pour les prochaines synthèses/)).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Désactiver Bloomberg' })).toBeEnabled()
|
||||
})
|
||||
38
frontend/tests/source-feed-outcome-ticket41.test.tsx
Normal file
38
frontend/tests/source-feed-outcome-ticket41.test.tsx
Normal file
@ -0,0 +1,38 @@
|
||||
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'
|
||||
import { afterEach, expect, it } from 'vitest'
|
||||
import { GenerationDetails } from '../src/components/GenerationDetails'
|
||||
import type { GenerationOutcome } from '../src/api/summaries'
|
||||
|
||||
afterEach(cleanup)
|
||||
const outcome = (status: string, sourceKey = 'bloomberg'): GenerationOutcome => ({
|
||||
id: 'g', status: 'partial', language: 'fr', ranking_mode: 'title_content', failure_code: 'content_incomplete',
|
||||
total_candidates: 6, laya_selected: 2, selected: 2, global_limit: 50, content_fallbacks: 1,
|
||||
content_complete: 3, content_incomplete: 2, content_unavailable: 1,
|
||||
source_stats: [{ source_id: 'b', source_key: sourceKey, source_type: 'stocktwits', status, candidates: 6, laya_selected: 2, selected: 2, article_limit: 20, content_fallbacks: 1,
|
||||
content_complete: 3, content_incomplete: 2, content_unavailable: 1,
|
||||
feeds: { attempted: 5, succeeded: status === 'failed' ? 0 : 4, failed: status === 'failed' ? 5 : 1 },
|
||||
}],
|
||||
})
|
||||
function show(value: GenerationOutcome) {
|
||||
const result = render(<GenerationDetails outcome={value} />)
|
||||
fireEvent.click(screen.getByText('Détails de la génération'))
|
||||
return result
|
||||
}
|
||||
|
||||
it('annonce une récupération partielle de feeds distincte de la complétude, sans perdre les agrégats', () => {
|
||||
show(outcome('partial'))
|
||||
expect(screen.getByText(/Certains flux RSS de Bloomberg n’ont pas pu être récupérés/)).toBeInTheDocument()
|
||||
const row = screen.getByRole('row', { name: /Bloomberg/ })
|
||||
expect(within(row).getByRole('cell', { name: 'Récupération partielle · contenus de complétude variable' })).toBeInTheDocument()
|
||||
expect(within(row).getByText('Tentés : 5 · récupérés : 4 · en échec : 1')).toBeInTheDocument()
|
||||
expect(screen.getByText('Contenus complets : 3')).toBeInTheDocument()
|
||||
expect(screen.getByText(/Seuls les contenus complets sont éligibles/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('nomme Investing.com et rend une indisponibilité complète des feeds sans diagnostic brut', () => {
|
||||
const { container } = show(outcome('failed', 'investing_com'))
|
||||
expect(screen.getByRole('rowheader', { name: 'Investing.com' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('cell', { name: 'Récupération impossible' })).toBeInTheDocument()
|
||||
expect(screen.getByText('Tentés : 5 · récupérés : 0 · en échec : 5')).toBeInTheDocument()
|
||||
expect(container.innerHTML).not.toMatch(/stocktwits|https?:|abonnement|authentification|challenge/i)
|
||||
})
|
||||
105
frontend/tests/source-feeds-editor-ticket41.test.tsx
Normal file
105
frontend/tests/source-feeds-editor-ticket41.test.tsx
Normal file
@ -0,0 +1,105 @@
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import { SourceFeedsEditor } from '../src/components/SourceFeedsEditor'
|
||||
|
||||
const latest = 'https://feed.quanwenrss.com/feed/bloomberg-latest.xml'
|
||||
const economics = 'https://feed.quanwenrss.com/feed/bloomberg-economics.xml'
|
||||
const save = vi.fn()
|
||||
const fetchMock = vi.fn()
|
||||
function show(urls = [latest]) {
|
||||
return render(<SourceFeedsEditor sourceId="b" sourceKey="bloomberg" sourceName="Bloomberg" urls={urls} onSave={save} />)
|
||||
}
|
||||
beforeEach(() => { save.mockReset().mockResolvedValue(undefined); vi.stubGlobal('fetch', fetchMock.mockReset()) })
|
||||
afterEach(() => { cleanup(); vi.unstubAllGlobals() })
|
||||
|
||||
it('ajoute et retire des lignes identifiées puis sauvegarde toutes les URLs sans récupération', async () => {
|
||||
show()
|
||||
expect(screen.getByLabelText('URL du flux RSS Bloomberg 1')).toHaveValue(latest)
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Ajouter un flux RSS Bloomberg' }))
|
||||
await userEvent.type(screen.getByLabelText('URL du flux RSS Bloomberg 2'), economics)
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(save).toHaveBeenLastCalledWith([latest, economics])
|
||||
expect(screen.getByRole('status')).toHaveTextContent('Flux RSS enregistrés pour les prochaines synthèses. Aucune récupération ni génération n’a été lancée.')
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Retirer le flux RSS Bloomberg 1' }))
|
||||
expect(screen.getByLabelText('URL du flux RSS Bloomberg 1')).toHaveValue(economics)
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(save).toHaveBeenLastCalledWith([economics])
|
||||
expect(fetchMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it.each([
|
||||
'', 'bad-url', 'http://feed.quanwenrss.com/feed/bloomberg-latest.xml',
|
||||
'https://feed.quanwenrss.com.evil.invalid/feed/bloomberg-latest.xml',
|
||||
'https://127.0.0.1/feed/bloomberg-latest.xml',
|
||||
'https://feed.quanwenrss.com:8443/feed/bloomberg-latest.xml',
|
||||
'https://user:PRIVATE_SECRET@feed.quanwenrss.com/feed/bloomberg-latest.xml',
|
||||
`${latest}#fragment`, `${latest}?secret=PRIVATE_SECRET`,
|
||||
'https://feed.quanwenrss.com/feed/investing-news.xml',
|
||||
'https://feed.quanwenrss.com/feed/unknown.xml',
|
||||
])('refuse une URL non autorisée sans requête (%s)', async url => {
|
||||
show([url])
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
const input = screen.getByLabelText('URL du flux RSS Bloomberg 1')
|
||||
expect(input).toHaveAttribute('aria-invalid', 'true')
|
||||
expect(input).toHaveAccessibleDescription(/URL|adresse/i)
|
||||
const alert = screen.getByRole('alert')
|
||||
expect(alert).not.toHaveTextContent(/PRIVATE_SECRET|127\.0\.0\.1|https?:/)
|
||||
expect(save).not.toHaveBeenCalled()
|
||||
expect(fetchMock).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('refuse les doublons et une liste vidée puis permet de corriger', async () => {
|
||||
show([latest, latest])
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(screen.getAllByRole('alert')[0]).toHaveTextContent(/déjà présent/)
|
||||
await userEvent.clear(screen.getByLabelText('URL du flux RSS Bloomberg 2'))
|
||||
await userEvent.type(screen.getByLabelText('URL du flux RSS Bloomberg 2'), economics)
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(save).toHaveBeenCalledWith([latest, economics])
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Retirer le flux RSS Bloomberg 2' }))
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Retirer le flux RSS Bloomberg 1' }))
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(screen.getByRole('alert')).toHaveTextContent(/Ajoutez au moins un flux RSS/)
|
||||
expect(save).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('garde les saisies après une erreur de sauvegarde, sans exposer le détail brut, et permet de réessayer', async () => {
|
||||
save.mockRejectedValueOnce(new Error('PRIVATE_SECRET https://private.invalid'))
|
||||
show([latest, economics])
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('Impossible d’enregistrer les flux RSS. Votre saisie est conservée. Réessayez.')
|
||||
expect(screen.getByRole('alert')).not.toHaveTextContent(/PRIVATE_SECRET|private.invalid/)
|
||||
expect(screen.getByLabelText('URL du flux RSS Bloomberg 2')).toHaveValue(economics)
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(save).toHaveBeenCalledTimes(2)
|
||||
expect(screen.getByRole('status')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('annonce l’enregistrement en cours et empêche les soumissions concurrentes', async () => {
|
||||
let complete!: () => void
|
||||
save.mockImplementationOnce(() => new Promise<void>(resolve => { complete = resolve }))
|
||||
show()
|
||||
const button = screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' })
|
||||
await userEvent.click(button)
|
||||
expect(screen.getByRole('form', { name: 'Flux RSS Bloomberg' })).toHaveAttribute('aria-busy', 'true')
|
||||
expect(button).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: 'Ajouter un flux RSS Bloomberg' })).toBeDisabled()
|
||||
expect(screen.getByRole('status')).toHaveTextContent('Enregistrement des flux RSS…')
|
||||
complete()
|
||||
expect(await screen.findByText(/Flux RSS enregistrés pour les prochaines synthèses/)).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it.each([` ${latest}`, `${latest} `, 'https://feed.quanwenrss.com/feed/../feed/bloomberg-latest.xml'])('refuse une normalisation qui masquerait une URL non conforme au serveur (%s)', async url => {
|
||||
show([url])
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(screen.getByRole('alert')).toBeInTheDocument()
|
||||
expect(save).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('normalise le port HTTPS standard et refuse les doublons normalisés', async () => {
|
||||
show([latest, 'https://FEED.QUANWENRSS.COM:443/feed/bloomberg-latest.xml'])
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Enregistrer les flux RSS Bloomberg' }))
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('déjà présent')
|
||||
expect(save).not.toHaveBeenCalled()
|
||||
})
|
||||
Reference in New Issue
Block a user