mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
86 - Deleting More Stale Code
This commit is contained in:
@@ -50,12 +50,6 @@ class Concert extends Model
|
||||
return $this->hasMany(Ticket::class);
|
||||
}
|
||||
|
||||
public function orderTickets($email, $ticketQuantity)
|
||||
{
|
||||
$tickets = $this->findTickets($ticketQuantity);
|
||||
return $this->createOrder($email, $tickets);
|
||||
}
|
||||
|
||||
public function reserveTickets($quantity, $email)
|
||||
{
|
||||
$tickets = $this->findTickets($quantity)->each(function ($ticket) {
|
||||
@@ -76,11 +70,6 @@ class Concert extends Model
|
||||
return $tickets;
|
||||
}
|
||||
|
||||
public function createOrder($email, $tickets)
|
||||
{
|
||||
return Order::forTickets($tickets, $email, $tickets->sum('price'));
|
||||
}
|
||||
|
||||
public function addTickets($quantity)
|
||||
{
|
||||
foreach (range(1, $quantity) as $i) {
|
||||
|
||||
@@ -71,5 +71,7 @@ $factory->define(App\Order::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'amount' => 5250,
|
||||
'email' => 'somebody@example.com',
|
||||
'confirmation_number' => 'ORDERCONFIRMATION1234',
|
||||
'card_last_four' => '1234',
|
||||
];
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ class CreateOrdersTable extends Migration
|
||||
$table->string('confirmation_number');
|
||||
$table->integer('amount');
|
||||
$table->string('email');
|
||||
$table->string('card_last_four')->nullable();
|
||||
$table->string('card_last_four');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Order;
|
||||
use App\Ticket;
|
||||
use App\Concert;
|
||||
use Carbon\Carbon;
|
||||
use App\Exceptions\NotEnoughTicketsException;
|
||||
@@ -55,17 +57,6 @@ class ConcertTest extends TestCase
|
||||
$this->assertFalse($publishedConcerts->contains($unpublishedConcert));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function can_order_concert_tickets()
|
||||
{
|
||||
$concert = factory(Concert::class)->create()->addTickets(3);
|
||||
|
||||
$order = $concert->orderTickets('jane@example.com', 3);
|
||||
|
||||
$this->assertEquals('jane@example.com', $order->email);
|
||||
$this->assertEquals(3, $order->ticketQuantity());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function can_add_tickets()
|
||||
{
|
||||
@@ -79,21 +70,21 @@ class ConcertTest extends TestCase
|
||||
/** @test */
|
||||
function tickets_remaining_does_not_include_tickets_associated_with_an_order()
|
||||
{
|
||||
$concert = factory(Concert::class)->create()->addTickets(50);
|
||||
$concert->orderTickets('jane@example.com', 30);
|
||||
$concert = factory(Concert::class)->create();
|
||||
$concert->tickets()->saveMany(factory(Ticket::class, 30)->create(['order_id' => 1]));
|
||||
$concert->tickets()->saveMany(factory(Ticket::class, 20)->create(['order_id' => null]));
|
||||
|
||||
$this->assertEquals(20, $concert->ticketsRemaining());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function trying_to_purchase_more_tickets_than_remain_throws_an_exception()
|
||||
function trying_to_reserve_more_tickets_than_remain_throws_an_exception()
|
||||
{
|
||||
$concert = factory(Concert::class)->create()->addTickets(10);
|
||||
|
||||
try {
|
||||
$concert->orderTickets('jane@example.com', 11);
|
||||
$reservation = $concert->reserveTickets(11, 'john@example.com');
|
||||
} catch (NotEnoughTicketsException $e) {
|
||||
$this->assertFalse($concert->hasOrderFor('jane@example.com'));
|
||||
$this->assertEquals(10, $concert->ticketsRemaining());
|
||||
return;
|
||||
}
|
||||
@@ -101,23 +92,6 @@ class ConcertTest extends TestCase
|
||||
$this->fail("Order succeeded even though there were not enough tickets remaining.");
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function cannot_order_tickets_that_have_already_been_purchased()
|
||||
{
|
||||
$concert = factory(Concert::class)->create()->addTickets(10);
|
||||
$concert->orderTickets('jane@example.com', 8);
|
||||
|
||||
try {
|
||||
$concert->orderTickets('john@example.com', 3);
|
||||
} catch (NotEnoughTicketsException $e) {
|
||||
$this->assertFalse($concert->hasOrderFor('john@example.com'));
|
||||
$this->assertEquals(2, $concert->ticketsRemaining());
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fail("Order succeeded even though there were not enough tickets remaining.");
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function can_reserve_available_tickets()
|
||||
{
|
||||
@@ -135,7 +109,8 @@ class ConcertTest extends TestCase
|
||||
function cannot_reserve_tickets_that_have_already_been_purchased()
|
||||
{
|
||||
$concert = factory(Concert::class)->create()->addTickets(3);
|
||||
$concert->orderTickets('jane@example.com', 2);
|
||||
$order = factory(Order::class)->create();
|
||||
$order->tickets()->saveMany($concert->tickets->take(2));
|
||||
|
||||
try {
|
||||
$concert->reserveTickets(2, 'john@example.com');
|
||||
|
||||
Reference in New Issue
Block a user