Fix payments chart (#1851)
* feat: payment history endpoint * test payment history * use new endpoint in frontend * refactor tests
This commit is contained in:
parent
f526a93b6c
commit
4c16675b3b
7 changed files with 243 additions and 90 deletions
|
|
@ -1,5 +1,6 @@
|
|||
# ruff: noqa: E402
|
||||
import asyncio
|
||||
from time import time
|
||||
|
||||
import uvloop
|
||||
|
||||
|
|
@ -11,11 +12,16 @@ from fastapi.testclient import TestClient
|
|||
from httpx import AsyncClient
|
||||
|
||||
from lnbits.app import create_app
|
||||
from lnbits.core.crud import create_account, create_wallet, get_user
|
||||
from lnbits.core.crud import (
|
||||
create_account,
|
||||
create_wallet,
|
||||
get_user,
|
||||
update_payment_status,
|
||||
)
|
||||
from lnbits.core.models import CreateInvoice
|
||||
from lnbits.core.services import update_wallet_balance
|
||||
from lnbits.core.views.api import api_payments_create_invoice
|
||||
from lnbits.db import Database
|
||||
from lnbits.db import DB_TYPE, SQLITE, Database
|
||||
from lnbits.settings import settings
|
||||
from tests.helpers import (
|
||||
clean_database,
|
||||
|
|
@ -173,6 +179,31 @@ async def real_invoice():
|
|||
del invoice
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
async def fake_payments(client, adminkey_headers_from):
|
||||
# Because sqlite only stores timestamps with milliseconds
|
||||
# we have to wait a second to ensure a different timestamp than previous invoices
|
||||
if DB_TYPE == SQLITE:
|
||||
await asyncio.sleep(1)
|
||||
ts = time()
|
||||
|
||||
fake_data = [
|
||||
CreateInvoice(amount=10, memo="aaaa", out=False),
|
||||
CreateInvoice(amount=100, memo="bbbb", out=False),
|
||||
CreateInvoice(amount=1000, memo="aabb", out=False),
|
||||
]
|
||||
|
||||
for invoice in fake_data:
|
||||
response = await client.post(
|
||||
"/api/v1/payments", headers=adminkey_headers_from, json=invoice.dict()
|
||||
)
|
||||
assert response.is_success
|
||||
await update_payment_status(response.json()["checking_id"], pending=False)
|
||||
|
||||
params = {"time[ge]": ts, "time[le]": time()}
|
||||
return fake_data, params
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
async def hold_invoice():
|
||||
invoice = get_hold_invoice(100)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue