feat(watchlist): add company identity catalog
Embed a pinned FinanceDatabase equity snapshot, add authenticated company search and identity-based follows, preserve legacy assets, and map selected Yahoo symbols for collection. Refs #19 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -23,18 +23,18 @@ const legacyAsset = {
|
||||
id: 'legacy-asset-1', user_id: 'reader-1', symbol: 'OLDX', name: 'Old historic asset',
|
||||
figi: null, created_at: '2025-01-01T00:00:00.000Z',
|
||||
}
|
||||
const indexOne = { figi: 'BBG000SPX001', name: 'S&P 500', symbol: 'SPX', market: 'US' }
|
||||
const indexTwo = { figi: 'BBG000SPX002', name: 'S&P 500 alternate listing', symbol: 'SPX', market: 'US' }
|
||||
const indexOne = { company_id: 'company-a', name: 'Apple Inc.', country: 'United States', exchange: 'Nasdaq', mic: 'XNAS', symbol: 'SSAAPL INDEX' }
|
||||
const indexTwo = { company_id: 'company-b', name: 'Apple Holdings', country: 'United Kingdom', exchange: 'London Stock Exchange', mic: 'XLON', symbol: 'AAPL/B' }
|
||||
|
||||
function apiError(status: number, message: string) {
|
||||
return Object.assign(new Error(message), { status })
|
||||
}
|
||||
|
||||
function resultRegion() {
|
||||
return screen.getByRole('region', { name: /résultats de recherche/i })
|
||||
return screen.getByRole('region', { name: /résultats des entreprises/i })
|
||||
}
|
||||
|
||||
describe('Ticket #4 — rechercher et suivre des indices', () => {
|
||||
describe('Régressions Watchlist — recherche explicite et suivis d’entreprises', () => {
|
||||
afterEach(cleanup)
|
||||
|
||||
beforeEach(() => {
|
||||
@ -50,13 +50,13 @@ describe('Ticket #4 — rechercher et suivre des indices', () => {
|
||||
searchIndices.mockResolvedValueOnce([indexOne])
|
||||
render(<Watchlist />)
|
||||
|
||||
const query = await screen.findByRole('textbox', { name: 'Nom ou symbole' })
|
||||
const query = await screen.findByRole('textbox', { name: "Nom de l'entreprise" })
|
||||
expect(query).toHaveAttribute('maxLength', '100')
|
||||
await user.type(query, 'S&P 500')
|
||||
await user.type(query, 'Apple Inc.')
|
||||
expect(searchIndices).not.toHaveBeenCalled()
|
||||
await user.click(screen.getByRole('button', { name: 'Rechercher' }))
|
||||
await waitFor(() => expect(searchIndices).toHaveBeenCalledWith('S&P 500', 20))
|
||||
expect(await within(resultRegion()).findByText('S&P 500')).toBeInTheDocument()
|
||||
await waitFor(() => expect(searchIndices).toHaveBeenCalledWith('Apple Inc.', 20))
|
||||
expect(await within(resultRegion()).findByText('Apple Inc.')).toBeInTheDocument()
|
||||
expect(within(resultRegion()).queryByText('BBG000SPX001')).not.toBeInTheDocument()
|
||||
|
||||
await user.clear(query)
|
||||
@ -65,27 +65,27 @@ describe('Ticket #4 — rechercher et suivre des indices', () => {
|
||||
expect(searchIndices).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('exige le choix explicite, transmet le FIGI, affiche les doublons ambigus et garde les actifs legacy', async () => {
|
||||
it('exige le choix explicite, transmet company_id et garde les suivis existants', async () => {
|
||||
const user = userEvent.setup()
|
||||
listAssets.mockResolvedValueOnce([legacyAsset, { id: 'followed-1', ...indexOne, user_id: 'reader-1' }])
|
||||
searchIndices.mockResolvedValueOnce([indexOne, indexTwo])
|
||||
render(<Watchlist />)
|
||||
|
||||
const history = await screen.findByRole('region', { name: /actifs historiques/i })
|
||||
expect(within(history).getByText('Type non vérifié')).toBeInTheDocument()
|
||||
expect(within(history).queryByRole('button')).not.toBeInTheDocument()
|
||||
expect(within(history).getByText('Old historic asset')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Nom ou symbole')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText("Nom de l'entreprise")).toBeInTheDocument()
|
||||
|
||||
const query = screen.getByRole('textbox', { name: 'Nom ou symbole' })
|
||||
await user.type(query, 'S&P 500{Enter}')
|
||||
const results = await screen.findByRole('region', { name: /résultats de recherche/i })
|
||||
expect(within(results).getByText('BBG000SPX001')).toBeInTheDocument()
|
||||
expect(within(results).getByText('BBG000SPX002')).toBeInTheDocument()
|
||||
expect(within(results).getByRole('button', { name: /déjà suivi/i })).toBeDisabled()
|
||||
const follow = within(results).getAllByRole('button', { name: /suivre cet indice/i })[0]
|
||||
const query = screen.getByRole('textbox', { name: "Nom de l'entreprise" })
|
||||
await user.type(query, 'Apple Inc.{Enter}')
|
||||
const results = await screen.findByRole('region', { name: /résultats des entreprises/i })
|
||||
expect(within(results).getByText('Nasdaq')).toBeInTheDocument()
|
||||
expect(within(results).getByText('London Stock Exchange')).toBeInTheDocument()
|
||||
expect(within(results).getByRole('button', { name: /déjà suivie/i })).toBeDisabled()
|
||||
const follow = within(results).getAllByRole('button', { name: /suivre cette entreprise/i })[0]
|
||||
await user.click(follow)
|
||||
await waitFor(() => expect(addAsset).toHaveBeenCalledWith({
|
||||
symbol: 'SPX', name: 'S&P 500 alternate listing', figi: 'BBG000SPX002',
|
||||
company_id: 'company-b',
|
||||
}))
|
||||
expect(addAsset).toHaveBeenCalledTimes(1)
|
||||
expect(within(history).getByText('Old historic asset')).toBeInTheDocument()
|
||||
@ -94,16 +94,16 @@ describe('Ticket #4 — rechercher et suivre des indices', () => {
|
||||
it('annonce aucun résultat et les erreurs quota, timeout et indisponibilité sans effacer la recherche', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<Watchlist />)
|
||||
const query = await screen.findByRole('textbox', { name: 'Nom ou symbole' })
|
||||
const query = await screen.findByRole('textbox', { name: "Nom de l'entreprise" })
|
||||
|
||||
searchIndices.mockResolvedValueOnce([])
|
||||
await user.type(query, 'No match{Enter}')
|
||||
expect(await screen.findByText(/aucun indice trouvé/i)).toBeInTheDocument()
|
||||
expect(await screen.findByText(/aucune entreprise trouvée/i)).toBeInTheDocument()
|
||||
|
||||
for (const [error, message] of [
|
||||
[apiError(429, 'rate limited'), /quota de recherche/i],
|
||||
[apiError(504, 'timeout'), /délai.*dépassé|timeout/i],
|
||||
[apiError(502, 'provider unavailable'), /fournisseur.*indisponible/i],
|
||||
[apiError(502, 'provider unavailable'), /service.*indisponible/i],
|
||||
] as const) {
|
||||
searchIndices.mockRejectedValueOnce(error)
|
||||
await user.clear(query)
|
||||
@ -122,16 +122,16 @@ describe('Ticket #4 — rechercher et suivre des indices', () => {
|
||||
.mockReturnValueOnce(new Promise(resolve => { resolveCurrent = resolve }))
|
||||
const user = userEvent.setup()
|
||||
render(<Watchlist />)
|
||||
const query = await screen.findByRole('textbox', { name: 'Nom ou symbole' })
|
||||
const query = await screen.findByRole('textbox', { name: "Nom de l'entreprise" })
|
||||
|
||||
await user.type(query, 'Old query{Enter}')
|
||||
await user.clear(query)
|
||||
await user.type(query, 'Current query{Enter}')
|
||||
resolveCurrent([{ figi: 'BBG-CURRENT', name: 'Current index', symbol: 'CUR' }])
|
||||
expect(await screen.findByText('Current index')).toBeInTheDocument()
|
||||
resolveOld([{ figi: 'BBG-STALE', name: 'Stale index', symbol: 'OLD' }])
|
||||
await waitFor(() => expect(screen.queryByText('Stale index')).not.toBeInTheDocument())
|
||||
expect(screen.getByText('Current index')).toBeInTheDocument()
|
||||
resolveCurrent([{ company_id: 'current-company', name: 'Current company', exchange: '', country: '', mic: '' }])
|
||||
expect(await screen.findByText('Current company')).toBeInTheDocument()
|
||||
resolveOld([{ company_id: 'stale-company', name: 'Stale company', exchange: '', country: '', mic: '' }])
|
||||
await waitFor(() => expect(screen.queryByText('Stale company')).not.toBeInTheDocument())
|
||||
expect(screen.getByText('Current company')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('conserve les actifs après erreur de suivi ou retrait et permet le retrait par identifiant', async () => {
|
||||
@ -142,17 +142,17 @@ describe('Ticket #4 — rechercher et suivre des indices', () => {
|
||||
searchIndices.mockResolvedValueOnce([indexTwo])
|
||||
render(<Watchlist />)
|
||||
|
||||
const query = await screen.findByRole('textbox', { name: 'Nom ou symbole' })
|
||||
await user.type(query, 'S&P 500{Enter}')
|
||||
const results = await screen.findByRole('region', { name: /résultats de recherche/i })
|
||||
await user.click(within(results).getByRole('button', { name: /suivre cet indice/i }))
|
||||
const query = await screen.findByRole('textbox', { name: "Nom de l'entreprise" })
|
||||
await user.type(query, 'Apple Inc.{Enter}')
|
||||
const results = await screen.findByRole('region', { name: /résultats des entreprises/i })
|
||||
await user.click(within(results).getByRole('button', { name: /suivre cette entreprise/i }))
|
||||
expect(await screen.findByRole('alert')).toBeInTheDocument()
|
||||
expect(query).toHaveValue('S&P 500')
|
||||
expect(query).toHaveValue('Apple Inc.')
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /ne plus suivre/i }))
|
||||
expect(await screen.findByRole('alert')).toBeInTheDocument()
|
||||
expect(removeAsset).toHaveBeenCalledWith('tracked-1')
|
||||
expect(screen.getByText('S&P 500')).toBeInTheDocument()
|
||||
expect(screen.getByText('Apple Inc.')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user