feat(sources): enforce supported source allowlist
Assign stable keys to the three supported sources, preserve excluded historical rows, and expose history read-only in admin. Add migration, coverage, and responsive browser spec. Refs #13 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { cleanup, render, screen, waitFor } from '@testing-library/react'
|
||||
import { cleanup, render, screen, waitFor, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
@ -23,7 +23,7 @@ describe('plafonds d’articles administrateur', () => {
|
||||
listSettings.mockResolvedValue([{ key: 'summary_max_articles', value: '700' }])
|
||||
getDefaultPrompt.mockResolvedValue({ prompt: 'system' })
|
||||
updateSettings.mockResolvedValue(undefined)
|
||||
listSources.mockResolvedValue([{ id: 'source-1', name: 'Yahoo Finance', type: 'yahoo', enabled: true, article_limit: 240 }])
|
||||
listSources.mockResolvedValue([{ id: 'source-1', name: 'Yahoo Finance', type: 'yahoo', source_key: 'yahoo_finance', supported: true, operational: true, enabled: true, article_limit: 240 }])
|
||||
updateSource.mockResolvedValue(undefined)
|
||||
})
|
||||
|
||||
@ -93,7 +93,7 @@ describe('plafonds d’articles administrateur', () => {
|
||||
|
||||
it('initialise uniquement les valeurs absentes à 50 et 20', async () => {
|
||||
listSettings.mockResolvedValue([])
|
||||
listSources.mockResolvedValue([{ id: 'source-1', name: 'Yahoo Finance', type: 'yahoo', enabled: true }])
|
||||
listSources.mockResolvedValue([{ id: 'source-1', name: 'Yahoo Finance', type: 'yahoo', source_key: 'yahoo_finance', supported: true, operational: true, enabled: true }])
|
||||
render(<Sources />)
|
||||
expect(await screen.findByLabelText('Articles max par résumé')).toHaveValue(50)
|
||||
expect(screen.getByLabelText('Plafond Yahoo Finance')).toHaveValue(20)
|
||||
@ -149,4 +149,75 @@ describe('plafonds d’articles administrateur', () => {
|
||||
expect(updateSource).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('ne rend activables que Yahoo, Bloomberg et Watcher Guru; garde StockTwits et Reuters en historique sans commandes', async () => {
|
||||
listSources.mockResolvedValue([
|
||||
{ id: 'y', name: 'Yahoo Finance', type: 'stocktwits', source_key: 'yahoo_finance', supported: true, operational: true, enabled: true, article_limit: 83 },
|
||||
{ id: 'b', name: 'Bloomberg', type: 'bloomberg', source_key: 'bloomberg', supported: true, operational: true, enabled: false, article_limit: 77 },
|
||||
{ id: 'w', name: 'Watcher.Guru', type: 'watcherguru', source_key: 'watcher_guru', supported: true, operational: true, enabled: true, article_limit: 64 },
|
||||
{ id: 's', name: 'StockTwits', type: 'stocktwits', source_key: null, supported: false, operational: false, enabled: false, article_limit: 31 },
|
||||
{ id: 'r', name: 'Reuters', type: 'reuters', source_key: null, supported: false, operational: false, enabled: false, article_limit: 42 },
|
||||
])
|
||||
render(<Sources />)
|
||||
expect(await screen.findByRole('heading', { name: 'Anciennes sources exclues' })).toBeInTheDocument()
|
||||
for (const name of ['Yahoo Finance', 'Bloomberg', 'Watcher.Guru']) {
|
||||
expect(screen.getByRole('button', { name: new RegExp(`^(?:Activer|Désactiver) ${name}$`) })).toBeInTheDocument()
|
||||
expect(screen.getByLabelText(`Plafond ${name}`)).toBeInTheDocument()
|
||||
}
|
||||
const historical = screen.getByRole('region', { name: 'Anciennes sources exclues' })
|
||||
expect(within(historical).getByText('StockTwits')).toBeInTheDocument()
|
||||
expect(within(historical).getByText('Reuters')).toBeInTheDocument()
|
||||
expect(within(historical).queryByRole('button')).not.toBeInTheDocument()
|
||||
expect(within(historical).queryByRole('spinbutton')).not.toBeInTheDocument()
|
||||
const yahooCard = screen.getByRole('form', { name: 'Réglages de Yahoo Finance' }).closest('.rounded-md')
|
||||
expect(yahooCard).not.toBeNull()
|
||||
expect(within(yahooCard as HTMLElement).queryByText(/stocktwits/i)).not.toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Plafond Yahoo Finance')).toHaveValue(83)
|
||||
expect(screen.getByLabelText('Plafond Bloomberg')).toHaveValue(77)
|
||||
expect(screen.getByLabelText('Plafond Watcher.Guru')).toHaveValue(64)
|
||||
})
|
||||
|
||||
it('garde les anciennes sources repliées et en lecture seule même si enabled est historique', async () => {
|
||||
listSources.mockResolvedValue([
|
||||
{ id: 'old', name: 'Reuters', type: 'reuters', source_key: null, supported: false, operational: false, enabled: true, article_limit: 42 },
|
||||
])
|
||||
const user = userEvent.setup()
|
||||
render(<Sources />)
|
||||
const region = await screen.findByRole('region', { name: 'Anciennes sources exclues' })
|
||||
const disclosure = region.querySelector('details')!
|
||||
expect(disclosure).not.toHaveAttribute('open')
|
||||
await user.click(within(region).getByText('Consulter les anciennes sources (1)'))
|
||||
expect(disclosure).toHaveAttribute('open')
|
||||
expect(within(region).getByText('Reuters')).toBeVisible()
|
||||
expect(within(region).queryByRole('button')).not.toBeInTheDocument()
|
||||
expect(within(region).queryByRole('spinbutton')).not.toBeInTheDocument()
|
||||
expect(updateSource).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('annonce les réglages des prochaines synthèses sans annoncer de génération lancée', async () => {
|
||||
listSources.mockResolvedValue([{ id: 'y', name: 'Stocktwits', type: 'stocktwits', source_key: 'yahoo_finance', supported: true, operational: true, enabled: true, article_limit: 83 }])
|
||||
const user = userEvent.setup()
|
||||
render(<Sources />)
|
||||
const input = await screen.findByLabelText('Plafond Yahoo Finance')
|
||||
expect(screen.queryByText('Stocktwits')).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Désactiver Yahoo Finance' }))
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Yahoo Finance désactivée pour les prochaines synthèses. Aucune génération n’a été lancée.')
|
||||
expect(input).toHaveValue(83)
|
||||
expect(input).toBeDisabled()
|
||||
await user.click(screen.getByRole('button', { name: 'Activer Yahoo Finance' }))
|
||||
await waitFor(() => expect(input).toBeEnabled())
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer le plafond Yahoo Finance' }))
|
||||
expect(await screen.findByRole('status')).toHaveTextContent('Plafond Yahoo Finance enregistré pour les prochaines synthèses.')
|
||||
expect(updateSource).toHaveBeenLastCalledWith('y', true, 83)
|
||||
})
|
||||
|
||||
it('permet de recharger après un échec sans afficher de commandes pour des sources supposées', async () => {
|
||||
listSources.mockRejectedValueOnce(new Error('network'))
|
||||
const user = userEvent.setup()
|
||||
render(<Sources />)
|
||||
expect(await screen.findByRole('alert')).toHaveTextContent('Impossible de charger')
|
||||
expect(screen.queryByRole('spinbutton')).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Réessayer' }))
|
||||
expect(await screen.findByLabelText('Plafond Yahoo Finance')).toHaveValue(240)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user