refactor(data): normalize provider symbols and remove dead scaffolding (CL34)
This commit is contained in:
parent
5c9e32d0ef
commit
e2292e4883
11 changed files with 287 additions and 581 deletions
148
test/integration/provider-symbol.test.ts
Normal file
148
test/integration/provider-symbol.test.ts
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
import { expect, test } from 'bun:test';
|
||||
import {
|
||||
normalizeProviderSymbol,
|
||||
type ProviderSymbol,
|
||||
type ProviderSymbolDocument,
|
||||
} from '../../apps/stock/data-pipeline/src/normalization/provider-symbol';
|
||||
|
||||
const variants: {
|
||||
name: string;
|
||||
input: ProviderSymbolDocument;
|
||||
expected: ProviderSymbol;
|
||||
}[] = [
|
||||
{
|
||||
name: 'QM camel case fields and qualified search code',
|
||||
input: {
|
||||
symbol: 'RY',
|
||||
exchangeCode: 'TSX',
|
||||
qmSearchCode: 'RY:CA',
|
||||
companyName: 'Royal Bank',
|
||||
countryCode: 'CA',
|
||||
currency: 'CAD',
|
||||
},
|
||||
expected: {
|
||||
symbol: 'RY',
|
||||
exchangeCode: 'TSX',
|
||||
providerSymbol: 'RY:CA',
|
||||
companyName: 'Royal Bank',
|
||||
country: 'CA',
|
||||
currency: 'CAD',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'EOD title case fields and qualified search code',
|
||||
input: {
|
||||
Code: 'RY',
|
||||
Exchange: 'TO',
|
||||
eodSearchCode: 'RY.TO',
|
||||
Name: 'Royal Bank',
|
||||
Country: 'CA',
|
||||
Currency: 'CAD',
|
||||
},
|
||||
expected: {
|
||||
symbol: 'RY',
|
||||
exchangeCode: 'TO',
|
||||
providerSymbol: 'RY.TO',
|
||||
companyName: 'Royal Bank',
|
||||
country: 'CA',
|
||||
currency: 'CAD',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'IB style code and snake case fields',
|
||||
input: {
|
||||
code: 'BRK.B',
|
||||
exchange_id: 'NYSE',
|
||||
company_name: 'Berkshire',
|
||||
country_code: 'US',
|
||||
currency: 'USD',
|
||||
},
|
||||
expected: {
|
||||
symbol: 'BRK.B',
|
||||
exchangeCode: 'NYSE',
|
||||
providerSymbol: 'BRK.B',
|
||||
companyName: 'Berkshire',
|
||||
country: 'US',
|
||||
currency: 'USD',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'older lowercase exchange and name',
|
||||
input: { symbol: 'aapl', exchange: 'nas', name: 'Apple' },
|
||||
expected: {
|
||||
symbol: 'aapl',
|
||||
exchangeCode: 'nas',
|
||||
providerSymbol: 'aapl',
|
||||
companyName: 'Apple',
|
||||
country: null,
|
||||
currency: null,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
test.each(variants)(
|
||||
'normalizes $name without changing provider identity',
|
||||
({ input, expected }) => {
|
||||
expect(normalizeProviderSymbol(Object.freeze(input))).toEqual(expected);
|
||||
}
|
||||
);
|
||||
|
||||
test('mixed and empty field variants preserve historical precedence', () => {
|
||||
expect(
|
||||
normalizeProviderSymbol({
|
||||
symbol: 'FIRST',
|
||||
code: 'SECOND',
|
||||
Code: 'THIRD',
|
||||
exchangeCode: 'FIRST_EXCHANGE',
|
||||
exchange: 'SECOND_EXCHANGE',
|
||||
exchange_id: 'THIRD_EXCHANGE',
|
||||
Exchange: 'FOURTH_EXCHANGE',
|
||||
qmSearchCode: 'FIRST_SEARCH',
|
||||
eodSearchCode: 'SECOND_SEARCH',
|
||||
companyName: 'FIRST_NAME',
|
||||
name: 'SECOND_NAME',
|
||||
company_name: 'THIRD_NAME',
|
||||
Name: 'FOURTH_NAME',
|
||||
countryCode: 'CA',
|
||||
country_code: 'US',
|
||||
Country: 'GB',
|
||||
currency: 'CAD',
|
||||
Currency: 'USD',
|
||||
})
|
||||
).toEqual({
|
||||
symbol: 'FIRST',
|
||||
exchangeCode: 'FIRST_EXCHANGE',
|
||||
providerSymbol: 'FIRST_SEARCH',
|
||||
companyName: 'FIRST_NAME',
|
||||
country: 'CA',
|
||||
currency: 'CAD',
|
||||
});
|
||||
expect(
|
||||
normalizeProviderSymbol({
|
||||
symbol: '',
|
||||
code: '',
|
||||
Code: 'RY',
|
||||
exchangeCode: null,
|
||||
exchange: '',
|
||||
exchange_id: '',
|
||||
Exchange: 'TO',
|
||||
qmSearchCode: '',
|
||||
eodSearchCode: 'RY.TO',
|
||||
companyName: '',
|
||||
name: '',
|
||||
company_name: '',
|
||||
Name: 'Royal Bank',
|
||||
countryCode: '',
|
||||
country_code: '',
|
||||
Country: 'CA',
|
||||
currency: '',
|
||||
Currency: 'CAD',
|
||||
})
|
||||
).toEqual(variants[1]!.expected);
|
||||
});
|
||||
|
||||
test('incomplete symbol identities remain skipped instead of manufacturing a mapping', () => {
|
||||
for (const input of [{}, { symbol: 'RY' }, { Exchange: 'TO' }, { Code: '', Exchange: 'TO' }]) {
|
||||
expect(normalizeProviderSymbol(input)).toBeNull();
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue