mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-25 19:57:28 +00:00
123 - Creating Published Concerts
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Backstage;
|
||||||
|
|
||||||
|
use App\Concert;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
|
class PublishedConcertsController extends Controller
|
||||||
|
{
|
||||||
|
public function store()
|
||||||
|
{
|
||||||
|
$concert = Concert::find(request('concert_id'));
|
||||||
|
|
||||||
|
if ($concert->isPublished()) {
|
||||||
|
abort(422);
|
||||||
|
}
|
||||||
|
|
||||||
|
$concert->publish();
|
||||||
|
return redirect()->route('backstage.concerts.index');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,3 +27,4 @@ Route::group(['middleware' => 'auth', 'prefix' => 'backstage', 'namespace' => 'B
|
|||||||
Route::patch('/concerts/{id}', 'ConcertsController@update')->name('backstage.concerts.update');
|
Route::patch('/concerts/{id}', 'ConcertsController@update')->name('backstage.concerts.update');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::post('/backstage/published-concerts', 'Backstage\PublishedConcertsController@store');
|
||||||
|
|||||||
51
tests/Feature/Backstage/PublishConcertTest.php
Normal file
51
tests/Feature/Backstage/PublishConcertTest.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Backstage;
|
||||||
|
|
||||||
|
use App\User;
|
||||||
|
use App\Concert;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
class PublishConcertTest extends TestCase
|
||||||
|
{
|
||||||
|
use DatabaseMigrations;
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
function a_promoter_can_publish_their_own_concert()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$concert = factory(Concert::class)->states('unpublished')->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'ticket_quantity' => 3,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->post('/backstage/published-concerts', [
|
||||||
|
'concert_id' => $concert->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertRedirect('/backstage/concerts');
|
||||||
|
$concert = $concert->fresh();
|
||||||
|
$this->assertTrue($concert->isPublished());
|
||||||
|
$this->assertEquals(3, $concert->ticketsRemaining());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
function a_concert_can_only_be_published_once()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$concert = \ConcertFactory::createPublished([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'ticket_quantity' => 3,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->post('/backstage/published-concerts', [
|
||||||
|
'concert_id' => $concert->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertStatus(422);
|
||||||
|
$this->assertEquals(3, $concert->fresh()->ticketsRemaining());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user