2022-11-07 16:18:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Sendpayment;
|
|
|
|
|
|
|
|
use App\Letter\BillDocument;
|
2022-11-18 00:12:24 +01:00
|
|
|
use App\Letter\LetterSettings;
|
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;
|
2022-11-18 00:12:24 +01:00
|
|
|
use Tests\RequestFactories\LetterSettingsFake;
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItCanCreatePdfPayments(): void
|
|
|
|
{
|
2022-11-18 00:12:24 +01:00
|
|
|
LetterSettings::fake(LetterSettingsFake::new()->create());
|
2022-11-07 16:18:11 +01:00
|
|
|
Tex::spy();
|
|
|
|
$this->withoutExceptionHandling();
|
|
|
|
$this->login()->loginNami();
|
|
|
|
$member = Member::factory()
|
|
|
|
->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()
|
|
|
|
->create();
|
|
|
|
|
|
|
|
$response = $this->call('GET', route('sendpayment.pdf'), ['type' => 'App\\Letter\\BillDocument']);
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
$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);
|
|
|
|
Tex::assertCompiled(BillDocument::class, fn ($document) => $document->hasAllContent(['1997', 'tollerbeitrag', '54.00'])
|
|
|
|
&& $document->missesAllContent(['1998', 'bezahltdesc', '58.00'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItDoesntCreatePdfsWhenUserHasEmail(): void
|
|
|
|
{
|
|
|
|
Tex::spy();
|
|
|
|
$this->withoutExceptionHandling();
|
|
|
|
$this->login()->loginNami();
|
|
|
|
$member = Member::factory()
|
|
|
|
->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();
|
|
|
|
|
|
|
|
$response = $this->call('GET', route('sendpayment.pdf'), ['type' => 'App\\Letter\\BillDocument']);
|
|
|
|
|
|
|
|
$response->assertStatus(204);
|
|
|
|
Tex::assertNotCompiled(BillDocument::class);
|
|
|
|
}
|
|
|
|
}
|