Skip to content

Commit

Permalink
test for multiple bids on same flight with block setting enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Dec 12, 2017
1 parent 5428f43 commit da5523e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
11 changes: 7 additions & 4 deletions app/Services/FlightService.php
Expand Up @@ -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')) {
Expand Down Expand Up @@ -74,7 +74,10 @@ public function removeBid(Flight $flight, User $user)
$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();
}
}
}
13 changes: 0 additions & 13 deletions phpvms.iml
Expand Up @@ -306,19 +306,6 @@
</SOURCES>
</library>
</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 name="TemplatesService">
<option name="TEMPLATE_FOLDERS">
Expand Down
20 changes: 20 additions & 0 deletions tests/FlightTest.php
Expand Up @@ -114,4 +114,24 @@ public function testBids()

$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);
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Expand Up @@ -19,7 +19,7 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
protected $connectionsToTransact = ['testing'];

protected static $auth_headers = [
'Authorization' => 'testapikey'
'Authorization' => 'testadminapikey'
];

public function __construct($name = null, array $data = [], $dataName = '') {
Expand Down
15 changes: 14 additions & 1 deletion tests/data/base.yml
Expand Up @@ -13,19 +13,32 @@ users:
name: Admin User
email: admin@phpvms.net
password: admin
api_key: testapikey
api_key: testadminapikey
airline_id: 1
home_airport_id: KAUS
curr_airport_id: KAUS
rank_id: 1
created_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:
- user_id: 1
role_id: 1
- user_id: 1
role_id: 2
- user_id: 2
role_id: 2

ranks:
- id: 1
Expand Down

0 comments on commit da5523e

Please sign in to comment.