T-87: tests
This commit is contained in:
parent
b2a1f5ce80
commit
33b1d23f84
2 changed files with 196 additions and 0 deletions
|
|
@ -1893,3 +1893,114 @@ describe('security-master source-symbol-readers', () => {
|
|||
expect(docsPerSec).toBeGreaterThanOrEqual(25_000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('security-master source-symbol-readers security-type QA edges', () => {
|
||||
test('Type/type precedence: blank or non-string `Type` falls back to string `type`; string `Type` wins over `type`', async () => {
|
||||
const exchangeLookup = createPass1ExchangeLookup();
|
||||
const base = { Exchange: 'NASDAQ', Country: 'USA', Currency: 'USD' };
|
||||
const reader = new FakeSourceSymbolReader(
|
||||
{
|
||||
eodSymbols: [
|
||||
{ ...base, eodSearchCode: 'AAPL.US', Code: 'AAPL', Isin: 'US0378331005', Name: 'Apple', Type: ' ', type: 'Common Stock' },
|
||||
{ ...base, eodSearchCode: 'SPY.US', Code: 'SPY', Isin: 'US78462F1030', Name: 'SPY', Type: 7, type: 'ETF' },
|
||||
{ ...base, eodSearchCode: 'Z.US', Code: 'Z', Isin: 'US98954M1018', Name: 'Zillow', Type: 'Common Stock', type: 'ETF' },
|
||||
],
|
||||
ibSymbols: [],
|
||||
qmSymbols: [],
|
||||
ceoSymbols: [],
|
||||
eodSymbolChange: [],
|
||||
},
|
||||
{ readOnly: true, applyFilterAndProjection: true }
|
||||
);
|
||||
|
||||
const sources = await readSecurityMasterSources(reader, { exchangeLookup });
|
||||
|
||||
assertStatsConservation(sources.stats.eodSymbols);
|
||||
expect(sources.stats.eodSymbols.emitted).toBe(3);
|
||||
expect([...sources.securityTypeByIsin.entries()]).toEqual([
|
||||
['US0378331005', 'common'],
|
||||
['US78462F1030', 'etf'],
|
||||
['US98954M1018', 'common'],
|
||||
]);
|
||||
expect(sources.securityTypeStats.missingType).toBe(0);
|
||||
expect(sources.securityTypeConflicts).toEqual([]);
|
||||
});
|
||||
|
||||
test('mixed EOD + IB sources: full-source Stage A EOD members all have a loader type, IB-only instruments are not typed', async () => {
|
||||
const exchangeLookup = createPass1ExchangeLookup();
|
||||
const reader = new FakeSourceSymbolReader(
|
||||
{
|
||||
eodSymbols: [
|
||||
{ eodSearchCode: 'AAPL.US', Code: 'AAPL', Exchange: 'NASDAQ', Country: 'USA', Currency: 'USD', Isin: 'US0378331005', Name: 'Apple', Type: 'Common Stock' },
|
||||
{ eodSearchCode: 'SHOP.TO', Code: 'SHOP', Exchange: 'TO', Country: 'Canada', Currency: 'CAD', Isin: 'CA82509L1076', Name: 'Shopify', Type: 'Common Stock' },
|
||||
{ eodSearchCode: 'SHOP.US', Code: 'SHOP', Exchange: 'NYSE', Country: 'USA', Currency: 'USD', Isin: 'CA82509L1076', Name: 'Shopify', Type: 'common stock' },
|
||||
],
|
||||
ibSymbols: [
|
||||
{ conid: 265598, symbol: 'AAPL', exchangeId: 'NASDAQ', country: 'US', currency: 'USD', isin: 'US0378331005' },
|
||||
{ conid: 900, symbol: 'Z', exchangeId: 'NASDAQ', country: 'US', currency: 'USD', isin: 'US98954M1018' },
|
||||
],
|
||||
qmSymbols: [],
|
||||
ceoSymbols: [],
|
||||
eodSymbolChange: [],
|
||||
},
|
||||
{ readOnly: true, applyFilterAndProjection: true }
|
||||
);
|
||||
|
||||
const sources = await readSecurityMasterSources(reader, { exchangeLookup });
|
||||
assertStatsConservation(sources.stats.eodSymbols);
|
||||
assertStatsConservation(sources.stats.ibSymbols);
|
||||
|
||||
// Same Stage A that the orchestrator will run over every source.
|
||||
const stageA = matchInstrumentsStageA(sources.stageARecords);
|
||||
const withEodMember = stageA.instruments.filter(inst => inst.members.some(m => m.source === 'eod'));
|
||||
expect(withEodMember.map(i => i.primaryIsin)).toEqual(['CA82509L1076', 'US0378331005']);
|
||||
for (const inst of withEodMember) {
|
||||
expect(sources.securityTypeByIsin.get(inst.primaryIsin)).toBe('common');
|
||||
}
|
||||
// Zillow is IB-only: IB type inference is out of scope, so it stays untyped (no guessing).
|
||||
expect(stageA.instruments.some(i => i.primaryIsin === 'US98954M1018')).toBe(true);
|
||||
expect(sources.securityTypeByIsin.has('US98954M1018')).toBe(false);
|
||||
expect(sources.securityTypeLoaderStats.isinsMapped).toBe(2);
|
||||
expect(sources.securityTypeLoaderStats.recordsIn).toBe(3);
|
||||
});
|
||||
|
||||
test('maxSecurityTypeConflicts option caps loader conflicts and invalid values reject', async () => {
|
||||
const exchangeLookup = createPass1ExchangeLookup();
|
||||
const docs = [
|
||||
{ eodSearchCode: 'SHOP.TO', Code: 'SHOP', Exchange: 'TO', Country: 'Canada', Currency: 'CAD', Isin: 'CA82509L1076', Name: 'Shopify', Type: 'Common Stock' },
|
||||
{ eodSearchCode: 'SHOP.US', Code: 'SHOP', Exchange: 'NYSE', Country: 'USA', Currency: 'USD', Isin: 'CA82509L1076', Name: 'Shopify', Type: 'ETF' },
|
||||
{ eodSearchCode: 'AAPL.US', Code: 'AAPL', Exchange: 'NASDAQ', Country: 'USA', Currency: 'USD', Isin: 'US0378331005', Name: 'Apple', Type: 'Common Stock' },
|
||||
{ eodSearchCode: 'AAPL.NEO', Code: 'AAPL', Exchange: 'NYSE', Country: 'USA', Currency: 'USD', Isin: 'US0378331005', Name: 'Apple', Type: 'CDR' },
|
||||
];
|
||||
const make = () =>
|
||||
new FakeSourceSymbolReader(
|
||||
{ eodSymbols: docs, ibSymbols: [], qmSymbols: [], ceoSymbols: [], eodSymbolChange: [] },
|
||||
{ readOnly: true, applyFilterAndProjection: true }
|
||||
);
|
||||
|
||||
const capped = await readSecurityMasterSources(make(), { exchangeLookup, maxSecurityTypeConflicts: 1 });
|
||||
expect(capped.securityTypeByIsin.size).toBe(0);
|
||||
expect(capped.securityTypeConflicts.map(c => c.isin)).toEqual(['CA82509L1076']);
|
||||
expect(capped.securityTypeLoaderStats.isinsConflicting).toBe(2);
|
||||
expect(capped.securityTypeLoaderStats.conflictsTruncated).toBe(1);
|
||||
|
||||
await expect(
|
||||
readSecurityMasterSources(make(), { exchangeLookup, maxSecurityTypeConflicts: -1 })
|
||||
).rejects.toThrow(RangeError);
|
||||
});
|
||||
|
||||
test('readEodSymbols on an empty collection returns an empty map and zeroed stats', async () => {
|
||||
const reader = new FakeSourceSymbolReader(
|
||||
{ eodSymbols: [] },
|
||||
{ readOnly: true, applyFilterAndProjection: true }
|
||||
);
|
||||
const result = await readEodSymbols(reader, { exchangeLookup: createPass1ExchangeLookup() });
|
||||
expect(result.securityTypeByIsin.size).toBe(0);
|
||||
expect(result.securityTypeRecords).toEqual([]);
|
||||
expect(result.unknownSecurityTypes).toEqual([]);
|
||||
expect(result.securityTypeConflicts).toEqual([]);
|
||||
expect(result.securityTypeStats.recordsIn).toBe(0);
|
||||
expect(result.securityTypeLoaderStats.recordsIn).toBe(0);
|
||||
assertStatsConservation(result.stats);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue