42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from app.business.leave_calc import compute_leave_used, get_or_create_balance
|
|
from app.models import WorkEntry, LeaveBalance
|
|
from app import db
|
|
from datetime import date
|
|
import sqlalchemy as sa
|
|
|
|
|
|
def test_compute_leave_used_conges(app):
|
|
with app.app_context():
|
|
entries = [
|
|
WorkEntry(date=date(2025, 1, 6), day_type="CONGE"),
|
|
WorkEntry(date=date(2025, 1, 7), day_type="CONGE"),
|
|
WorkEntry(date=date(2025, 1, 8), day_type="RTT"),
|
|
WorkEntry(date=date(2025, 1, 9), day_type="WORK"),
|
|
]
|
|
for e in entries:
|
|
db.session.add(e)
|
|
db.session.commit()
|
|
|
|
used = compute_leave_used(2025)
|
|
assert used["conges"] == 2
|
|
assert used["rtt"] == 1
|
|
|
|
|
|
def test_get_or_create_balance_creates_default(app):
|
|
with app.app_context():
|
|
balance = get_or_create_balance(2025)
|
|
assert balance.year == 2025
|
|
assert balance.conges_total == 28
|
|
assert balance.rtt_total == 18
|
|
|
|
|
|
def test_get_or_create_balance_returns_existing(app):
|
|
with app.app_context():
|
|
existing = LeaveBalance(year=2025, conges_total=25, rtt_total=15)
|
|
db.session.add(existing)
|
|
db.session.commit()
|
|
|
|
balance = get_or_create_balance(2025)
|
|
assert balance.conges_total == 25
|
|
assert balance.rtt_total == 15
|