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();
|
2022-12-14 23:20:05 +01:00
|
|
|
$subscription = Subscription::factory()->name('hi')->for(Fee::factory())->create(['split' => true, 'for_promise' => false]);
|
2022-12-13 21:25:03 +01:00
|
|
|
$fee = Fee::factory()->create();
|
|
|
|
|
|
|
|
$response = $this->from("/subscription/{$subscription->id}")->patch(
|
|
|
|
"/subscription/{$subscription->id}",
|
2022-12-14 23:20:05 +01:00
|
|
|
SubscriptionRequestFactory::new()->amount(2500)->fee($fee)->name('lorem')->create(['split' => false, 'for_promise' => true])
|
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-14 00:23:03 +01:00
|
|
|
'split' => false,
|
2022-12-14 23:20:05 +01:00
|
|
|
'for_promise' => true,
|
2022-12-13 21:25:03 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
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.',
|
2022-12-14 23:20:05 +01:00
|
|
|
'for_promise' => 'Für Versprechen benutzen muss ein Wahrheitswert sein.',
|
2022-12-13 21:25:03 +01:00
|
|
|
], $response);
|
|
|
|
}
|
|
|
|
}
|