From ce22ff1ec609a2dafb65525a63a59db513172362 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Sun, 13 Nov 2016 16:38:01 -0500 Subject: [PATCH] 3.1 - Outlining the First Test Case --- tests/features/PurchaseTicketsTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/features/PurchaseTicketsTest.php b/tests/features/PurchaseTicketsTest.php index 625b17b..9adaa87 100644 --- a/tests/features/PurchaseTicketsTest.php +++ b/tests/features/PurchaseTicketsTest.php @@ -79,6 +79,25 @@ class PurchaseTicketsTest extends TestCase $this->assertNull($order); } + /** @test */ + function cannot_purchase_more_tickets_than_remain() + { + $concert = factory(Concert::class)->states('published')->create(); + $concert->addTickets(50); + + $this->orderTickets($concert, [ + 'email' => 'john@example.com', + 'ticket_quantity' => 51, + 'payment_token' => $this->paymentGateway->getValidTestToken(), + ]); + + $this->assertResponseStatus(422); + $order = $concert->orders()->where('email', 'john@example.com')->first(); + $this->assertNull($order); + $this->assertEquals(0, $this->paymentGateway->totalCharges()); + $this->assertEquals(50, $concert->ticketsRemaining()); + } + /** @test */ function email_is_required_to_purchase_tickets() {