2023-12-16 01:13:49 +01:00
|
|
|
<?php
|
|
|
|
|
2024-12-15 16:05:38 +01:00
|
|
|
namespace Tests\Feature\EndToEnd;
|
2023-12-16 01:13:49 +01:00
|
|
|
|
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;
|
2024-02-10 01:45:41 +01:00
|
|
|
use App\Payment\Subscription;
|
2023-12-16 01:13:49 +01:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2024-12-15 16:05:38 +01:00
|
|
|
use Tests\EndToEndTestCase;
|
|
|
|
use Tests\Feature\Invoice\ReceiverRequestFactory;
|
2023-12-16 01:13:49 +01:00
|
|
|
|
2024-09-21 18:29:47 +02:00
|
|
|
uses(DatabaseTransactions::class);
|
2024-12-15 16:05:38 +01:00
|
|
|
uses(EndToEndTestCase::class);
|
2023-12-16 01:13:49 +01:00
|
|
|
|
2024-09-21 18:29:47 +02:00
|
|
|
it('testItDisplaysInvoices', function () {
|
2024-09-21 18:56:53 +02:00
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
2024-09-21 18:29:47 +02:00
|
|
|
$subscription = Subscription::factory()->forFee()->name('Beitrag')->create();
|
|
|
|
$member = Member::factory()->defaults()->create(['firstname' => 'Aaaa', 'lastname' => 'Aaab']);
|
|
|
|
$invoice = Invoice::factory()
|
|
|
|
->has(InvoicePosition::factory()->price(1100)->for($member)->state(['description' => 'lala']), 'positions')
|
|
|
|
->has(InvoicePosition::factory()->price(2200)->withMember(), 'positions')
|
|
|
|
->to(ReceiverRequestFactory::new()->name('Familie Blabla'))
|
|
|
|
->sentAt(now()->subDay())
|
|
|
|
->via(BillKind::POST)
|
|
|
|
->status(InvoiceStatus::SENT)
|
|
|
|
->create(['usage' => 'Usa', 'mail_email' => 'a@b.de']);
|
2023-12-16 01:13:49 +01:00
|
|
|
|
2024-12-15 16:05:38 +01:00
|
|
|
sleep(2);
|
2024-09-21 18:29:47 +02:00
|
|
|
test()->get(route('invoice.index'))
|
|
|
|
->assertInertiaPath('data.data.0.to.name', 'Familie Blabla')
|
|
|
|
->assertInertiaPath('data.data.0.id', $invoice->id)
|
|
|
|
->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')
|
|
|
|
->assertInertiaPath('data.data.0.via', 'Post')
|
|
|
|
->assertInertiaPath('data.data.0.mail_email', 'a@b.de')
|
|
|
|
->assertInertiaPath('data.data.0.usage', 'Usa')
|
|
|
|
->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)
|
|
|
|
->assertInertiaPath('data.data.0.links.pdf', route('invoice.pdf', ['invoice' => $invoice]))
|
|
|
|
->assertInertiaPath('data.data.0.links.rememberpdf', route('invoice.rememberpdf', ['invoice' => $invoice]))
|
|
|
|
->assertInertiaPath('data.data.0.links.update', route('invoice.update', ['invoice' => $invoice]))
|
|
|
|
->assertInertiaPath('data.data.0.links.destroy', route('invoice.destroy', ['invoice' => $invoice]))
|
|
|
|
->assertInertiaPath('data.meta.links.mass-store', route('invoice.mass-store'))
|
|
|
|
->assertInertiaPath('data.meta.links.newInvoiceAttributes', route('invoice.new-invoice-attributes'))
|
|
|
|
->assertInertiaPath('data.meta.links.store', route('invoice.store'))
|
|
|
|
->assertInertiaPath('data.meta.links.masspdf', route('invoice.masspdf'))
|
|
|
|
->assertInertiaPath('data.meta.vias.0', ['id' => 'E-Mail', 'name' => 'E-Mail'])
|
|
|
|
->assertInertiaPath('data.meta.statuses.0', ['id' => 'Neu', 'name' => 'Neu'])
|
|
|
|
->assertInertiaPath('data.meta.members.0', ['id' => $member->id, 'name' => 'Aaaa Aaab'])
|
|
|
|
->assertInertiaPath('data.meta.subscriptions.0', ['name' => 'Beitrag', 'id' => $subscription->id])
|
|
|
|
->assertInertiaPath('data.meta.filter.statuses', ['Neu', 'Rechnung gestellt'])
|
|
|
|
->assertInertiaPath('data.meta.default', [
|
|
|
|
'to' => [
|
|
|
|
'name' => '',
|
|
|
|
'address' => '',
|
|
|
|
'zip' => '',
|
|
|
|
'location' => '',
|
|
|
|
],
|
|
|
|
'positions' => [],
|
|
|
|
'greeting' => '',
|
|
|
|
'status' => InvoiceStatus::NEW->value,
|
|
|
|
'via' => null,
|
|
|
|
'usage' => '',
|
|
|
|
'mail_email' => '',
|
|
|
|
])
|
|
|
|
->assertInertiaPath('data.meta.default_position', [
|
|
|
|
'id' => null,
|
|
|
|
'price' => 0,
|
|
|
|
'description' => '',
|
|
|
|
'member_id' => null,
|
|
|
|
]);
|
|
|
|
});
|
2023-12-16 01:13:49 +01:00
|
|
|
|
2024-09-21 18:29:47 +02:00
|
|
|
it('testValuesCanBeNull', function () {
|
|
|
|
test()->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
Invoice::factory()->create();
|
2023-12-16 13:08:17 +01:00
|
|
|
|
2024-12-15 16:05:38 +01:00
|
|
|
sleep(2);
|
2024-09-21 18:29:47 +02:00
|
|
|
test()->get(route('invoice.index'))
|
|
|
|
->assertInertiaPath('data.data.0.sent_at_human', '');
|
|
|
|
});
|
2023-12-16 13:08:17 +01:00
|
|
|
|
2024-12-15 16:05:38 +01:00
|
|
|
it('filters for invoice status', function (array $filter, int $count) {
|
2024-09-21 18:29:47 +02:00
|
|
|
test()->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
Invoice::factory()->status(InvoiceStatus::NEW)->create();
|
|
|
|
Invoice::factory()->status(InvoiceStatus::SENT)->count(2)->create();
|
|
|
|
Invoice::factory()->status(InvoiceStatus::PAID)->count(3)->create();
|
2024-05-14 01:29:39 +02:00
|
|
|
|
2024-12-15 16:05:38 +01:00
|
|
|
sleep(2);
|
|
|
|
test()->callFilter('invoice.index', $filter)->assertInertiaCount('data.data', $count);
|
|
|
|
})->with([
|
|
|
|
[[], 3],
|
|
|
|
[['statuses' => []], 0],
|
|
|
|
[['statuses' => ['Neu']], 1],
|
|
|
|
[['statuses' => ['Neu', 'Rechnung beglichen']], 4],
|
|
|
|
[['statuses' => ['Neu', 'Rechnung beglichen', 'Rechnung gestellt']], 6],
|
|
|
|
]);
|
|
|
|
|
|
|
|
it('searches invoice usage', function (array $filter, int $count) {
|
|
|
|
test()->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
Invoice::factory()->status(InvoiceStatus::NEW)->create(['usage' => 'Kein Zweck']);
|
|
|
|
Invoice::factory()->status(InvoiceStatus::NEW)->create(['usage' => 'Mitgliedsbeitrag']);
|
|
|
|
|
|
|
|
sleep(2);
|
|
|
|
test()->callFilter('invoice.index', $filter)->assertInertiaCount('data.data', $count);
|
|
|
|
})->with([
|
|
|
|
[['search' => 'Mitgliedsbeitrag'], 1],
|
|
|
|
[['search' => 'Kein'], 1],
|
|
|
|
]);
|