From da5523e9722a2d07ae8d4e1d8a42f10df2951c36 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Tue, 12 Dec 2017 17:26:27 -0600 Subject: [PATCH] test for multiple bids on same flight with block setting enabled --- app/Services/FlightService.php | 11 +++++++---- phpvms.iml | 13 ------------- tests/FlightTest.php | 20 ++++++++++++++++++++ tests/TestCase.php | 2 +- tests/data/base.yml | 15 ++++++++++++++- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/app/Services/FlightService.php b/app/Services/FlightService.php index cdf24ae5..3a65d3b2 100644 --- a/app/Services/FlightService.php +++ b/app/Services/FlightService.php @@ -20,9 +20,9 @@ class FlightService extends BaseService * Allow a user to bid on a flight. Check settings and all that good stuff * @param Flight $flight * @param User $user - * @return UserBid + * @return UserBid|null */ - public function addBid(Flight $flight, User $user): UserBid + public function addBid(Flight $flight, User $user) { # If it's already been bid on, then it can't be bid on again if($flight->has_bid && setting('bids.disable_flight_on_bid')) { @@ -74,7 +74,10 @@ class FlightService extends BaseService $user_bid->forceDelete(); } - $flight->has_bid = false; - $flight->save(); + # Only flip the flag if there are no bids left for this flight + if(!UserBid::where('flight_id', $flight->id)->exists()) { + $flight->has_bid = false; + $flight->save(); + } } } diff --git a/phpvms.iml b/phpvms.iml index 34e6cb40..8b7db6af 100644 --- a/phpvms.iml +++ b/phpvms.iml @@ -306,19 +306,6 @@ - - - - - - - - - - - - -