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:
2026-11-22 15:08:22 +01:00
parent 1123360914
commit d65222169a
50 changed files with 49897 additions and 193 deletions

View File

@ -68,7 +68,7 @@ export function readStackManifest() {
if (!manifest.bootstrapAdmin?.email || !manifest.bootstrapAdmin?.password) {
throw new Error('E2E fake stack manifest must provide disposable bootstrap admin credentials.')
}
for (const field of ['indexQuery', 'indexName', 'indexSymbol', 'indexFIGI', 'summaryModelID', 'summarySentinel', 'articleTitle', 'articleURL', 'articleContent', 'candidateID']) {
for (const field of ['companyQuery', 'companyID', 'companyName', 'companySymbol', 'companyFIGI', 'summaryModelID', 'summarySentinel', 'articleTitle', 'articleURL', 'articleContent', 'candidateID']) {
if (typeof manifest.fixtures?.[field] !== 'string' || !manifest.fixtures[field]) {
throw new Error(`E2E fake stack manifest is missing fixtures.${field}.`)
}

View File

@ -35,7 +35,7 @@ async function login(page, baseURL, email, password) {
await expect(page).toHaveURL(new URL('/', baseURL).href)
}
test('admin creates a user who follows a fake index and generates a private summary without article/job writes', async ({ page, request }) => {
test('admin creates a user who follows a fake company and generates a private summary without article/job writes', async ({ page, request }) => {
const stack = readStackManifest()
await page.context().route('**/*', async route => {
const host = new URL(route.request().url()).hostname
@ -60,17 +60,45 @@ test('admin creates a user who follows a fake index and generates a private summ
await page.getByRole('button', { name: 'Déconnexion' }).click()
})
await test.step('new user login and explicit fake OpenFIGI selection', async () => {
let companySearchRequest
let companyFollowRequest
page.on('request', request => {
const url = new URL(request.url())
if (url.pathname === '/api/companies/search') companySearchRequest = url
if (url.pathname === '/api/me/assets' && request.method() === 'POST') companyFollowRequest = request.postDataJSON()
})
await test.step('new user searches by company name and follows the selected local catalog company', async () => {
await login(page, baseURL, email, password)
// Seed a pre-existing legacy follow through the compatibility API so the
// real Watchlist page can prove it remains present after a company follow.
const token = await page.evaluate(() => localStorage.getItem('token'))
const legacy = await request.post(new URL('/api/me/assets', stack.apiUrl).href, {
headers: { Authorization: `Bearer ${token}` },
data: { symbol: 'LEGACYIDX', name: 'Historic index follow' },
})
expect(legacy.status()).toBe(201)
await page.goto(new URL('/assets', baseURL).href)
const query = page.getByRole('textbox', { name: 'Nom ou symbole' })
await query.fill(fixture.indexQuery)
const oldFollows = page.getByRole('region', { name: /autres suivis existants/i })
await expect(oldFollows).toContainText('Historic index follow')
const query = page.getByRole('textbox', { name: "Nom de l'entreprise" })
await query.fill(fixture.companyQuery)
await page.getByRole('button', { name: 'Rechercher' }).click()
const results = page.getByRole('region', { name: 'Résultats de recherche' })
await expect(results.getByText(fixture.indexName)).toBeVisible()
await expect(results.getByText(fixture.indexSymbol)).toBeVisible()
await results.getByRole('button', { name: 'Suivre cet indice' }).click()
await expect(page.getByRole('region', { name: 'Indices suivis' })).toContainText(fixture.indexSymbol)
const results = page.getByRole('region', { name: 'Résultats des entreprises' })
await expect(results.getByText(fixture.companyName)).toBeVisible()
await expect(results).toContainText('E2E Country')
for (const privateValue of [fixture.companySymbol, fixture.companyFIGI, fixture.companyID]) {
await expect(results.getByText(privateValue, { exact: false })).toHaveCount(0)
}
await results.getByRole('button', { name: 'Suivre cette entreprise' }).click()
await expect(page.getByRole('region', { name: 'Entreprises suivies' })).toContainText(fixture.companyName)
await expect(oldFollows).toContainText('Historic index follow')
await expect(companySearchRequest?.pathname).toBe('/api/companies/search')
await expect(companySearchRequest?.searchParams.get('q')).toBe(fixture.companyQuery)
await expect(companySearchRequest?.searchParams.get('limit')).toBe('20')
expect(companyFollowRequest).toEqual({ company_id: fixture.companyID })
})
await test.step('user saves language and ranking preferences', async () => {
@ -105,7 +133,9 @@ test('admin creates a user who follows a fake index and generates a private summ
const response = await request.get(new URL(stack.fakeAuditPath, stack.fakeControlUrl).href)
expect(response.ok()).toBeTruthy()
const events = await response.json()
expect(events.openfigiSearches).toBeGreaterThan(0)
expect(events.openfigiSearches).toBe(0)
expect(events.companySearches).toBeGreaterThan(0)
expect(events.companyResolutions).toBeGreaterThan(0)
expect(events.scraperCalls).toBeGreaterThan(0)
expect(events.layaRankingCalls).toBeGreaterThan(0)
expect(events.layaSummaryCalls).toBeGreaterThan(0)

View File

@ -0,0 +1,67 @@
import { expect, test } from '@playwright/test'
import { readStackManifest } from './stack-manifest.mjs'
async function login(page, baseURL, email, password) {
await page.goto(new URL('/login', baseURL).href)
await page.getByLabel('Adresse email').fill(email)
await page.getByLabel('Mot de passe').fill(password)
await page.getByRole('button', { name: 'Se connecter' }).click()
await expect(page).toHaveURL(new URL('/', baseURL).href)
}
test('ticket #19: search companies by name and follow by company_id while preserving legacy assets', async ({ page }) => {
const stack = readStackManifest()
await page.context().route('**/*', async route => {
const host = new URL(route.request().url()).hostname
if (host !== '127.0.0.1' && host !== '[::1]') return route.abort('blockedbyclient')
return route.continue()
})
await login(page, stack.frontendUrl, stack.bootstrapAdmin.email, stack.bootstrapAdmin.password)
const oldAsset = {
id: 'historical-index-19', user_id: 'ticket19-admin', symbol: 'OLDX',
name: 'Historic S&P index', figi: null, created_at: '2025-01-01T00:00:00.000Z',
}
const companies = [
{ company_id: 'isin:CNE100001526', name: 'BYD Company Limited', exchange: 'Shenzhen Stock Exchange', country: 'China', mic: 'XSHE' },
{ company_id: 'isin:HK0285041858', name: 'BYD Electronic (International) Company Limited', exchange: 'Hong Kong Stock Exchange', country: 'China', mic: 'XHKG' },
]
let followedBody
let searchURL
await page.route('**/api/me/assets', async route => {
if (route.request().method() === 'GET') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [oldAsset] }) })
if (route.request().method() === 'POST') {
followedBody = route.request().postDataJSON()
return route.fulfill({ status: 201, contentType: 'application/json', body: JSON.stringify({ data: { id: 'followed-byd', user_id: oldAsset.user_id, company_id: 'isin:CNE100001526', name: 'BYD Company Limited' } }) })
}
return route.continue()
})
await page.route('**/api/companies/search?**', async route => {
searchURL = new URL(route.request().url())
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: companies }) })
})
await page.goto(new URL('/assets', stack.frontendUrl).href)
await expect(page.getByRole('heading', { name: 'Rechercher une entreprise' })).toBeVisible({ timeout: 3000 })
const query = page.getByRole('textbox', { name: /nom de l'entreprise/i })
await expect(page.getByRole('textbox')).toHaveCount(1)
await query.fill('BYD')
await page.getByRole('button', { name: /rechercher/i }).click()
const results = page.getByRole('region', { name: /résultats des entreprises/i })
const byd = results.getByText('BYD Company Limited').locator('..')
await expect(byd).toContainText('Shenzhen Stock Exchange')
await expect(byd).toContainText('China')
await expect(results.getByText('BYD Electronic (International) Company Limited')).toBeVisible()
for (const privateValue of ['002594.SZ', '0285.HK', 'BBG001QVK2K1', 'BBG000JPLTR7']) {
await expect(results.getByText(privateValue, { exact: false })).toHaveCount(0)
}
await expect(page.getByRole('region', { name: /actifs historiques/i })).toContainText('Historic S&P index')
await byd.getByRole('button', { name: /suivre/i }).click()
await expect.poll(() => followedBody).toEqual({ company_id: 'isin:CNE100001526' })
expect(Object.keys(followedBody)).toEqual(['company_id'])
await expect(page.getByRole('region', { name: /actifs historiques/i })).toContainText('Historic S&P index')
expect(searchURL?.pathname).toBe('/api/companies/search')
expect(searchURL?.searchParams.get('q')).toBe('BYD')
expect(searchURL?.searchParams.get('limit')).toBe('20')
})