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() {