adrema/tests/Feature/Invoice/InvoiceSendActionTest.php

47 lines
1.6 KiB
PHP
Raw Normal View History

2022-11-07 16:18:11 +01:00
<?php
2023-04-18 22:08:45 +02:00
namespace Tests\Feature\Invoice;
2022-11-07 16:18:11 +01:00
2023-04-18 22:08:45 +02:00
use App\Invoice\Actions\InvoiceSendAction;
use App\Invoice\BillDocument;
2022-11-07 16:18:11 +01:00
use App\Member\Member;
use App\Payment\Payment;
use App\Payment\PaymentMail;
use Illuminate\Foundation\Testing\DatabaseTransactions;
2023-02-18 01:22:58 +01:00
use Illuminate\Support\Facades\Mail;
2022-11-07 16:18:11 +01:00
use Illuminate\Support\Facades\Storage;
2022-12-13 23:11:32 +01:00
use Tests\RequestFactories\Child;
2022-11-07 16:18:11 +01:00
use Tests\TestCase;
use Zoomyboy\Tex\Tex;
2023-04-18 22:08:45 +02:00
class InvoiceSendActionTest extends TestCase
2022-11-07 16:18:11 +01:00
{
use DatabaseTransactions;
2023-11-30 23:54:16 +01:00
public function testItCanCreatePdfPayments(): void
2022-11-07 16:18:11 +01:00
{
2023-11-30 23:54:16 +01:00
Mail::fake();
Tex::spy();
2023-02-18 01:22:58 +01:00
Storage::fake('temp');
2022-11-07 16:18:11 +01:00
$this->withoutExceptionHandling();
$this->login()->loginNami();
2023-11-30 23:54:16 +01:00
$member = 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),
]))
2022-11-07 16:18:11 +01:00
->emailBillKind()
->create(['firstname' => 'Lah', 'lastname' => 'Mom', 'email' => 'peter@example.com']);
2023-04-18 22:08:45 +02:00
InvoiceSendAction::run();
2022-11-07 16:18:11 +01:00
2023-11-30 23:54:16 +01:00
Mail::assertSent(PaymentMail::class, fn ($mail) => Storage::disk('temp')->path('rechnung-fur-mom.pdf') === $mail->filename && Storage::disk('temp')->exists('rechnung-fur-mom.pdf'));
Tex::assertCompiled(
BillDocument::class,
fn ($document) => 'Mom' === $document->familyName
&& $document->positions === ['tollerbeitrag 1997 für Lah Mom' => '54.00']
2022-11-07 16:18:11 +01:00
);
2023-11-30 23:54:16 +01:00
Tex::assertCompiledContent(BillDocument::class, BillDocument::from($member->payments->first()->invoice_data)->renderBody());
2022-11-07 16:18:11 +01:00
}
}