mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-03-02 16:59:21 +00:00
131 - Asserting Against Sort Order
This commit is contained in:
@@ -14,6 +14,7 @@ class PublishedConcertOrdersController extends Controller
|
|||||||
|
|
||||||
return view('backstage.published-concert-orders.index', [
|
return view('backstage.published-concert-orders.index', [
|
||||||
'concert' => $concert,
|
'concert' => $concert,
|
||||||
|
'orders' => $concert->orders()->latest()->take(10)->get(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,11 @@
|
|||||||
<h2 class="m-xs-b-2 text-lg">Recent Orders</h2>
|
<h2 class="m-xs-b-2 text-lg">Recent Orders</h2>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-section">
|
<div class="card-section">
|
||||||
|
@if($orders->isEmpty())
|
||||||
|
<div class="text-center">
|
||||||
|
No orders yet.
|
||||||
|
</div>
|
||||||
|
@else
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -71,17 +76,18 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach(range(1, 10) as $i)
|
@foreach($orders as $order)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ collect(['john', 'jane', 'dave', 'donna'])->random() }}@example.com</td>
|
<td>{{ $order->email }}</td>
|
||||||
<td>{{ rand(1, 4) }}</td>
|
<td>{{ $order->ticketQuantity() }}</td>
|
||||||
<td>${{ number_format(rand(5000, 15000) / 100, 2) }}</td>
|
<td>${{ number_format($order->amount / 100, 2) }}</td>
|
||||||
<td><span class="text-dark-soft">****</span> 4242</td>
|
<td><span class="text-dark-soft">****</span> {{ $order->card_last_four}}</td>
|
||||||
<td class="text-dark-soft">July 18, 2017 @ 12:37pm</td>
|
<td class="text-dark-soft">{{ $order->created_at->format('M j, Y @ g:ia') }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,28 +17,6 @@ class ViewConcertListTest extends TestCase
|
|||||||
{
|
{
|
||||||
use DatabaseMigrations;
|
use DatabaseMigrations;
|
||||||
|
|
||||||
protected function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
Collection::macro('assertContains', function ($value) {
|
|
||||||
Assert::assertTrue($this->contains($value), "Failed asserting that the collection contains the specified value.");
|
|
||||||
});
|
|
||||||
|
|
||||||
Collection::macro('assertNotContains', function ($value) {
|
|
||||||
Assert::assertFalse($this->contains($value), "Failed asserting that the collection does not contain the specified value.");
|
|
||||||
});
|
|
||||||
|
|
||||||
Collection::macro('assertEquals', function ($items) {
|
|
||||||
Assert::assertEquals(count($this), count($items));
|
|
||||||
|
|
||||||
$this->zip($items)->each(function ($pair) {
|
|
||||||
list($a, $b) = $pair;
|
|
||||||
Assert::assertTrue($a->is($b));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
function guests_cannot_view_a_promoters_concert_list()
|
function guests_cannot_view_a_promoters_concert_list()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,13 +22,37 @@ class ViewPublishedConcertOrdersTest extends TestCase
|
|||||||
$user = factory(User::class)->create();
|
$user = factory(User::class)->create();
|
||||||
$concert = ConcertFactory::createPublished(['user_id' => $user->id]);
|
$concert = ConcertFactory::createPublished(['user_id' => $user->id]);
|
||||||
|
|
||||||
$order = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('11 days ago')]);
|
$oldOrder = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('11 days ago')]);
|
||||||
|
$recentOrder1 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('10 days ago')]);
|
||||||
|
$recentOrder2 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('9 days ago')]);
|
||||||
|
$recentOrder3 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('8 days ago')]);
|
||||||
|
$recentOrder4 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('7 days ago')]);
|
||||||
|
$recentOrder5 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('6 days ago')]);
|
||||||
|
$recentOrder6 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('5 days ago')]);
|
||||||
|
$recentOrder7 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('4 days ago')]);
|
||||||
|
$recentOrder8 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('3 days ago')]);
|
||||||
|
$recentOrder9 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('2 days ago')]);
|
||||||
|
$recentOrder10 = OrderFactory::createForConcert($concert, ['created_at' => Carbon::parse('1 days ago')]);
|
||||||
|
|
||||||
$response = $this->actingAs($user)->get("/backstage/published-concerts/{$concert->id}/orders");
|
$response = $this->actingAs($user)->get("/backstage/published-concerts/{$concert->id}/orders");
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$response->assertViewIs('backstage.published-concert-orders.index');
|
$response->assertViewIs('backstage.published-concert-orders.index');
|
||||||
$this->assertTrue($response->data('concert')->is($concert));
|
$this->assertTrue($response->data('concert')->is($concert));
|
||||||
|
|
||||||
|
$response->data('orders')->assertNotContains($oldOrder);
|
||||||
|
$response->data('orders')->assertEquals([
|
||||||
|
$recentOrder10,
|
||||||
|
$recentOrder9,
|
||||||
|
$recentOrder8,
|
||||||
|
$recentOrder7,
|
||||||
|
$recentOrder6,
|
||||||
|
$recentOrder5,
|
||||||
|
$recentOrder4,
|
||||||
|
$recentOrder3,
|
||||||
|
$recentOrder2,
|
||||||
|
$recentOrder1,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use App\Exceptions\Handler;
|
|||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
use Illuminate\Foundation\Testing\TestResponse;
|
use Illuminate\Foundation\Testing\TestResponse;
|
||||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||||
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||||
|
|
||||||
abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
|
abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
|
||||||
{
|
{
|
||||||
@@ -30,6 +31,23 @@ abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
|
|||||||
TestResponse::macro('assertViewIs', function ($name) {
|
TestResponse::macro('assertViewIs', function ($name) {
|
||||||
Assert::assertEquals($name, $this->original->name());
|
Assert::assertEquals($name, $this->original->name());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EloquentCollection::macro('assertContains', function ($value) {
|
||||||
|
Assert::assertTrue($this->contains($value), "Failed asserting that the collection contains the specified value.");
|
||||||
|
});
|
||||||
|
|
||||||
|
EloquentCollection::macro('assertNotContains', function ($value) {
|
||||||
|
Assert::assertFalse($this->contains($value), "Failed asserting that the collection does not contain the specified value.");
|
||||||
|
});
|
||||||
|
|
||||||
|
EloquentCollection::macro('assertEquals', function ($items) {
|
||||||
|
Assert::assertEquals(count($this), count($items));
|
||||||
|
|
||||||
|
$this->zip($items)->each(function ($pair) {
|
||||||
|
list($a, $b) = $pair;
|
||||||
|
Assert::assertTrue($a->is($b));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function disableExceptionHandling()
|
protected function disableExceptionHandling()
|
||||||
|
|||||||
Reference in New Issue
Block a user