feat(пополнение): таблица topups, ключ ext_ref, зачисление и возврат одной транзакцией

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
anor
2026-10-28 14:42:53 +10:00
co-authored by Claude Opus 5.5
parent b6cbaf3ca7
commit c204c38843
2 changed files with 198 additions and 21 deletions
+13 -3
View File
@@ -67,7 +67,7 @@ def test_migration_on_old_schema_keeps_rows(tmp_path, monkeypatch):
with _db._conn() as c:
cols = {r[1] for r in c.execute("PRAGMA table_info(account_entries)")}
assert "ext_ref" in cols
assert c.execute("SELECT amount_kop, ext_ref FROM account_entries").fetchall() == [(5000, None)]
assert [tuple(r) for r in c.execute("SELECT amount_kop, ext_ref FROM account_entries")] == [(5000, None)]
assert c.execute("SELECT COUNT(*) FROM topups").fetchone()[0] == 0
@@ -204,11 +204,21 @@ def test_refund_over_remaining_refused(db):
tid = _pending(db)
db.credit_topup(tid, 100_000, "{}")
db.refund_topup(tid, 60_000, "admin")
with pytest.raises(db.AccountEntryError, match="больше"):
with pytest.raises(db.AccountEntryError, match="можно вернуть не больше 400.00"):
db.refund_topup(tid, 50_000, "admin")
assert len(_entries(db)) == 2
def test_refund_entries_capped_by_credit_at_entry_level(db):
"""Правило записи на счёт само держит «возвратов не больше взноса» для refund:* — даже в
обход refund_topup. Порча: снять сравнение суммы возвратов со взносом."""
eid = db.add_account_entry(USER, 100.0, "", "topup", ext_ref="topup:robokassa:5")
db.add_account_entry(USER, -60.0, "", "topup", reverses=eid, ext_ref="refund:robokassa:5:1")
with pytest.raises(db.AccountEntryError, match="больше суммы платежа"):
db.add_account_entry(USER, -41.0, "", "topup", reverses=eid, ext_ref="refund:robokassa:5:2")
db.add_account_entry(USER, -40.0, "", "topup", reverses=eid, ext_ref="refund:robokassa:5:2")
def test_sweep_refund_only_when_nothing_refunded(db):
"""Обход статусов пишет полный возврат только если вручную ещё ничего не возвращали —
обход и кнопка не задваивают. Порча: обход без проверки refunded_kop."""
@@ -217,7 +227,7 @@ def test_sweep_refund_only_when_nothing_refunded(db):
db.refund_topup(tid, 30_000, "admin")
assert db.refund_topup(tid, 100_000, "sweep") is None
assert db.get_topup(tid)["refunded_kop"] == 30_000
tid2 = _pending(db, pid="11")
tid2 = _pending(db, kop=50_000, pid="11")
db.credit_topup(tid2, 50_000, "{}")
assert db.refund_topup(tid2, 50_000, "sweep")["refunded_kop"] == 50_000
assert db.refund_topup(tid2, 50_000, "sweep") is None