mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-14 20:53:11 +00:00
(add basic tests for viewing published concert orders page)
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Backstage;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class PublishedConcertOrdersController extends Controller
|
||||||
|
{
|
||||||
|
public function index($concertId)
|
||||||
|
{
|
||||||
|
$concert = Auth::user()->concerts()->published()->findOrFail($concertId);
|
||||||
|
|
||||||
|
return view('backstage.published-concert-orders.index', [
|
||||||
|
'concert' => $concert,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,8 @@ Route::group(['middleware' => 'auth', 'prefix' => 'backstage', 'namespace' => 'B
|
|||||||
Route::post('/concerts', 'ConcertsController@store');
|
Route::post('/concerts', 'ConcertsController@store');
|
||||||
Route::get('/concerts/{id}/edit', 'ConcertsController@edit')->name('backstage.concerts.edit');
|
Route::get('/concerts/{id}/edit', 'ConcertsController@edit')->name('backstage.concerts.edit');
|
||||||
Route::patch('/concerts/{id}', 'ConcertsController@update')->name('backstage.concerts.update');
|
Route::patch('/concerts/{id}', 'ConcertsController@update')->name('backstage.concerts.update');
|
||||||
|
|
||||||
Route::post('/published-concerts', 'PublishedConcertsController@store')->name('backstage.published-concerts.store');
|
Route::post('/published-concerts', 'PublishedConcertsController@store')->name('backstage.published-concerts.store');
|
||||||
|
Route::get('/published-concerts/{id}/orders', 'PublishedConcertOrdersController@index')->name('backstage.published-concert-orders.index');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
62
tests/Feature/Backstage/ViewPublishedConcertOrdersTest.php
Normal file
62
tests/Feature/Backstage/ViewPublishedConcertOrdersTest.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Features\Backstage;
|
||||||
|
|
||||||
|
use App\User;
|
||||||
|
use ConcertFactory;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
class ViewPublishedConcertOrdersTest extends TestCase
|
||||||
|
{
|
||||||
|
use DatabaseMigrations;
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
function a_promoter_can_view_the_orders_of_their_own_published_concert()
|
||||||
|
{
|
||||||
|
$this->disableExceptionHandling();
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$concert = ConcertFactory::createPublished(['user_id' => $user->id]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->get("/backstage/published-concerts/{$concert->id}/orders");
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertViewIs('backstage.published-concert-orders.index');
|
||||||
|
$this->assertTrue($response->data('concert')->is($concert));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
function a_promoter_cannot_view_the_orders_of_unpublished_concerts()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$concert = ConcertFactory::createUnpublished(['user_id' => $user->id]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->get("/backstage/published-concerts/{$concert->id}/orders");
|
||||||
|
|
||||||
|
$response->assertStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
function a_promoter_cannot_view_the_orders_of_another_published_concert()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$otherUser = factory(User::class)->create();
|
||||||
|
$concert = ConcertFactory::createPublished(['user_id' => $otherUser->id]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->get("/backstage/published-concerts/{$concert->id}/orders");
|
||||||
|
|
||||||
|
$response->assertStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
function a_guest_cannot_view_the_orders_of_any_published_concert()
|
||||||
|
{
|
||||||
|
$concert = ConcertFactory::createPublished();
|
||||||
|
|
||||||
|
$response = $this->get("/backstage/published-concerts/{$concert->id}/orders");
|
||||||
|
|
||||||
|
$response->assertRedirect('/login');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace Tests;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use App\Exceptions\Handler;
|
use App\Exceptions\Handler;
|
||||||
|
use PHPUnit\Framework\Assert;
|
||||||
use Illuminate\Foundation\Testing\TestResponse;
|
use Illuminate\Foundation\Testing\TestResponse;
|
||||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||||
|
|
||||||
@@ -25,6 +26,10 @@ abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
|
|||||||
TestResponse::macro('data', function ($key) {
|
TestResponse::macro('data', function ($key) {
|
||||||
return $this->original->getData()[$key];
|
return $this->original->getData()[$key];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
TestResponse::macro('assertViewIs', function ($name) {
|
||||||
|
Assert::assertEquals($name, $this->original->name());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function disableExceptionHandling()
|
protected function disableExceptionHandling()
|
||||||
|
|||||||
Reference in New Issue
Block a user