adrema/tests/Feature/Payment/IndexTest.php

66 lines
2.6 KiB
PHP
Raw Normal View History

2023-10-13 15:48:29 +02:00
<?php
namespace Tests\Feature\Payment;
2023-12-01 01:25:02 +01:00
use App\Invoice\BillDocument;
use App\Invoice\DocumentFactory;
2023-10-13 15:48:29 +02:00
use App\Member\Member;
use App\Payment\Payment;
use App\Payment\Subscription;
use Illuminate\Foundation\Testing\DatabaseTransactions;
2023-12-13 00:35:39 +01:00
use Illuminate\Support\Collection;
2023-10-13 15:48:29 +02:00
use Tests\RequestFactories\Child;
use Tests\TestCase;
class IndexTest extends TestCase
{
use DatabaseTransactions;
public function testItShowsPayments(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()
->has(Payment::factory()->notPaid()->nr('2019')->subscription('Free', [
new Child('a', 1000),
new Child('b', 50),
]))
->defaults()->create();
$payment = $member->payments->first();
2023-10-16 16:21:23 +02:00
$this->get("/member/{$member->id}/payment")
2023-10-13 15:48:29 +02:00
->assertJsonPath('data.0.subscription.name', 'Free')
->assertJsonPath('data.0.subscription.id', $payment->subscription->id)
->assertJsonPath('data.0.subscription.amount', 1050)
->assertJsonPath('data.0.subscription_id', $payment->subscription->id)
->assertJsonPath('data.0.status_name', 'Nicht bezahlt')
->assertJsonPath('data.0.nr', '2019')
2023-12-01 01:25:02 +01:00
->assertJsonPath('data.0.links.show', null)
2023-10-16 16:21:23 +02:00
->assertJsonPath('data.0.links.update', url("/payment/{$payment->id}"))
->assertJsonPath('data.0.links.destroy', url("/payment/{$payment->id}"))
2023-10-13 15:48:29 +02:00
->assertJsonPath('meta.statuses.0.name', 'Nicht bezahlt')
->assertJsonPath('meta.statuses.0.id', $payment->status->id)
->assertJsonPath('meta.subscriptions.0.id', Subscription::first()->id)
->assertJsonPath('meta.subscriptions.0.name', Subscription::first()->name)
->assertJsonPath('meta.links.store', url("/member/{$member->id}/payment"));
}
2023-12-01 01:25:02 +01:00
public function testItShowsPaymentLink(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()
->has(Payment::factory()->notPaid()->nr('2019')->subscription('Free', [
new Child('a', 1000),
new Child('b', 50),
]))
->defaults()->create();
2023-12-13 00:35:39 +01:00
/** @var Collection<int|string, Member> */
2023-12-01 01:25:02 +01:00
$members = collect([$member]);
app(DocumentFactory::class)->afterSingle(BillDocument::fromMembers($members), $members);
$this->get("/member/{$member->id}/payment")
->assertJsonPath('data.0.links.show', route('payment.pdf', ['payment' => $member->payments->first()]));
}
2023-10-13 15:48:29 +02:00
}