diff --git a/database/factories/Payment/SubscriptionFactory.php b/database/factories/Payment/SubscriptionFactory.php index aacd7c72..05185da4 100644 --- a/database/factories/Payment/SubscriptionFactory.php +++ b/database/factories/Payment/SubscriptionFactory.php @@ -23,4 +23,9 @@ class SubscriptionFactory extends Factory { return $this->state(['name' => $name]); } + + public function amount(int $amount): self + { + return $this->state(['amount' => $amount]); + } } diff --git a/tests/Feature/Subscription/UpdateTest.php b/tests/Feature/Subscription/UpdateTest.php new file mode 100644 index 00000000..c593602a --- /dev/null +++ b/tests/Feature/Subscription/UpdateTest.php @@ -0,0 +1,52 @@ +withoutExceptionHandling()->login()->loginNami(); + $subscription = Subscription::factory()->amount(670)->name('hi')->for(Fee::factory())->create(); + $fee = Fee::factory()->create(); + + $response = $this->from("/subscription/{$subscription->id}")->patch( + "/subscription/{$subscription->id}", + SubscriptionRequestFactory::new()->amount(2500)->fee($fee)->name('lorem')->create() + ); + + $response->assertRedirect('/subscription'); + $this->assertDatabaseHas('subscriptions', [ + 'id' => $subscription->id, + 'amount' => 2500, + 'fee_id' => $fee->id, + 'name' => 'Lorem', + ]); + } + + public function testItValidatesRequest(): void + { + $this->login()->loginNami(); + $subscription = Subscription::factory()->amount(670)->name('hi')->for(Fee::factory())->create(); + $fee = Fee::factory()->create(); + + $response = $this->from("/subscription/{$subscription->id}")->patch( + "/subscription/{$subscription->id}", + SubscriptionRequestFactory::new()->invalid()->create() + ); + + $this->assertErrors([ + 'amount' => 'Interner Beitrag ist erforderlich.', + 'fee_id' => 'Nami-Beitrag ist nicht vorhanden.', + 'name' => 'Name ist erforderlich.', + ], $response); + } +}