T-91: tests
This commit is contained in:
parent
50e6da57f0
commit
4b51bea15a
2 changed files with 202 additions and 0 deletions
|
|
@ -1323,4 +1323,68 @@ describe('persistSecurityMaster unit tests', () => {
|
|||
expect(result.providerMappingsDeletedStaleFallback).toBe(0);
|
||||
expect(result.providerMappingsInserted).toBe(3);
|
||||
});
|
||||
|
||||
test('rolls back instead of committing when a step after the stale-fallback DELETE fails', async () => {
|
||||
const stageA = emptyStageA();
|
||||
stageA.instruments.push({
|
||||
primaryIsin: 'US0378331005',
|
||||
primaryCusip: '037833100',
|
||||
issuerCountry: 'US',
|
||||
canonicalName: 'Apple Inc.',
|
||||
members: [{ source: 'eod', sourceId: 'AAPL.US', currency: 'USD', method: 'tier1_isin' }],
|
||||
});
|
||||
const key = {
|
||||
primaryIsin: 'US0378331005',
|
||||
mic: 'XNAS',
|
||||
tickerRoot: 'AAPL',
|
||||
classSuffix: '',
|
||||
currency: 'USD',
|
||||
};
|
||||
const stageB = emptyStageB();
|
||||
stageB.listings.push({
|
||||
...key,
|
||||
ibConid: null,
|
||||
ibPrimaryExchange: null,
|
||||
listedFrom: '2012-05-18',
|
||||
listedTo: null,
|
||||
});
|
||||
stageB.providerMappings.push({
|
||||
source: 'eod',
|
||||
sourceId: 'AAPL.US',
|
||||
listingKey: key,
|
||||
method: 'tier1_isin',
|
||||
validFrom: '2012-05-18',
|
||||
validTo: null,
|
||||
});
|
||||
|
||||
const base = createMockClient();
|
||||
const queries: RecordedQuery[] = [];
|
||||
const client: SecurityMasterQueryable = {
|
||||
release: () => undefined,
|
||||
async query<Row = Record<string, unknown>>(text: string, values?: readonly unknown[]) {
|
||||
if (text.includes('WITH enforced AS')) {
|
||||
queries.push({ text, values });
|
||||
throw new Error('override enforcement failed');
|
||||
}
|
||||
const res = await base.client.query<Row>(text, values);
|
||||
queries.push({ text, values });
|
||||
return res;
|
||||
},
|
||||
};
|
||||
|
||||
await expect(
|
||||
persistSecurityMaster(client, {
|
||||
stageA,
|
||||
stageB,
|
||||
securityTypeByIsin: new Map<string, SecurityType>([['US0378331005', 'common']]),
|
||||
})
|
||||
).rejects.toThrow('override enforcement failed');
|
||||
|
||||
const texts = queries.map(q => q.text.trim());
|
||||
const deleteIdx = texts.findIndex(t => t.includes('DELETE FROM provider_mapping'));
|
||||
expect(texts[0]).toBe('BEGIN');
|
||||
expect(deleteIdx).toBeGreaterThan(0);
|
||||
expect(texts.at(-1)).toBe('ROLLBACK');
|
||||
expect(texts).not.toContain('COMMIT');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue