adrema/tests/Feature/Invoice/InvoiceSendActionTest.php

61 lines
1.7 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;
2022-11-09 01:33:31 +01:00
use Illuminate\Support\Facades\Artisan;
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;
public Member $member;
public function setUp(): void
{
parent::setUp();
2023-02-18 01:22:58 +01:00
Storage::fake('temp');
2022-11-07 16:18:11 +01:00
$this->withoutExceptionHandling();
$this->login()->loginNami();
$this->member = Member::factory()
->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']);
}
public function testItCanCreatePdfPayments(): void
{
Mail::fake();
2023-04-18 22:08:45 +02:00
Artisan::call('invoice:send');
2022-11-07 16:18:11 +01:00
2023-02-18 01:22:58 +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'));
2022-11-07 16:18:11 +01:00
}
public function testItCanCompileAttachment(): void
{
Mail::fake();
Tex::spy();
2023-04-18 22:08:45 +02:00
InvoiceSendAction::run();
2022-11-07 16:18:11 +01:00
Tex::assertCompiled(BillDocument::class, fn ($document) => 'Mom' === $document->pages->first()->familyName
2022-12-14 00:23:03 +01:00
&& $document->pages->first()->getPositions() === ['tollerbeitrag 1997 für Lah Mom' => '54.00']
2022-11-07 16:18:11 +01:00
);
}
}