adrema/tests/Feature/Invoice/MassStoreActionTest.php

109 lines
4.1 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\Invoice;
2023-12-16 11:18:00 +01:00
use App\Invoice\BillKind;
use App\Invoice\Models\Invoice;
use App\Member\Member;
use App\Payment\Subscription;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\RequestFactories\Child;
use Tests\TestCase;
class MassStoreActionTest extends TestCase
{
use DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
$this->login()->loginNami()->withoutExceptionHandling();
}
public function testItDoesntCreatePaymentsWithoutSubscription(): void
{
Member::factory()->defaults()->emailBillKind()->create(['subscription_id' => null]);
2023-12-16 01:13:49 +01:00
$this->postJson(route('invoice.mass-store'), [
'year' => now()->addYear()->year,
])->assertOk();
$this->assertDatabaseEmpty('invoices');
}
public function testItDoesntCreatePaymentWithoutBillKind(): void
{
Member::factory()->defaults()->create();
2023-12-16 01:13:49 +01:00
$this->postJson(route('invoice.mass-store'), [
'year' => now()->addYear()->year,
])->assertOk();
$this->assertDatabaseEmpty('invoices');
}
public function testItCreatesPayments(): void
{
$member = Member::factory()->defaults()
2024-02-22 11:13:20 +01:00
->for(Subscription::factory()->forFee()->children([
new Child('beitrag {name}', 4466),
new Child('beitrag2 für {name} für {year}', 2290),
2023-12-18 01:15:16 +01:00
]))->emailBillKind()->create(['firstname' => 'Max', 'lastname' => 'Muster', 'address' => 'Maxstr 4', 'zip' => '33445', 'location' => 'Solingen', 'email' => 'lala@b.de']);
2023-12-16 01:13:49 +01:00
$this->postJson(route('invoice.mass-store'), [
'year' => now()->addYear()->year,
])->assertOk();
$invoice = Invoice::first();
$this->assertNotNull($invoice);
$this->assertEquals([
'name' => 'Familie Muster',
'address' => 'Maxstr 4',
'zip' => '33445',
'location' => 'Solingen',
], $invoice->to);
2023-12-17 23:29:01 +01:00
$this->assertEquals('Mitgliedsbeitrag für Muster', $invoice->usage);
2023-12-18 01:15:16 +01:00
$this->assertEquals('lala@b.de', $invoice->mail_email);
2023-12-16 11:18:00 +01:00
$this->assertEquals(BillKind::EMAIL, $invoice->via);
$this->assertDatabaseHas('invoice_positions', [
'invoice_id' => $invoice->id,
'member_id' => $member->id,
'price' => 4466,
'description' => 'beitrag Max Muster'
]);
$this->assertDatabaseHas('invoice_positions', [
'invoice_id' => $invoice->id,
'member_id' => $member->id,
'price' => 2290,
'description' => 'beitrag2 für Max Muster für ' . now()->addYear()->year
]);
}
public function testItCreatesOneInvoiceForFamilyMember(): void
{
2024-02-22 11:13:20 +01:00
$subscription = Subscription::factory()->forFee()->children([new Child('beitrag {name}', 4466)])->create();
$member = Member::factory()->defaults()->for($subscription)->emailBillKind()->create(['firstname' => 'Max', 'lastname' => 'Muster']);
Member::factory()->defaults()->for($subscription)->sameFamilyAs($member)->emailBillKind()->create(['firstname' => 'Jane']);
2023-12-16 01:13:49 +01:00
$this->postJson(route('invoice.mass-store'), ['year' => now()->addYear()->year])->assertOk();
$this->assertDatabaseCount('invoices', 1);
$this->assertDatabaseCount('invoice_positions', 2);
$this->assertDatabaseHas('invoice_positions', ['description' => 'beitrag Max Muster']);
$this->assertDatabaseHas('invoice_positions', ['description' => 'beitrag Jane Muster']);
}
public function testItSeparatesBillKinds(): void
{
2024-02-22 11:13:20 +01:00
$subscription = Subscription::factory()->forFee()->children([new Child('beitrag {name]', 4466)])->create();
$member = Member::factory()->defaults()->for($subscription)->emailBillKind()->create();
Member::factory()->defaults()->for($subscription)->sameFamilyAs($member)->postBillKind()->create();
2023-12-16 01:13:49 +01:00
$this->postJson(route('invoice.mass-store'), ['year' => now()->addYear()->year])->assertOk();
$this->assertDatabaseCount('invoices', 2);
$this->assertDatabaseCount('invoice_positions', 2);
}
}