Files
ticketbeast/tests/features/PurchaseTicketsTest.php
2016-11-09 10:35:42 -05:00

44 lines
1.3 KiB
PHP

<?php
use App\Concert;
use App\Billing\PaymentGateway;
use App\Billing\FakePaymentGateway;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class PurchaseTicketsTest extends TestCase
{
use DatabaseMigrations;
/** @test */
function customer_can_purchase_concert_tickets()
{
$paymentGateway = new FakePaymentGateway;
$this->app->instance(PaymentGateway::class, $paymentGateway);
// Arrange
// Create a concert
$concert = factory(Concert::class)->create(['ticket_price' => 3250]);
// Act
// Purchase concert tickets
$this->json('POST', "/concerts/{$concert->id}/orders", [
'email' => 'john@example.com',
'ticket_quantity' => 3,
'payment_token' => $paymentGateway->getValidTestToken(),
]);
// Assert
$this->assertResponseStatus(201);
// Make sure the customer was charged the correct amount
$this->assertEquals(9750, $paymentGateway->totalCharges());
// Make sure that an order exists for this customer
$order = $concert->orders()->where('email', 'john@example.com')->first();
$this->assertNotNull($order);
$this->assertEquals(3, $order->tickets->count());
}
}