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 */