adrema/tests/Feature/Sendpayment/SendpaymentTest.php

130 lines
5.3 KiB
PHP
Raw Normal View History

2022-11-07 16:18:11 +01:00
<?php
namespace Tests\Feature\Sendpayment;
2023-04-18 22:08:45 +02:00
use App\Invoice\BillDocument;
2023-11-30 23:54:16 +01:00
use App\Invoice\BillKind;
2023-04-18 22:08:45 +02:00
use App\Invoice\InvoiceSettings;
2023-11-30 23:54:16 +01:00
use App\Invoice\Queries\BillKindQuery;
use App\Invoice\RememberDocument;
2022-11-07 16:18:11 +01:00
use App\Member\Member;
use App\Payment\Payment;
use App\Payment\Status;
use Illuminate\Foundation\Testing\DatabaseTransactions;
2022-12-13 23:11:32 +01:00
use Tests\RequestFactories\Child;
2023-04-18 22:08:45 +02:00
use Tests\RequestFactories\InvoiceSettingsFake;
2022-11-07 16:18:11 +01:00
use Tests\TestCase;
use Zoomyboy\Tex\Tex;
class SendpaymentTest extends TestCase
{
use DatabaseTransactions;
public function testItCanViewSendpaymentPage(): void
{
$this->withoutExceptionHandling();
$this->login()->loginNami();
$response = $this->get(route('sendpayment.create'));
$response->assertOk();
$this->assertInertiaHas('Rechnungen versenden', $response, 'types.0.link.label');
$href = $this->inertia($response, 'types.0.link.href');
$this->assertStringContainsString('BillDocument', $href);
}
2023-11-30 23:54:16 +01:00
public function testItDownloadsPdfOfAllMembersForBill(): void
{
InvoiceSettings::fake(InvoiceSettingsFake::new()->create());
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults()->postBillKind()->count(3)
->has(Payment::factory()->notPaid()->subscription('tollerbeitrag', [new Child('a', 5400)]))
->create();
$response = $this->call('GET', route('sendpayment.pdf'), ['type' => 'App\\Invoice\\BillDocument']);
$response->assertOk();
$this->assertPdfPageCount(3, $response->getFile());
}
public function testItDownloadsPdfOfAllMembersForRemember(): void
{
InvoiceSettings::fake(InvoiceSettingsFake::new()->create());
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults()->postBillKind()->count(3)
->has(Payment::factory()->pending()->subscription('tollerbeitrag', [new Child('a', 5400)]))
->create();
$response = $this->call('GET', route('sendpayment.pdf'), ['type' => 'App\\Invoice\\RememberDocument']);
$response->assertOk();
$this->assertPdfPageCount(3, $response->getFile());
}
2022-11-07 16:18:11 +01:00
public function testItCanCreatePdfPayments(): void
{
2023-04-18 22:08:45 +02:00
InvoiceSettings::fake(InvoiceSettingsFake::new()->create());
2022-11-07 16:18:11 +01:00
Tex::spy();
2023-11-30 23:54:16 +01:00
$this->withoutExceptionHandling()->login()->loginNami();
$members = Member::factory()
2022-11-07 16:18:11 +01:00
->defaults()
2022-12-13 23:11:32 +01:00
->has(Payment::factory()->notPaid()->nr('1997')->subscription('tollerbeitrag', [new Child('a', 5400)]))
->has(Payment::factory()->paid()->nr('1998')->subscription('bezahltdesc', [new Child('b', 5800)]))
2022-11-07 16:18:11 +01:00
->postBillKind()
2023-11-30 23:54:16 +01:00
->count(3)
2022-11-07 16:18:11 +01:00
->create();
2023-11-30 23:54:16 +01:00
$member = $members->first();
2022-11-07 16:18:11 +01:00
2023-11-30 23:54:16 +01:00
$this->call('GET', route('sendpayment.pdf'), ['type' => 'App\\Invoice\\BillDocument']);
2022-11-07 16:18:11 +01:00
$this->assertEquals(Status::firstWhere('name', 'Rechnung gestellt')->id, $member->payments->firstWhere('nr', '1997')->status_id);
$this->assertEquals(Status::firstWhere('name', 'Rechnung beglichen')->id, $member->payments->firstWhere('nr', '1998')->status_id);
2023-11-30 23:54:16 +01:00
Tex::assertCompiled(
BillDocument::class,
fn ($document) => $document->hasAllContent(['1997', 'tollerbeitrag', '54.00'])
&& $document->missesAllContent(['1998', 'bezahltdesc', '58.00'])
);
$member->payments->firstWhere('nr', '1997')->update(['status_id' => Status::firstWhere('name', 'Nicht bezahlt')->id]);
$invoice = BillDocument::fromMembers((new BillKindQuery(BillKind::POST))->type(BillDocument::class)->getMembers()->first());
$this->assertEquals(
BillDocument::from($member->payments->firstWhere('nr', '1997')->invoice_data)->renderBody(),
$invoice->renderBody()
2022-11-07 16:18:11 +01:00
);
}
2023-11-30 23:54:16 +01:00
public function testItCanCreatePdfPaymentsForRemember(): void
{
InvoiceSettings::fake(InvoiceSettingsFake::new()->create());
Tex::spy();
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()
->defaults()
->has(Payment::factory()->pending()->nr('1997')->subscription('tollerbeitrag', [new Child('a', 5400)]))
->postBillKind()
->create();
$this->call('GET', route('sendpayment.pdf'), ['type' => 'App\\Invoice\\RememberDocument']);
Tex::assertCompiled(
RememberDocument::class,
fn ($document) => $document->hasAllContent(['1997', 'tollerbeitrag', '54.00'])
);
$this->assertNull($member->payments()->first()->invoice_data);
$this->assertEquals(now()->format('Y-m-d'), $member->payments->first()->last_remembered_at->format('Y-m-d'));
}
2022-11-07 16:18:11 +01:00
public function testItDoesntCreatePdfsWhenUserHasEmail(): void
{
Tex::spy();
$this->withoutExceptionHandling();
$this->login()->loginNami();
2023-11-30 23:54:16 +01:00
Member::factory()
2022-11-07 16:18:11 +01:00
->defaults()
2022-12-13 23:11:32 +01:00
->has(Payment::factory()->notPaid()->nr('1997')->subscription('tollerbeitrag', [new Child('u', 5400)]))
2022-11-07 16:18:11 +01:00
->emailBillKind()
->create();
2023-04-18 22:08:45 +02:00
$response = $this->call('GET', route('sendpayment.pdf'), ['type' => 'App\\Invoice\\BillDocument']);
2022-11-07 16:18:11 +01:00
$response->assertStatus(204);
Tex::assertNotCompiled(BillDocument::class);
}
}