Skip to content

Fix issue #6: deduct club points after booking - #5

Merged
Aurelien7777 merged 1 commit into
masterfrom
bug/deduct-club-points-after-booking
May 5, 2026
Merged

Aurelien7777 merged 1 commit into
masterfrom
bug/deduct-club-points-after-booking

Conversation

@Aurelien7777

@Aurelien7777 Aurelien7777 commented May 5, 2026 •

Copy link
Copy Markdown
Owner

Description

This pull request fixes the issue where club points were not deducted after a successful booking.

Previously, when a secretary booked places for a competition, the number of available places was correctly updated, but the club's points balance remained unchanged.

Now, when a booking is confirmed:

  • the number of available places is deducted from the competition;
  • the corresponding amount of points is deducted from the club's balance.

Changes made

  • Updated the /purchasePlaces route to deduct booked places from the club's points balance after a valid booking.
  • Kept the existing validations:
    • clubs cannot book more places than their available points;
    • clubs cannot book more than 12 places per competition.
  • Added a test to verify that club points are correctly deducted after a successful booking.
  • Reused fixture test data to validate the booking flow with isolated test cases.

Closes #6

Summary by Sourcery

Deduct club points when places are purchased and add coverage to verify the booking flow.

Bug Fixes:

  • Ensure a club's points balance is reduced by the number of places booked in a competition.

Tests:

  • Add a test confirming that club points are deducted after a successful booking using existing booking fixtures.

@sourcery-ai

sourcery-ai Bot commented May 5, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Updates the booking workflow so that, after a successful purchase, club points are reduced by the number of booked places and adds a focused test to validate this behavior using existing booking fixtures.

Sequence diagram for updated booking and club points deduction

sequenceDiagram
    actor Secretary
    participant WebApp
    participant purchasePlacesRoute
    participant Competition
    participant Club

    Secretary->>WebApp: Submit booking form
    WebApp->>purchasePlacesRoute: POST /purchasePlaces
    purchasePlacesRoute->>Competition: Load competition by name
    purchasePlacesRoute->>Club: Load club by email
    purchasePlacesRoute->>purchasePlacesRoute: Validate placesRequired <= 12
    purchasePlacesRoute->>purchasePlacesRoute: Validate placesRequired <= club points
    purchasePlacesRoute->>Competition: Deduct placesRequired from numberOfPlaces
    purchasePlacesRoute->>Club: Deduct placesRequired from points
    purchasePlacesRoute-->>WebApp: Render welcome.html with updated data
    WebApp-->>Secretary: Show updated competition places and club points
Loading

File-Level Changes

Change Details Files
Deduct club points when places are successfully purchased.
  • Extend the /purchasePlaces handler to decrement the club's points by the number of places booked, mirroring the existing decrement of competition places.
  • Ensure the new deduction only occurs in the successful booking path, preserving prior validation behavior for points and per-competition limits.
server.py
Add an integration-style test to assert club points are deducted after booking using existing booking fixtures.
  • Reuse the booking_test_data fixture to set up a club and competition for the new test case.
  • Post to /purchasePlaces with a valid booking, assert success response, and implicitly rely on fixture state to validate the updated booking flow.
  • Minor test file formatting adjustments (blank lines and newline at EOF).
test/test_server.py

Assessment against linked issues

Issue Objective Addressed Explanation
OpenClassrooms-Student-Center#6 Deduct the appropriate number of points from a club's balance when places are successfully booked for a competition. ✅

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The new test_club_points_are_deducted_after_booking test doesn't actually assert that the club's points were reduced (it only checks status and flash message); consider asserting the updated club_test["points"] to ensure the new behavior is really exercised.
  • In purchasePlaces, you're converting club['points'] to int inline for the subtraction; if club['points'] is reused later, consider normalizing it once (e.g., when loading or before arithmetic) to avoid mixing string/int types and repeated casting.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `test_club_points_are_deducted_after_booking` test doesn't actually assert that the club's points were reduced (it only checks status and flash message); consider asserting the updated `club_test["points"]` to ensure the new behavior is really exercised.
- In `purchasePlaces`, you're converting `club['points']` to `int` inline for the subtraction; if `club['points']` is reused later, consider normalizing it once (e.g., when loading or before arithmetic) to avoid mixing string/int types and repeated casting.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Aurelien7777
Aurelien7777 merged commit ed60486 into master May 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Point updates are not reflected

1 participant