From 91672fef0b92d133676126aedba945c5cc6028f0 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Sun, 20 Nov 2016 17:46:56 -0500 Subject: [PATCH] 6.6 - Uh Oh, a Segault --- tests/features/PurchaseTicketsTest.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/features/PurchaseTicketsTest.php b/tests/features/PurchaseTicketsTest.php index 8d631ba..177d985 100644 --- a/tests/features/PurchaseTicketsTest.php +++ b/tests/features/PurchaseTicketsTest.php @@ -105,13 +105,31 @@ class PurchaseTicketsTest extends TestCase /** @test */ function cannot_purchase_tickets_another_customer_is_already_trying_to_purchase() { - $concert = factory(Concert::class)->states('published')->create()->addTickets(3); + $concert = factory(Concert::class)->states('published')->create([ + 'ticket_price' => 1200 + ])->addTickets(3); + + $this->paymentGateway->beforeFirstCharge(function ($paymentGateway) use ($concert) { + $this->orderTickets($concert, [ + 'email' => 'personB@example.com', + 'ticket_quantity' => 1, + 'payment_token' => $this->paymentGateway->getValidTestToken(), + ]); + + $this->assertResponseStatus(422); + $this->assertFalse($concert->hasOrderFor('personB@example.com')); + $this->assertEquals(0, $this->paymentGateway->totalCharges()); + }); $this->orderTickets($concert, [ 'email' => 'personA@example.com', - 'ticket_quantity' => 51, + 'ticket_quantity' => 3, 'payment_token' => $this->paymentGateway->getValidTestToken(), ]); + + $this->assertEquals(3600, $this->paymentGateway->totalCharges()); + $this->assertTrue($concert->hasOrderFor('personA@example.com')); + $this->assertEquals(3, $concert->ordersFor('personA@example.com')->first()->ticketQuantity()); } /** @test */