test for multiple bids on same flight with block setting enabled
This commit is contained in:
@@ -20,9 +20,9 @@ class FlightService extends BaseService
|
|||||||
* Allow a user to bid on a flight. Check settings and all that good stuff
|
* Allow a user to bid on a flight. Check settings and all that good stuff
|
||||||
* @param Flight $flight
|
* @param Flight $flight
|
||||||
* @param User $user
|
* @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 it's already been bid on, then it can't be bid on again
|
||||||
if($flight->has_bid && setting('bids.disable_flight_on_bid')) {
|
if($flight->has_bid && setting('bids.disable_flight_on_bid')) {
|
||||||
@@ -74,7 +74,10 @@ class FlightService extends BaseService
|
|||||||
$user_bid->forceDelete();
|
$user_bid->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
$flight->has_bid = false;
|
# Only flip the flag if there are no bids left for this flight
|
||||||
$flight->save();
|
if(!UserBid::where('flight_id', $flight->id)->exists()) {
|
||||||
|
$flight->has_bid = false;
|
||||||
|
$flight->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
phpvms.iml
13
phpvms.iml
@@ -306,19 +306,6 @@
|
|||||||
</SOURCES>
|
</SOURCES>
|
||||||
</library>
|
</library>
|
||||||
</orderEntry>
|
</orderEntry>
|
||||||
<orderEntry type="module-library">
|
|
||||||
<library name="PHARS">
|
|
||||||
<CLASSES>
|
|
||||||
<root url="phar://$MODULE_DIR$/vendor/phar-io/manifest/tests/_fixture/test.phar/" />
|
|
||||||
<root url="phar://$MODULE_DIR$/vendor/phpunit/phpunit/tests/_files/phpunit-example-extension/tools/phpunit.d/phpunit-example-extension-1.0.1.phar/" />
|
|
||||||
</CLASSES>
|
|
||||||
<JAVADOC />
|
|
||||||
<SOURCES>
|
|
||||||
<root url="phar://$MODULE_DIR$/vendor/phar-io/manifest/tests/_fixture/test.phar/" />
|
|
||||||
<root url="phar://$MODULE_DIR$/vendor/phpunit/phpunit/tests/_files/phpunit-example-extension/tools/phpunit.d/phpunit-example-extension-1.0.1.phar/" />
|
|
||||||
</SOURCES>
|
|
||||||
</library>
|
|
||||||
</orderEntry>
|
|
||||||
</component>
|
</component>
|
||||||
<component name="TemplatesService">
|
<component name="TemplatesService">
|
||||||
<option name="TEMPLATE_FOLDERS">
|
<option name="TEMPLATE_FOLDERS">
|
||||||
|
|||||||
@@ -114,4 +114,24 @@ class FlightTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals(0, sizeof($body));
|
$this->assertEquals(0, sizeof($body));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testMultipleBidsSingleFlight()
|
||||||
|
{
|
||||||
|
setting('bids.disable_flight_on_bid', true);
|
||||||
|
|
||||||
|
$user1 = User::find(1);
|
||||||
|
$user2 = User::find(2);
|
||||||
|
|
||||||
|
$flight_id = $this->addFlight();
|
||||||
|
$flight = Flight::find($flight_id);
|
||||||
|
|
||||||
|
# Put bid on the flight to block it off
|
||||||
|
$bid = $this->flightSvc->addBid($flight, $user1);
|
||||||
|
|
||||||
|
$bidRepeat = $this->flightSvc->addBid($flight, $user2);
|
||||||
|
$this->assertNull($bidRepeat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
protected $connectionsToTransact = ['testing'];
|
protected $connectionsToTransact = ['testing'];
|
||||||
|
|
||||||
protected static $auth_headers = [
|
protected static $auth_headers = [
|
||||||
'Authorization' => 'testapikey'
|
'Authorization' => 'testadminapikey'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct($name = null, array $data = [], $dataName = '') {
|
public function __construct($name = null, array $data = [], $dataName = '') {
|
||||||
|
|||||||
@@ -13,19 +13,32 @@ users:
|
|||||||
name: Admin User
|
name: Admin User
|
||||||
email: admin@phpvms.net
|
email: admin@phpvms.net
|
||||||
password: admin
|
password: admin
|
||||||
api_key: testapikey
|
api_key: testadminapikey
|
||||||
airline_id: 1
|
airline_id: 1
|
||||||
home_airport_id: KAUS
|
home_airport_id: KAUS
|
||||||
curr_airport_id: KAUS
|
curr_airport_id: KAUS
|
||||||
rank_id: 1
|
rank_id: 1
|
||||||
created_at: now
|
created_at: now
|
||||||
updated_at: now
|
updated_at: now
|
||||||
|
- id: 2
|
||||||
|
name: Test User
|
||||||
|
email: test@phpvms.net
|
||||||
|
password: test
|
||||||
|
api_key: testuserapikey
|
||||||
|
airline_id: 1
|
||||||
|
home_airport_id: KJFK
|
||||||
|
curr_airport_id: KJFK
|
||||||
|
rank_id: 1
|
||||||
|
created_at: now
|
||||||
|
updated_at: now
|
||||||
|
|
||||||
role_user:
|
role_user:
|
||||||
- user_id: 1
|
- user_id: 1
|
||||||
role_id: 1
|
role_id: 1
|
||||||
- user_id: 1
|
- user_id: 1
|
||||||
role_id: 2
|
role_id: 2
|
||||||
|
- user_id: 2
|
||||||
|
role_id: 2
|
||||||
|
|
||||||
ranks:
|
ranks:
|
||||||
- id: 1
|
- id: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user