Add Subscription StoreTest
This commit is contained in:
parent
f126ce17c1
commit
db79f4dc17
|
@ -39,6 +39,9 @@ class SubscriptionController extends Controller
|
|||
'name' => 'required|max:255',
|
||||
'amount' => 'required|numeric',
|
||||
'fee_id' => 'required|exists:fees,id',
|
||||
], [], [
|
||||
'fee_id' => 'Nami-Beitrag',
|
||||
'amount' => 'Interner Beitrag',
|
||||
]));
|
||||
|
||||
return redirect()->route('subscription.index');
|
||||
|
@ -62,6 +65,9 @@ class SubscriptionController extends Controller
|
|||
'name' => 'required|max:255',
|
||||
'amount' => 'required|numeric',
|
||||
'fee_id' => 'required|exists:fees,id',
|
||||
], [], [
|
||||
'fee_id' => 'Nami-Beitrag',
|
||||
'amount' => 'Interner Beitrag',
|
||||
]));
|
||||
|
||||
return redirect()->route('subscription.index');
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Subscription;
|
||||
|
||||
use App\Fee;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StoreTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function testItStoresASubscription(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$fee = Fee::factory()->create();
|
||||
|
||||
$response = $this->from('/subscription')->post('/subscription', [
|
||||
'amount' => 2500,
|
||||
'fee_id' => $fee->id,
|
||||
'name' => 'Lorem',
|
||||
]);
|
||||
|
||||
$response->assertRedirect('/subscription');
|
||||
$this->assertDatabaseHas('subscriptions', [
|
||||
'amount' => 2500,
|
||||
'fee_id' => $fee->id,
|
||||
'name' => 'Lorem',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testItValidatesSubscription(): void
|
||||
{
|
||||
$this->login()->loginNami();
|
||||
$fee = Fee::factory()->create();
|
||||
|
||||
$response = $this->post('/subscription', [
|
||||
'amount' => '',
|
||||
'fee_id' => 99,
|
||||
'name' => '',
|
||||
]);
|
||||
|
||||
$this->assertErrors([
|
||||
'amount' => 'Interner Beitrag ist erforderlich.',
|
||||
'fee_id' => 'Nami-Beitrag ist nicht vorhanden.',
|
||||
'name' => 'Name ist erforderlich.',
|
||||
], $response);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue