test: cover overlapping portfolio imports
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@family-budget/backend",
|
"name": "@family-budget/backend",
|
||||||
"version": "0.14.0",
|
"version": "0.14.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "tsx watch src/app.ts",
|
"dev": "tsx watch src/app.ts",
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ const payload = {
|
|||||||
positions: [{ instrument: 'Test Bond', isin: 'RU0000000001', quantity: '1.000', price: '100.123456', valuation: '100.123456' }],
|
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' }],
|
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> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
@@ -17,6 +23,12 @@ async function run(): Promise<void> {
|
|||||||
assert.equal(second.duplicateTrades, 1);
|
assert.equal(second.duplicateTrades, 1);
|
||||||
const rows = await pool.query('SELECT COUNT(*)::int AS count FROM portfolio_trades WHERE account_id = $1', [first.accountId]);
|
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);
|
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');
|
console.log('portfolio import SQL: OK');
|
||||||
} finally {
|
} 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')");
|
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