T-74: tests

This commit is contained in:
Studio 2026-11-27 21:41:41 -05:00
parent 06f14c8730
commit acbcb0ab7a
2 changed files with 331 additions and 0 deletions

View file

@ -419,4 +419,68 @@ describe.skipIf(!url)('security master override seed SQL', () => {
).rows[0]?.count;
expect(count).toBe(0);
});
test('multi-statement seed file round-trips special characters, class suffix keys, and distinct valid_from rows', async () => {
const f = await createIsolatedFixture();
const aaplListingId = await seedSingleListing(f.pool);
const brk = await f.pool.query<{ instrument_id: number }>(
`INSERT INTO instrument (primary_isin, canonical_name, security_type, issuer_country)
VALUES ('US0846707026', 'Berkshire Hathaway', 'common', 'US') RETURNING instrument_id`
);
const brkA = await f.pool.query<{ listing_id: number }>(
`INSERT INTO listing (instrument_id, mic, ticker_root, class_suffix, currency)
VALUES ($1, 'XNYS', 'BRK', 'A', 'USD') RETURNING listing_id`,
[brk.rows[0]?.instrument_id]
);
const brkB = await f.pool.query<{ listing_id: number }>(
`INSERT INTO listing (instrument_id, mic, ticker_root, class_suffix, currency)
VALUES ($1, 'XNYS', 'BRK', 'B', 'USD') RETURNING listing_id`,
[brk.rows[0]?.instrument_id]
);
const trickyReason = "line1\nO'Brien \\ back\r\nslash -- not a comment; DROP TABLE override;";
const sql = generateOverrideSeedSql([
{ source: 'eod', sourceId: 'BRK-B.US', validFrom: '2021-01-01', validTo: null, primaryIsin: 'US0846707026', mic: 'XNYS', tickerRoot: 'BRK', classSuffix: 'B', currency: 'USD', reason: trickyReason, createdBy: 'director' },
{ source: 'eod', sourceId: 'BRK-B.US', validFrom: '2020-01-01', validTo: '2020-12-31', primaryIsin: 'US0846707026', mic: 'XNYS', tickerRoot: 'BRK', classSuffix: 'A', currency: 'USD', reason: 'pre-split mapping', createdBy: 'director' },
{ source: 'qm', sourceId: "AAPL'Q", primaryIsin: 'US0378331005', mic: 'XNAS', tickerRoot: 'AAPL', classSuffix: '', currency: 'USD', reason: 'default dates', createdBy: 'qa' },
]);
await f.pool.query(sql);
const rows = (
await f.pool.query<{ source: string; source_id: string; valid_from: string; valid_to: string | null; listing_id: number; reason: string }>(
`SELECT source, source_id, to_char(valid_from, 'YYYY-MM-DD') AS valid_from,
to_char(valid_to, 'YYYY-MM-DD') AS valid_to, listing_id, reason
FROM override ORDER BY source, source_id, valid_from`
)
).rows;
expect(rows).toEqual([
{ source: 'eod', source_id: 'BRK-B.US', valid_from: '2020-01-01', valid_to: '2020-12-31', listing_id: brkA.rows[0]?.listing_id ?? -1, reason: 'pre-split mapping' },
{ source: 'eod', source_id: 'BRK-B.US', valid_from: '2021-01-01', valid_to: null, listing_id: brkB.rows[0]?.listing_id ?? -1, reason: trickyReason },
{ source: 'qm', source_id: "AAPL'Q", valid_from: '1900-01-01', valid_to: null, listing_id: aaplListingId, reason: 'default dates' },
]);
});
test('re-seeding an existing override key keeps the originally stored listing_id (DO NOTHING, no overwrite)', async () => {
const f = await createIsolatedFixture();
const aaplListingId = await seedSingleListing(f.pool);
await f.pool.query(
`INSERT INTO override (source, source_id, valid_from, listing_id, reason, created_by)
VALUES ('eod', 'AAPL.US', DATE '1900-01-01', $1, 'original', 'director')`,
[aaplListingId]
);
const instrumentId = (await f.pool.query<{ instrument_id: number }>(`SELECT instrument_id FROM instrument`)).rows[0]?.instrument_id;
await f.pool.query(
`INSERT INTO listing (instrument_id, mic, ticker_root, class_suffix, currency) VALUES ($1, 'XNYS', 'AAPL', '', 'USD')`,
[instrumentId]
);
await f.pool.query(
generateOverrideSeedSql([
{ source: 'eod', sourceId: 'AAPL.US', primaryIsin: 'US0378331005', mic: 'XNYS', tickerRoot: 'AAPL', classSuffix: '', currency: 'USD', reason: 'replacement', createdBy: 'qa' },
])
);
const rows = (await f.pool.query<{ listing_id: number; reason: string }>('SELECT listing_id, reason FROM override')).rows;
expect(rows).toEqual([{ listing_id: aaplListingId, reason: 'original' }]);
});
});