107 - Reducing Noise with Form Factories

This commit is contained in:
Adam Wathan
2017-05-19 15:08:27 -04:00
parent c97432b575
commit 68a1d94540

View File

@@ -12,6 +12,24 @@ class AddConcertTest extends TestCase
{ {
use DatabaseMigrations; 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) private function from($url)
{ {
session()->setPreviousUrl(url($url)); session()->setPreviousUrl(url($url));
@@ -80,20 +98,7 @@ class AddConcertTest extends TestCase
/** @test */ /** @test */
function guests_cannot_add_new_concerts() function guests_cannot_add_new_concerts()
{ {
$response = $this->post('/backstage/concerts', [ $response = $this->post('/backstage/concerts', $this->validParams());
'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->assertStatus(302); $response->assertStatus(302);
$response->assertRedirect('/login'); $response->assertRedirect('/login');
@@ -105,20 +110,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '', '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->assertStatus(302);
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
@@ -133,36 +127,15 @@ class AddConcertTest extends TestCase
$user = factory(User::class)->create(); $user = factory(User::class)->create();
$response = $this->actingAs($user)->post('/backstage/concerts', [ $response = $this->actingAs($user)->post('/backstage/concerts', $this->validParams([
'title' => 'No Warning',
'subtitle' => '', '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) { tap(Concert::first(), function ($concert) use ($response) {
$response->assertStatus(302); $response->assertStatus(302);
$response->assertRedirect("/concerts/{$concert->id}"); $response->assertRedirect("/concerts/{$concert->id}");
$this->assertEquals('No Warning', $concert->title);
$this->assertNull($concert->subtitle); $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(); $user = factory(User::class)->create();
$response = $this->actingAs($user)->post('/backstage/concerts', [ $response = $this->actingAs($user)->post('/backstage/concerts', $this->validParams([
'title' => 'No Warning',
'subtitle' => 'with Cruel Hand and Backtrack',
'additional_information' => "", '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) { tap(Concert::first(), function ($concert) use ($response) {
$response->assertStatus(302); $response->assertStatus(302);
$response->assertRedirect("/concerts/{$concert->id}"); $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->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(); $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' => 'No Warning',
'subtitle' => 'with Cruel Hand and Backtrack',
'additional_information' => "You must be 19 years of age to attend this concert.",
'date' => '', '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->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('date'); $response->assertSessionHasErrors('date');
@@ -236,20 +177,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => 'No Warning',
'subtitle' => 'with Cruel Hand and Backtrack',
'additional_information' => "You must be 19 years of age to attend this concert.",
'date' => 'not a date', '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->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('date'); $response->assertSessionHasErrors('date');
@@ -261,20 +191,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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' => '', '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->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('time'); $response->assertSessionHasErrors('time');
@@ -286,20 +205,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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' => 'not-a-time', '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->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('time'); $response->assertSessionHasErrors('time');
@@ -311,20 +219,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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' => '', '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->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('venue'); $response->assertSessionHasErrors('venue');
@@ -336,20 +233,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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' => '', 'venue_address' => '',
'city' => 'Laraville', ]));
'state' => 'ON',
'zip' => '12345',
'ticket_price' => '32.50',
'ticket_quantity' => '75',
]);
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('venue_address'); $response->assertSessionHasErrors('venue_address');
@@ -361,20 +247,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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' => '', 'city' => '',
'state' => 'ON', ]));
'zip' => '12345',
'ticket_price' => '32.50',
'ticket_quantity' => '75',
]);
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('city'); $response->assertSessionHasErrors('city');
@@ -386,20 +261,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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' => '', 'state' => '',
'zip' => '12345', ]));
'ticket_price' => '32.50',
'ticket_quantity' => '75',
]);
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('state'); $response->assertSessionHasErrors('state');
@@ -411,20 +275,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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' => '', 'zip' => '',
'ticket_price' => '32.50', ]));
'ticket_quantity' => '75',
]);
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('zip'); $response->assertSessionHasErrors('zip');
@@ -436,20 +289,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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' => '', 'ticket_price' => '',
'ticket_quantity' => '75', ]));
]);
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('ticket_price'); $response->assertSessionHasErrors('ticket_price');
@@ -461,20 +303,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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' => 'not a price', 'ticket_price' => 'not a price',
'ticket_quantity' => '75', ]));
]);
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('ticket_price'); $response->assertSessionHasErrors('ticket_price');
@@ -486,20 +317,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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' => '4.99', 'ticket_price' => '4.99',
'ticket_quantity' => '75', ]));
]);
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('ticket_price'); $response->assertSessionHasErrors('ticket_price');
@@ -511,20 +331,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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',
'ticket_quantity' => '', 'ticket_quantity' => '',
]); ]));
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('ticket_quantity'); $response->assertSessionHasErrors('ticket_quantity');
@@ -536,20 +345,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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',
'ticket_quantity' => 'not a number', 'ticket_quantity' => 'not a number',
]); ]));
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('ticket_quantity'); $response->assertSessionHasErrors('ticket_quantity');
@@ -561,20 +359,9 @@ class AddConcertTest extends TestCase
{ {
$user = factory(User::class)->create(); $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' => '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',
'ticket_quantity' => '0', 'ticket_quantity' => '0',
]); ]));
$response->assertRedirect('/backstage/concerts/new'); $response->assertRedirect('/backstage/concerts/new');
$response->assertSessionHasErrors('ticket_quantity'); $response->assertSessionHasErrors('ticket_quantity');