From f4b264407580cea8e12ba101b01f48ff72637566 Mon Sep 17 00:00:00 2001 From: elof-dev Date: Wed, 22 Oct 2025 16:04:59 +0700 Subject: [PATCH] Fix issue #6 : correct purchasePlaces() and add unit tests - Added missing line in purchasePlaces() to decrease club points after a valid booking - Created test to verify: - club points decrease when booking succeeds --- server.py | 1 + .../unit/test_booking_decrease_club_points.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/unit/test_booking_decrease_club_points.py diff --git a/server.py b/server.py index 7ea6e6c3c..d5cce5c41 100644 --- a/server.py +++ b/server.py @@ -72,6 +72,7 @@ def purchasePlaces(): return render_template('welcome.html', club=club, competitions=competitions) competition['numberOfPlaces'] = int(competition['numberOfPlaces']) - placesRequired + club['points'] = club_points - placesRequired flash('Great - booking complete!') return render_template('welcome.html', club=club, competitions=competitions) diff --git a/tests/unit/test_booking_decrease_club_points.py b/tests/unit/test_booking_decrease_club_points.py new file mode 100644 index 000000000..d1c54da16 --- /dev/null +++ b/tests/unit/test_booking_decrease_club_points.py @@ -0,0 +1,27 @@ +import server + +""" +Unit test file to verify that club points are correctly updated after booking. + +Test 1: Club has 10 points, books 3 places, points should decrease by 3. + - status code 200 + - success message "Great - booking complete!" + - club points decrease by 3 + +""" + + +def test_club_points_decrease_after_booking(client): + server.clubs = [{"name": "Club A", "points": "10"}] + server.competitions = [{"name": "Comp 1", "numberOfPlaces": "20"}] + + response = client.post('/purchasePlaces', data={ + 'competition': 'Comp 1', + 'club': 'Club A', + 'places': '3' + }) + + assert response.status_code == 200 + assert b"Great - booking complete!" in response.data + assert int(server.clubs[0]['points']) == 7 +