mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-10 09:05:48 +02:00
Work on interest system
This commit is contained in:
parent
a1345f9138
commit
de7b5cd960
9 changed files with 196 additions and 59 deletions
|
|
@ -6,6 +6,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||
from database.crud import users
|
||||
from database.schemas import (
|
||||
Bank,
|
||||
BankSavings,
|
||||
UforaAnnouncement,
|
||||
UforaCourse,
|
||||
UforaCourseAlias,
|
||||
|
|
@ -38,6 +39,14 @@ async def bank(postgres: AsyncSession, user: User) -> Bank:
|
|||
return _bank
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def savings(postgres: AsyncSession, user: User) -> BankSavings:
|
||||
"""Fixture to fetch the test user's savings account"""
|
||||
_savings = user.savings
|
||||
await postgres.refresh(_savings)
|
||||
return _savings
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def ufora_course(postgres: AsyncSession) -> UforaCourse:
|
||||
"""Fixture to create a course"""
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||
|
||||
from database.crud import currency as crud
|
||||
from database.exceptions import currency as exceptions
|
||||
from database.schemas import Bank
|
||||
from database.schemas import Bank, BankSavings
|
||||
|
||||
|
||||
async def test_add_dinks(postgres: AsyncSession, bank: Bank):
|
||||
|
|
@ -40,40 +40,43 @@ async def test_claim_nightly_unavailable(postgres: AsyncSession, bank: Bank):
|
|||
assert bank.dinks == crud.NIGHTLY_AMOUNT
|
||||
|
||||
|
||||
async def test_invest(postgres: AsyncSession, bank: Bank):
|
||||
"""Test investing some Dinks"""
|
||||
async def test_save(postgres: AsyncSession, bank: Bank, savings: BankSavings):
|
||||
"""Test saving some Dinks"""
|
||||
bank.dinks = 100
|
||||
postgres.add(bank)
|
||||
await postgres.commit()
|
||||
|
||||
await crud.invest(postgres, bank.user_id, 20)
|
||||
await crud.save(postgres, bank.user_id, 20, bank=bank, savings=savings)
|
||||
await postgres.refresh(bank)
|
||||
await postgres.refresh(savings)
|
||||
|
||||
assert bank.dinks == 80
|
||||
assert bank.invested == 20
|
||||
assert savings.saved == 20
|
||||
|
||||
|
||||
async def test_invest_all(postgres: AsyncSession, bank: Bank):
|
||||
"""Test investing all dinks"""
|
||||
async def test_save_all(postgres: AsyncSession, bank: Bank, savings: BankSavings):
|
||||
"""Test saving all dinks"""
|
||||
bank.dinks = 100
|
||||
postgres.add(bank)
|
||||
await postgres.commit()
|
||||
|
||||
await crud.invest(postgres, bank.user_id, "all")
|
||||
await crud.save(postgres, bank.user_id, "all", bank=bank, savings=savings)
|
||||
await postgres.refresh(bank)
|
||||
await postgres.refresh(savings)
|
||||
|
||||
assert bank.dinks == 0
|
||||
assert bank.invested == 100
|
||||
assert savings.saved == 100
|
||||
|
||||
|
||||
async def test_invest_more_than_owned(postgres: AsyncSession, bank: Bank):
|
||||
"""Test investing more Dinks than you own"""
|
||||
async def test_save_more_than_owned(postgres: AsyncSession, bank: Bank, savings: BankSavings):
|
||||
"""Test saving more Dinks than you own"""
|
||||
bank.dinks = 100
|
||||
postgres.add(bank)
|
||||
await postgres.commit()
|
||||
|
||||
await crud.invest(postgres, bank.user_id, 200)
|
||||
await crud.save(postgres, bank.user_id, 200, bank=bank, savings=savings)
|
||||
await postgres.refresh(bank)
|
||||
await postgres.refresh(savings)
|
||||
|
||||
assert bank.dinks == 0
|
||||
assert bank.invested == 100
|
||||
assert savings.saved == 100
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue