mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-30 07:46:23 +00:00
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
use App\Order;
|
|
use App\Concert;
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
class OrderTest extends TestCase
|
|
{
|
|
use DatabaseMigrations;
|
|
|
|
/** @test */
|
|
function converting_to_an_array()
|
|
{
|
|
$concert = factory(Concert::class)->create(['ticket_price' => 1200])->addTickets(5);
|
|
$order = $concert->orderTickets('jane@example.com', 5);
|
|
|
|
$result = $order->toArray();
|
|
|
|
$this->assertEquals([
|
|
'email' => 'jane@example.com',
|
|
'ticket_quantity' => 5,
|
|
'amount' => 6000,
|
|
], $result);
|
|
}
|
|
|
|
/** @test */
|
|
function tickets_are_released_when_an_order_is_cancelled()
|
|
{
|
|
$concert = factory(Concert::class)->create()->addTickets(10);
|
|
$order = $concert->orderTickets('jane@example.com', 5);
|
|
$this->assertEquals(5, $concert->ticketsRemaining());
|
|
|
|
$order->cancel();
|
|
|
|
$this->assertEquals(10, $concert->ticketsRemaining());
|
|
$this->assertNull(Order::find($order->id));
|
|
}
|
|
}
|