adrema/tests/Feature/Subscription/StoreTest.php

49 lines
1.3 KiB
PHP
Raw Normal View History

2022-11-17 21:05:35 +01:00
<?php
namespace Tests\Feature\Subscription;
use App\Fee;
use Illuminate\Foundation\Testing\DatabaseTransactions;
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',
SubscriptionRequestFactory::new()->amount(2500)->fee($fee)->name('lorem')->create()
);
2022-11-17 21:05:35 +01:00
$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();
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([
'amount' => 'Interner Beitrag ist erforderlich.',
'fee_id' => 'Nami-Beitrag ist nicht vorhanden.',
'name' => 'Name ist erforderlich.',
], $response);
}
}