test: cover overlapping portfolio imports
This commit is contained in:
@@ -8,6 +8,12 @@ const payload = {
|
||||
positions: [{ instrument: 'Test Bond', isin: 'RU0000000001', quantity: '1.000', price: '100.123456', valuation: '100.123456' }],
|
||||
trades: [{ instrument: 'Test Bond', isin: 'RU0000000001', concludedAt: '2026-08-10T10:00:00+03:00', side: 'Покупка', quantity: '1.000', settlementAmount: '100.123456' }],
|
||||
};
|
||||
const overlappingPayload = {
|
||||
...payload,
|
||||
reportPeriod: { from: '2026-08-10', to: '2026-08-25' },
|
||||
positions: [{ ...payload.positions[0], valuation: '120.000000' }],
|
||||
trades: [{ ...payload.trades[0], sourceId: 'second-trade', concludedAt: '2026-08-15T10:00:00+03:00', side: 'Продажа', quantity: '0.500', settlementAmount: '60.000000' }],
|
||||
};
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
@@ -17,6 +23,12 @@ async function run(): Promise<void> {
|
||||
assert.equal(second.duplicateTrades, 1);
|
||||
const rows = await pool.query('SELECT COUNT(*)::int AS count FROM portfolio_trades WHERE account_id = $1', [first.accountId]);
|
||||
assert.equal(rows.rows[0].count, 1);
|
||||
const overlapping = await importPortfolio(overlappingPayload);
|
||||
assert.equal(overlapping.importedTrades, 1);
|
||||
const reports = await pool.query('SELECT COUNT(*)::int AS count FROM portfolio_reports WHERE account_id = $1', [first.accountId]);
|
||||
assert.equal(reports.rows[0].count, 2);
|
||||
const trades = await pool.query('SELECT COUNT(*)::int AS count FROM portfolio_trades WHERE account_id = $1', [first.accountId]);
|
||||
assert.equal(trades.rows[0].count, 2);
|
||||
console.log('portfolio import SQL: OK');
|
||||
} finally {
|
||||
await pool.query("DELETE FROM portfolio_trades WHERE account_id IN (SELECT id FROM accounts WHERE bank = 'PORTFOLIO_TEST' AND account_number = 'portfolio-test')");
|
||||
|
||||
Reference in New Issue
Block a user