mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
117 - Storing the Intended Ticket Quantity
This commit is contained in:
@@ -79,6 +79,7 @@ class ConcertsController extends Controller
|
||||
'state' => ['required'],
|
||||
'zip' => ['required'],
|
||||
'ticket_price' => ['required', 'numeric', 'min:5'],
|
||||
'ticket_quantity' => ['required', 'integer', 'min:1'],
|
||||
]);
|
||||
|
||||
$concert = Auth::user()->concerts()->findOrFail($id);
|
||||
@@ -99,6 +100,7 @@ class ConcertsController extends Controller
|
||||
'state' => request('state'),
|
||||
'zip' => request('zip'),
|
||||
'ticket_price' => request('ticket_price') * 100,
|
||||
'ticket_quantity' => (int) request('ticket_quantity'),
|
||||
]);
|
||||
|
||||
return redirect()->route('backstage.concerts.index');
|
||||
|
||||
@@ -26,6 +26,7 @@ class CreateConcertsTable extends Migration
|
||||
$table->string('state');
|
||||
$table->string('zip');
|
||||
$table->integer('ticket_price');
|
||||
$table->integer('ticket_quantity');
|
||||
$table->datetime('published_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
@@ -117,6 +117,7 @@ class EditConcertTest extends TestCase
|
||||
'state' => 'Old state',
|
||||
'zip' => '00000',
|
||||
'ticket_price' => 2000,
|
||||
'ticket_quantity' => 5,
|
||||
]);
|
||||
$this->assertFalse($concert->isPublished());
|
||||
|
||||
@@ -132,6 +133,7 @@ class EditConcertTest extends TestCase
|
||||
'state' => 'New state',
|
||||
'zip' => '99999',
|
||||
'ticket_price' => '72.50',
|
||||
'ticket_quantity' => '10',
|
||||
]);
|
||||
|
||||
$response->assertRedirect("/backstage/concerts");
|
||||
@@ -146,6 +148,7 @@ class EditConcertTest extends TestCase
|
||||
$this->assertEquals('New state', $concert->state);
|
||||
$this->assertEquals('99999', $concert->zip);
|
||||
$this->assertEquals(7250, $concert->ticket_price);
|
||||
$this->assertEquals(10, $concert->ticket_quantity);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -606,4 +609,67 @@ class EditConcertTest extends TestCase
|
||||
$this->assertEquals(5250, $concert->ticket_price);
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_quantity_is_required()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$concert = factory(Concert::class)->create([
|
||||
'user_id' => $user->id,
|
||||
'ticket_quantity' => 5,
|
||||
]);
|
||||
$this->assertFalse($concert->isPublished());
|
||||
|
||||
$response = $this->actingAs($user)->from("/backstage/concerts/{$concert->id}/edit")->patch("/backstage/concerts/{$concert->id}", $this->validParams([
|
||||
'ticket_quantity' => '',
|
||||
]));
|
||||
|
||||
$response->assertRedirect("/backstage/concerts/{$concert->id}/edit");
|
||||
$response->assertSessionHasErrors('ticket_quantity');
|
||||
tap($concert->fresh(), function ($concert) {
|
||||
$this->assertEquals(5, $concert->ticket_quantity);
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_quantity_must_be_an_integer()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$concert = factory(Concert::class)->create([
|
||||
'user_id' => $user->id,
|
||||
'ticket_quantity' => 5,
|
||||
]);
|
||||
$this->assertFalse($concert->isPublished());
|
||||
|
||||
$response = $this->actingAs($user)->from("/backstage/concerts/{$concert->id}/edit")->patch("/backstage/concerts/{$concert->id}", $this->validParams([
|
||||
'ticket_quantity' => '7.8',
|
||||
]));
|
||||
|
||||
$response->assertRedirect("/backstage/concerts/{$concert->id}/edit");
|
||||
$response->assertSessionHasErrors('ticket_quantity');
|
||||
tap($concert->fresh(), function ($concert) {
|
||||
$this->assertEquals(5, $concert->ticket_quantity);
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function ticket_quantity_must_be_at_least_1()
|
||||
{
|
||||
$user = factory(User::class)->create();
|
||||
$concert = factory(Concert::class)->create([
|
||||
'user_id' => $user->id,
|
||||
'ticket_quantity' => 5,
|
||||
]);
|
||||
$this->assertFalse($concert->isPublished());
|
||||
|
||||
$response = $this->actingAs($user)->from("/backstage/concerts/{$concert->id}/edit")->patch("/backstage/concerts/{$concert->id}", $this->validParams([
|
||||
'ticket_quantity' => '0',
|
||||
]));
|
||||
|
||||
$response->assertRedirect("/backstage/concerts/{$concert->id}/edit");
|
||||
$response->assertSessionHasErrors('ticket_quantity');
|
||||
tap($concert->fresh(), function ($concert) {
|
||||
$this->assertEquals(5, $concert->ticket_quantity);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user