diff --git a/tests/Feature/Backstage/AddConcertTest.php b/tests/Feature/Backstage/AddConcertTest.php index 90d7a1e..208f4c3 100644 --- a/tests/Feature/Backstage/AddConcertTest.php +++ b/tests/Feature/Backstage/AddConcertTest.php @@ -12,6 +12,24 @@ class AddConcertTest extends TestCase { use DatabaseMigrations; + private function validParams($overrides = []) + { + return array_merge([ + 'title' => 'No Warning', + 'subtitle' => 'with Cruel Hand and Backtrack', + 'additional_information' => "You must be 19 years of age to attend this concert.", + 'date' => '2017-11-18', + 'time' => '8:00pm', + 'venue' => 'The Mosh Pit', + 'venue_address' => '123 Fake St.', + 'city' => 'Laraville', + 'state' => 'ON', + 'zip' => '12345', + 'ticket_price' => '32.50', + 'ticket_quantity' => '75', + ], $overrides); + } + private function from($url) { session()->setPreviousUrl(url($url)); @@ -80,20 +98,7 @@ class AddConcertTest extends TestCase /** @test */ function guests_cannot_add_new_concerts() { - $response = $this->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + $response = $this->post('/backstage/concerts', $this->validParams()); $response->assertStatus(302); $response->assertRedirect('/login'); @@ -105,20 +110,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'title' => '', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); $response->assertStatus(302); $response->assertRedirect('/backstage/concerts/new'); @@ -133,36 +127,15 @@ class AddConcertTest extends TestCase $user = factory(User::class)->create(); - $response = $this->actingAs($user)->post('/backstage/concerts', [ - 'title' => 'No Warning', + $response = $this->actingAs($user)->post('/backstage/concerts', $this->validParams([ 'subtitle' => '', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); tap(Concert::first(), function ($concert) use ($response) { $response->assertStatus(302); $response->assertRedirect("/concerts/{$concert->id}"); - $this->assertEquals('No Warning', $concert->title); $this->assertNull($concert->subtitle); - $this->assertEquals("You must be 19 years of age to attend this concert.", $concert->additional_information); - $this->assertEquals(Carbon::parse('2017-11-18 8:00pm'), $concert->date); - $this->assertEquals('The Mosh Pit', $concert->venue); - $this->assertEquals('123 Fake St.', $concert->venue_address); - $this->assertEquals('Laraville', $concert->city); - $this->assertEquals('ON', $concert->state); - $this->assertEquals('12345', $concert->zip); - $this->assertEquals(3250, $concert->ticket_price); - $this->assertEquals(75, $concert->ticketsRemaining()); }); } @@ -173,36 +146,15 @@ class AddConcertTest extends TestCase $user = factory(User::class)->create(); - $response = $this->actingAs($user)->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', + $response = $this->actingAs($user)->post('/backstage/concerts', $this->validParams([ 'additional_information' => "", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); tap(Concert::first(), function ($concert) use ($response) { $response->assertStatus(302); $response->assertRedirect("/concerts/{$concert->id}"); - $this->assertEquals('No Warning', $concert->title); - $this->assertEquals('with Cruel Hand and Backtrack', $concert->subtitle); $this->assertNull($concert->additional_information); - $this->assertEquals(Carbon::parse('2017-11-18 8:00pm'), $concert->date); - $this->assertEquals('The Mosh Pit', $concert->venue); - $this->assertEquals('123 Fake St.', $concert->venue_address); - $this->assertEquals('Laraville', $concert->city); - $this->assertEquals('ON', $concert->state); - $this->assertEquals('12345', $concert->zip); - $this->assertEquals(3250, $concert->ticket_price); - $this->assertEquals(75, $concert->ticketsRemaining()); }); } @@ -211,20 +163,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'date' => '', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('date'); @@ -236,20 +177,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'date' => 'not a date', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('date'); @@ -261,20 +191,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'time' => '', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('time'); @@ -286,20 +205,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'time' => 'not-a-time', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('time'); @@ -311,20 +219,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'venue' => '', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('venue'); @@ -336,20 +233,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'venue_address' => '', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('venue_address'); @@ -361,20 +247,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'city' => '', - 'state' => 'ON', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('city'); @@ -386,20 +261,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'state' => '', - 'zip' => '12345', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('state'); @@ -411,20 +275,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'zip' => '', - 'ticket_price' => '32.50', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('zip'); @@ -436,20 +289,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '90210', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'ticket_price' => '', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('ticket_price'); @@ -461,20 +303,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '90210', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'ticket_price' => 'not a price', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('ticket_price'); @@ -486,20 +317,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '90210', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'ticket_price' => '4.99', - 'ticket_quantity' => '75', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('ticket_price'); @@ -511,20 +331,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '90210', - 'ticket_price' => '5', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'ticket_quantity' => '', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('ticket_quantity'); @@ -536,20 +345,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '90210', - 'ticket_price' => '5', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'ticket_quantity' => 'not a number', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('ticket_quantity'); @@ -561,20 +359,9 @@ class AddConcertTest extends TestCase { $user = factory(User::class)->create(); - $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', [ - 'title' => 'No Warning', - 'subtitle' => 'with Cruel Hand and Backtrack', - 'additional_information' => "You must be 19 years of age to attend this concert.", - 'date' => '2017-11-18', - 'time' => '8:00pm', - 'venue' => 'The Mosh Pit', - 'venue_address' => '123 Fake St.', - 'city' => 'Laraville', - 'state' => 'ON', - 'zip' => '90210', - 'ticket_price' => '5', + $response = $this->actingAs($user)->from('/backstage/concerts/new')->post('/backstage/concerts', $this->validParams([ 'ticket_quantity' => '0', - ]); + ])); $response->assertRedirect('/backstage/concerts/new'); $response->assertSessionHasErrors('ticket_quantity');