mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-31 00:46:26 +00:00
40 lines
1.2 KiB
PHP
40 lines
1.2 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()
|
|
{
|
|
// Arrange
|
|
$paymentGateway = new FakePaymentGateway;
|
|
$this->app->instance(PaymentGateway::class, $paymentGateway);
|
|
|
|
$concert = factory(Concert::class)->create(['ticket_price' => 3250]);
|
|
|
|
// Act
|
|
$this->json('POST', "/concerts/{$concert->id}/orders", [
|
|
'email' => 'john@example.com',
|
|
'ticket_quantity' => 3,
|
|
'payment_token' => $paymentGateway->getValidTestToken(),
|
|
]);
|
|
|
|
// Assert
|
|
$this->assertResponseStatus(201);
|
|
|
|
$this->assertEquals(9750, $paymentGateway->totalCharges());
|
|
|
|
$order = $concert->orders()->where('email', 'john@example.com')->first();
|
|
$this->assertNotNull($order);
|
|
$this->assertEquals(3, $order->tickets()->count());
|
|
}
|
|
}
|