2023-12-16 00:16:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Invoice;
|
|
|
|
|
2023-12-16 11:18:00 +01:00
|
|
|
use App\Invoice\BillKind;
|
2023-12-16 00:16:07 +01:00
|
|
|
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'), [
|
2023-12-16 00:16:07 +01:00
|
|
|
'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'), [
|
2023-12-16 00:16:07 +01:00
|
|
|
'year' => now()->addYear()->year,
|
|
|
|
])->assertOk();
|
|
|
|
|
|
|
|
$this->assertDatabaseEmpty('invoices');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItCreatesPayments(): void
|
|
|
|
{
|
|
|
|
$member = Member::factory()->defaults()
|
|
|
|
->for(Subscription::factory()->children([
|
|
|
|
new Child('beitrag {name}', 4466),
|
|
|
|
new Child('beitrag2 für {name} für {year}', 2290),
|
|
|
|
]))->emailBillKind()->create(['firstname' => 'Max', 'lastname' => 'Muster', 'address' => 'Maxstr 4', 'zip' => '33445', 'location' => 'Solingen']);
|
|
|
|
|
2023-12-16 01:13:49 +01:00
|
|
|
$this->postJson(route('invoice.mass-store'), [
|
2023-12-16 00:16:07 +01:00
|
|
|
'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-16 11:18:00 +01:00
|
|
|
$this->assertEquals(BillKind::EMAIL, $invoice->via);
|
2023-12-16 00:16:07 +01:00
|
|
|
$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
|
|
|
|
{
|
|
|
|
$subscription = Subscription::factory()->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();
|
2023-12-16 00:16:07 +01:00
|
|
|
|
|
|
|
$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
|
|
|
|
{
|
|
|
|
$subscription = Subscription::factory()->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();
|
2023-12-16 00:16:07 +01:00
|
|
|
|
|
|
|
$this->assertDatabaseCount('invoices', 2);
|
|
|
|
$this->assertDatabaseCount('invoice_positions', 2);
|
|
|
|
}
|
|
|
|
}
|