From db79f4dc177af573be8bde90e23cbae94958735b Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 17 Nov 2022 21:05:35 +0100 Subject: [PATCH] Add Subscription StoreTest --- app/Payment/SubscriptionController.php | 6 +++ tests/Feature/Subscription/StoreTest.php | 49 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/Feature/Subscription/StoreTest.php 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); + } +}