3.4 - Finishing the Feature Test

This commit is contained in:
Adam Wathan
2016-11-14 20:23:54 -05:00
parent 2ccc635f5f
commit f341608264
2 changed files with 9 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ use App\Concert;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Billing\PaymentGateway; use App\Billing\PaymentGateway;
use App\Billing\PaymentFailedException; use App\Billing\PaymentFailedException;
use App\Exceptions\NotEnoughTicketsException;
class ConcertOrdersController extends Controller class ConcertOrdersController extends Controller
{ {
@@ -27,12 +28,13 @@ class ConcertOrdersController extends Controller
]); ]);
try { try {
$this->paymentGateway->charge(request('ticket_quantity') * $concert->ticket_price, request('payment_token'));
$order = $concert->orderTickets(request('email'), request('ticket_quantity')); $order = $concert->orderTickets(request('email'), request('ticket_quantity'));
$this->paymentGateway->charge(request('ticket_quantity') * $concert->ticket_price, request('payment_token'));
return response()->json([], 201); return response()->json([], 201);
} catch (PaymentFailedException $e) { } catch (PaymentFailedException $e) {
return response()->json([], 422); return response()->json([], 422);
} catch (NotEnoughTicketsException $e) {
return response()->json([], 422);
} }
} }
} }

View File

@@ -33,6 +33,7 @@ class PurchaseTicketsTest extends TestCase
function customer_can_purchase_tickets_to_a_published_concert() function customer_can_purchase_tickets_to_a_published_concert()
{ {
$concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250]); $concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250]);
$concert->addTickets(3);
$this->orderTickets($concert, [ $this->orderTickets($concert, [
'email' => 'john@example.com', 'email' => 'john@example.com',
@@ -51,6 +52,7 @@ class PurchaseTicketsTest extends TestCase
function cannot_purchase_tickets_to_an_unpublished_concert() function cannot_purchase_tickets_to_an_unpublished_concert()
{ {
$concert = factory(Concert::class)->states('unpublished')->create(); $concert = factory(Concert::class)->states('unpublished')->create();
$concert->addTickets(3);
$this->orderTickets($concert, [ $this->orderTickets($concert, [
'email' => 'john@example.com', 'email' => 'john@example.com',
@@ -67,6 +69,7 @@ class PurchaseTicketsTest extends TestCase
function an_order_is_not_created_if_payment_fails() function an_order_is_not_created_if_payment_fails()
{ {
$concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250]); $concert = factory(Concert::class)->states('published')->create(['ticket_price' => 3250]);
$concert->addTickets(3);
$this->orderTickets($concert, [ $this->orderTickets($concert, [
'email' => 'john@example.com', 'email' => 'john@example.com',
@@ -82,6 +85,8 @@ class PurchaseTicketsTest extends TestCase
/** @test */ /** @test */
function cannot_purchase_more_tickets_than_remain() function cannot_purchase_more_tickets_than_remain()
{ {
$this->disableExceptionHandling();
$concert = factory(Concert::class)->states('published')->create(); $concert = factory(Concert::class)->states('published')->create();
$concert->addTickets(50); $concert->addTickets(50);