feat: add reconciliation and ledger views to web dashboard with test suite
All checks were successful
Deploy to K8s / deploy (push) Successful in 11s

This commit is contained in:
Jan Novak
2026-03-02 14:29:48 +01:00
parent d719383c9c
commit 535e1bb772
5 changed files with 713 additions and 2 deletions

78
tests/test_app.py Normal file
View File

@@ -0,0 +1,78 @@
import unittest
from unittest.mock import patch, MagicMock
from app import app
class TestWebApp(unittest.TestCase):
def setUp(self):
# Configure app for testing
app.config['TESTING'] = True
self.client = app.test_client()
@patch('app.get_members_with_fees')
def test_index_page(self, mock_get_members):
"""Test that / returns the refresh meta tag"""
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
self.assertIn(b'url=/fees', response.data)
@patch('app.get_members_with_fees')
def test_fees_route(self, mock_get_members):
"""Test that /fees returns 200 and renders the dashboard"""
# Mock attendance data
mock_get_members.return_value = (
[('Test Member', 'A', {'2026-01': (750, 4)})],
['2026-01']
)
response = self.client.get('/fees')
self.assertEqual(response.status_code, 200)
self.assertIn(b'FUJ Fees Dashboard', response.data)
self.assertIn(b'Test Member', response.data)
@patch('app.fetch_sheet_data')
@patch('app.get_members_with_fees')
def test_reconcile_route(self, mock_get_members, mock_fetch_sheet):
"""Test that /reconcile returns 200 and shows matches"""
# Mock attendance data
mock_get_members.return_value = (
[('Test Member', 'A', {'2026-01': (750, 4)})],
['2026-01']
)
# Mock sheet data - include all keys required by reconcile
mock_fetch_sheet.return_value = [{
'date': '2026-01-01',
'amount': 750,
'person': 'Test Member',
'purpose': '2026-01',
'message': 'test payment',
'sender': 'External Bank User',
'inferred_amount': 750
}]
response = self.client.get('/reconcile')
self.assertEqual(response.status_code, 200)
self.assertIn(b'Payment Reconciliation', response.data)
self.assertIn(b'Test Member', response.data)
self.assertIn(b'OK', response.data)
@patch('app.fetch_sheet_data')
def test_payments_route(self, mock_fetch_sheet):
"""Test that /payments returns 200 and groups transactions"""
# Mock sheet data
mock_fetch_sheet.return_value = [{
'date': '2026-01-01',
'amount': 750,
'person': 'Test Member',
'purpose': '2026-01',
'message': 'Direct Member Payment',
'sender': 'External Bank User'
}]
response = self.client.get('/payments')
self.assertEqual(response.status_code, 200)
self.assertIn(b'Payments Ledger', response.data)
self.assertIn(b'Test Member', response.data)
self.assertIn(b'Direct Member Payment', response.data)
if __name__ == '__main__':
unittest.main()