adrema/tests/Feature/Subscription/UpdateTest.php

75 lines
2.4 KiB
PHP
Raw Normal View History

2022-12-13 21:25:03 +01:00
<?php
namespace Tests\Feature\Subscription;
use App\Fee;
use App\Payment\Subscription;
use Illuminate\Foundation\Testing\DatabaseTransactions;
2022-12-13 23:11:32 +01:00
use Tests\RequestFactories\Child;
2022-12-13 21:25:03 +01:00
use Tests\RequestFactories\SubscriptionRequestFactory;
use Tests\TestCase;
class UpdateTest extends TestCase
{
use DatabaseTransactions;
public function testItUpdatesASubscription(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
2023-12-20 22:11:07 +01:00
$subscription = Subscription::factory()->name('hi')->for(Fee::factory())->create();
2022-12-13 21:25:03 +01:00
$fee = Fee::factory()->create();
$response = $this->from("/subscription/{$subscription->id}")->patch(
"/subscription/{$subscription->id}",
2023-12-20 22:11:07 +01:00
SubscriptionRequestFactory::new()->amount(2500)->fee($fee)->name('lorem')->create()
2022-12-13 21:25:03 +01:00
);
$response->assertRedirect('/subscription');
$this->assertDatabaseHas('subscriptions', [
'id' => $subscription->id,
'fee_id' => $fee->id,
'name' => 'Lorem',
]);
}
2022-12-13 23:11:32 +01:00
public function testItUpdatesChildren(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$subscription = Subscription::factory()->name('hi')->for(Fee::factory())->children([
new Child('a', 1400),
new Child('b', 1500),
])->create();
$response = $this->from("/subscription/{$subscription->id}")->patch(
"/subscription/{$subscription->id}",
SubscriptionRequestFactory::new()->children([
new Child('c', 1900),
])->create()
);
$response->assertRedirect('/subscription');
$this->assertDatabaseHas('subscription_children', [
'parent_id' => $subscription->id,
'name' => 'c',
'amount' => 1900,
]);
$this->assertDatabaseCount('subscription_children', 1);
}
2022-12-13 21:25:03 +01:00
public function testItValidatesRequest(): void
{
$this->login()->loginNami();
2022-12-13 23:11:32 +01:00
$subscription = Subscription::factory()->name('hi')->for(Fee::factory())->create();
2022-12-13 21:25:03 +01:00
$response = $this->from("/subscription/{$subscription->id}")->patch(
"/subscription/{$subscription->id}",
SubscriptionRequestFactory::new()->invalid()->create()
);
$this->assertErrors([
'fee_id' => 'Nami-Beitrag ist nicht vorhanden.',
'name' => 'Name ist erforderlich.',
], $response);
}
}