mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-06 09:58:56 +00:00
(add remaining validation tests)
This commit is contained in:
@@ -165,4 +165,419 @@ class AddConcertTest extends TestCase
|
||||
$this->assertEquals(75, $concert->ticketsRemaining());
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function additional_information_is_optional()
|
||||
{
|
||||
$this->disableExceptionHandling();
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
|
||||
$response = $this->actingAs($user)->post('/backstage/concerts', [
|
||||
'title' => 'No Warning',
|
||||
'subtitle' => 'with Cruel Hand and Backtrack',
|
||||
'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());
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function date_is_required()
|
||||
{
|
||||
$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' => '',
|
||||
'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');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function date_must_be_a_valid_date()
|
||||
{
|
||||
$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' => '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');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function time_is_required()
|
||||
{
|
||||
$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' => '',
|
||||
'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');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function time_must_be_a_valid_time()
|
||||
{
|
||||
$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' => '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');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function venue_is_required()
|
||||
{
|
||||
$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' => '',
|
||||
'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');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function venue_address_is_required()
|
||||
{
|
||||
$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' => '',
|
||||
'city' => 'Laraville',
|
||||
'state' => 'ON',
|
||||
'zip' => '12345',
|
||||
'ticket_price' => '32.50',
|
||||
'ticket_quantity' => '75',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/backstage/concerts/new');
|
||||
$response->assertSessionHasErrors('venue_address');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function city_is_required()
|
||||
{
|
||||
$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' => '',
|
||||
'state' => 'ON',
|
||||
'zip' => '12345',
|
||||
'ticket_price' => '32.50',
|
||||
'ticket_quantity' => '75',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/backstage/concerts/new');
|
||||
$response->assertSessionHasErrors('city');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function state_is_required()
|
||||
{
|
||||
$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' => '',
|
||||
'zip' => '12345',
|
||||
'ticket_price' => '32.50',
|
||||
'ticket_quantity' => '75',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/backstage/concerts/new');
|
||||
$response->assertSessionHasErrors('state');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function zip_is_required()
|
||||
{
|
||||
$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' => '',
|
||||
'ticket_price' => '32.50',
|
||||
'ticket_quantity' => '75',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/backstage/concerts/new');
|
||||
$response->assertSessionHasErrors('zip');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_price_is_required()
|
||||
{
|
||||
$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' => '',
|
||||
'ticket_quantity' => '75',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/backstage/concerts/new');
|
||||
$response->assertSessionHasErrors('ticket_price');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_price_must_be_numeric()
|
||||
{
|
||||
$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' => 'not a price',
|
||||
'ticket_quantity' => '75',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/backstage/concerts/new');
|
||||
$response->assertSessionHasErrors('ticket_price');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_price_must_be_at_least_5()
|
||||
{
|
||||
$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' => '4.99',
|
||||
'ticket_quantity' => '75',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/backstage/concerts/new');
|
||||
$response->assertSessionHasErrors('ticket_price');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_quantity_is_required()
|
||||
{
|
||||
$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',
|
||||
'ticket_quantity' => '',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/backstage/concerts/new');
|
||||
$response->assertSessionHasErrors('ticket_quantity');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_quantity_must_be_numeric()
|
||||
{
|
||||
$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',
|
||||
'ticket_quantity' => 'not a number',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/backstage/concerts/new');
|
||||
$response->assertSessionHasErrors('ticket_quantity');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_quantity_must_be_at_least_1()
|
||||
{
|
||||
$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',
|
||||
'ticket_quantity' => '0',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/backstage/concerts/new');
|
||||
$response->assertSessionHasErrors('ticket_quantity');
|
||||
$this->assertEquals(0, Concert::count());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user