mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
(add remaining validation tests)
This commit is contained in:
@@ -18,22 +18,31 @@ class ConcertsController extends Controller
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'title' => ['required'],
|
||||
'date' => ['required', 'date'],
|
||||
'time' => ['required', 'date_format:g:ia'],
|
||||
'venue' => ['required'],
|
||||
'venue_address' => ['required'],
|
||||
'city' => ['required'],
|
||||
'state' => ['required'],
|
||||
'zip' => ['required'],
|
||||
'ticket_price' => ['required', 'numeric', 'min:5'],
|
||||
'ticket_quantity' => ['required', 'numeric', 'min:1'],
|
||||
]);
|
||||
|
||||
$concert = Concert::create([
|
||||
'title' => request('title'),
|
||||
'subtitle' => request('subtitle'),
|
||||
'additional_information' => request('additional_information'),
|
||||
'date' => Carbon::parse(vsprintf('%s %s', [
|
||||
request('date'),
|
||||
request('time'),
|
||||
])),
|
||||
'ticket_price' => request('ticket_price') * 100,
|
||||
'venue' => request('venue'),
|
||||
'venue_address' => request('venue_address'),
|
||||
'city' => request('city'),
|
||||
'state' => request('state'),
|
||||
'zip' => request('zip'),
|
||||
'additional_information' => request('additional_information'),
|
||||
'ticket_price' => request('ticket_price') * 100,
|
||||
])->addTickets(request('ticket_quantity'));
|
||||
|
||||
return redirect()->route('concerts.show', $concert);
|
||||
|
||||
@@ -17,14 +17,14 @@ class CreateConcertsTable extends Migration
|
||||
$table->increments('id');
|
||||
$table->string('title');
|
||||
$table->string('subtitle')->nullable();
|
||||
$table->text('additional_information')->nullable();
|
||||
$table->datetime('date');
|
||||
$table->integer('ticket_price');
|
||||
$table->string('venue');
|
||||
$table->string('venue_address');
|
||||
$table->string('city');
|
||||
$table->string('state');
|
||||
$table->string('zip');
|
||||
$table->text('additional_information');
|
||||
$table->integer('ticket_price');
|
||||
$table->datetime('published_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -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