diff --git a/app/Payment/SubscriptionController.php b/app/Payment/SubscriptionController.php index 5db251c4..7277ff5c 100644 --- a/app/Payment/SubscriptionController.php +++ b/app/Payment/SubscriptionController.php @@ -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'); diff --git a/tests/Feature/Subscription/StoreTest.php b/tests/Feature/Subscription/StoreTest.php new file mode 100644 index 00000000..c6588684 --- /dev/null +++ b/tests/Feature/Subscription/StoreTest.php @@ -0,0 +1,49 @@ +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); + } +}