2023-12-16 01:13:49 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Invoice;
|
|
|
|
|
2023-12-16 11:18:00 +01:00
|
|
|
use App\Invoice\BillKind;
|
2023-12-16 01:13:49 +01:00
|
|
|
use App\Invoice\Enums\InvoiceStatus;
|
|
|
|
use App\Invoice\Models\Invoice;
|
|
|
|
use App\Invoice\Models\InvoicePosition;
|
2023-12-17 00:45:03 +01:00
|
|
|
use App\Member\Member;
|
2023-12-16 01:13:49 +01:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class InvoiceIndexActionTest extends TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
public function testItDisplaysInvoices(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
2023-12-16 23:52:41 +01:00
|
|
|
$member = Member::factory()->defaults()->create(['firstname' => 'Aaaa', 'lastname' => 'Aaab']);
|
2023-12-17 00:45:03 +01:00
|
|
|
$invoice = Invoice::factory()
|
|
|
|
->has(InvoicePosition::factory()->price(1100)->for($member)->state(['description' => 'lala']), 'positions')
|
2023-12-17 02:03:39 +01:00
|
|
|
->has(InvoicePosition::factory()->price(2200)->withMember(), 'positions')
|
2023-12-16 01:13:49 +01:00
|
|
|
->to(ReceiverRequestFactory::new()->name('Familie Blabla'))
|
|
|
|
->sentAt(now()->subDay())
|
2023-12-16 11:18:00 +01:00
|
|
|
->via(BillKind::POST)
|
2023-12-16 01:13:49 +01:00
|
|
|
->status(InvoiceStatus::SENT)
|
2023-12-17 23:00:52 +01:00
|
|
|
->create(['usage' => 'Usa']);
|
2023-12-16 01:13:49 +01:00
|
|
|
|
|
|
|
$this->get(route('invoice.index'))
|
2023-12-17 00:45:03 +01:00
|
|
|
->assertInertiaPath('data.data.0.to.name', 'Familie Blabla')
|
|
|
|
->assertInertiaPath('data.data.0.id', $invoice->id)
|
2023-12-16 01:13:49 +01:00
|
|
|
->assertInertiaPath('data.data.0.sum_human', '33,00 €')
|
|
|
|
->assertInertiaPath('data.data.0.sent_at_human', now()->subDay()->format('d.m.Y'))
|
|
|
|
->assertInertiaPath('data.data.0.status', 'Rechnung gestellt')
|
2023-12-16 11:18:00 +01:00
|
|
|
->assertInertiaPath('data.data.0.via', 'Post')
|
2023-12-17 23:00:52 +01:00
|
|
|
->assertInertiaPath('data.data.0.usage', 'Usa')
|
2023-12-17 00:45:03 +01:00
|
|
|
->assertInertiaPath('data.data.0.greeting', $invoice->greeting)
|
|
|
|
->assertInertiaPath('data.data.0.positions.0.price', 1100)
|
|
|
|
->assertInertiaPath('data.data.0.positions.0.member_id', $member->id)
|
|
|
|
->assertInertiaPath('data.data.0.positions.0.description', 'lala')
|
|
|
|
->assertInertiaPath('data.data.0.positions.0.id', $invoice->positions->first()->id)
|
2023-12-17 23:27:55 +01:00
|
|
|
->assertInertiaPath('data.data.0.links.pdf', route('invoice.pdf', ['invoice' => $invoice]))
|
2023-12-17 00:45:03 +01:00
|
|
|
->assertInertiaPath('data.data.0.links.update', route('invoice.update', ['invoice' => $invoice]))
|
2023-12-17 00:55:31 +01:00
|
|
|
->assertInertiaPath('data.data.0.links.destroy', route('invoice.destroy', ['invoice' => $invoice]))
|
2023-12-16 20:35:28 +01:00
|
|
|
->assertInertiaPath('data.meta.links.mass-store', route('invoice.mass-store'))
|
2023-12-16 22:30:56 +01:00
|
|
|
->assertInertiaPath('data.meta.links.store', route('invoice.store'))
|
2023-12-16 20:35:28 +01:00
|
|
|
->assertInertiaPath('data.meta.vias.0', ['id' => 'E-Mail', 'name' => 'E-Mail'])
|
2023-12-16 22:30:56 +01:00
|
|
|
->assertInertiaPath('data.meta.statuses.0', ['id' => 'Neu', 'name' => 'Neu'])
|
2023-12-16 23:52:41 +01:00
|
|
|
->assertInertiaPath('data.meta.members.0', ['id' => $member->id, 'name' => 'Aaaa Aaab'])
|
2023-12-16 22:30:56 +01:00
|
|
|
->assertInertiaPath('data.meta.default', [
|
|
|
|
'to' => [
|
|
|
|
'name' => '',
|
|
|
|
'address' => '',
|
|
|
|
'zip' => '',
|
|
|
|
'location' => '',
|
|
|
|
],
|
|
|
|
'positions' => [],
|
|
|
|
'greeting' => '',
|
|
|
|
'status' => InvoiceStatus::NEW->value,
|
|
|
|
'via' => null,
|
2023-12-17 23:00:52 +01:00
|
|
|
'usage' => '',
|
2023-12-16 22:30:56 +01:00
|
|
|
])
|
|
|
|
->assertInertiaPath('data.meta.default_position', [
|
2023-12-17 00:45:03 +01:00
|
|
|
'id' => null,
|
2023-12-16 22:30:56 +01:00
|
|
|
'price' => 0,
|
|
|
|
'description' => '',
|
2023-12-17 00:45:03 +01:00
|
|
|
'member_id' => null,
|
2023-12-16 22:30:56 +01:00
|
|
|
]);
|
2023-12-16 01:13:49 +01:00
|
|
|
}
|
2023-12-16 13:08:17 +01:00
|
|
|
|
|
|
|
public function testValuesCanBeNull(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
Invoice::factory()->create();
|
|
|
|
|
|
|
|
$this->get(route('invoice.index'))
|
|
|
|
->assertInertiaPath('data.data.0.sent_at_human', '');
|
|
|
|
}
|
2023-12-16 01:13:49 +01:00
|
|
|
}
|