adrema/tests/Feature/Subscription/StoreTest.php

57 lines
1.6 KiB
PHP
Raw Normal View History

2022-11-17 21:05:35 +01:00
<?php
namespace Tests\Feature\Subscription;
use App\Fee;
2022-12-13 23:11:32 +01:00
use App\Payment\Subscription;
2022-11-17 21:05:35 +01:00
use Illuminate\Foundation\Testing\DatabaseTransactions;
2022-12-13 23:11:32 +01:00
use Tests\RequestFactories\Child;
2022-12-13 21:21:08 +01:00
use Tests\RequestFactories\SubscriptionRequestFactory;
2022-11-17 21:05:35 +01:00
use Tests\TestCase;
class StoreTest extends TestCase
{
use DatabaseTransactions;
public function testItStoresASubscription(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$fee = Fee::factory()->create();
2022-12-13 21:21:08 +01:00
$response = $this->from('/subscription')->post(
'/subscription',
2022-12-13 23:11:32 +01:00
SubscriptionRequestFactory::new()->fee($fee)->name('lorem')->children([
new Child('ch', 2500),
2023-12-20 22:11:07 +01:00
])->create()
2022-12-13 21:21:08 +01:00
);
2022-11-17 21:05:35 +01:00
$response->assertRedirect('/subscription');
2022-12-13 23:11:32 +01:00
$subscription = Subscription::firstWhere('name', 'lorem');
2022-11-17 21:05:35 +01:00
$this->assertDatabaseHas('subscriptions', [
'fee_id' => $fee->id,
2022-12-13 23:11:32 +01:00
'name' => 'lorem',
]);
$this->assertDatabaseHas('subscription_children', [
'name' => 'ch',
'amount' => 2500,
'parent_id' => $subscription->id,
2022-11-17 21:05:35 +01:00
]);
}
public function testItValidatesSubscription(): void
{
$this->login()->loginNami();
2023-12-20 22:11:07 +01:00
Fee::factory()->create();
2022-11-17 21:05:35 +01:00
2022-12-13 21:21:08 +01:00
$response = $this->post(
'/subscription',
SubscriptionRequestFactory::new()->invalid()->create()
);
2022-11-17 21:05:35 +01:00
$this->assertErrors([
'fee_id' => 'Nami-Beitrag ist nicht vorhanden.',
'name' => 'Name ist erforderlich.',
], $response);
}
}