Set default member model as meta

This commit is contained in:
philipp lang 2024-08-28 13:26:30 +02:00
parent 151477dbdd
commit 298140e387
4 changed files with 56 additions and 66 deletions

View File

@ -33,7 +33,6 @@ class MemberController extends Controller
session()->put('title', 'Mitglied erstellen'); session()->put('title', 'Mitglied erstellen');
return Inertia::render('member/VForm', [ return Inertia::render('member/VForm', [
'data' => MemberResource::defaultModel(),
'mode' => 'create', 'mode' => 'create',
'meta' => MemberResource::meta(), 'meta' => MemberResource::meta(),
]); ]);

View File

@ -162,54 +162,47 @@ class MemberResource extends JsonResource
'activity_ids' => [], 'activity_ids' => [],
'subactivity_ids' => [] 'subactivity_ids' => []
], ],
]; 'default' => [
} 'gender_id' => null,
'salutation' => '',
/** 'nationality_id' => null,
* @return array<string, mixed> 'firstname' => '',
*/ 'lastname' => '',
public static function defaultModel(): array 'address' => '',
{ 'further_address' => '',
return [ 'zip' => '',
'gender_id' => null, 'location' => '',
'salutation' => '', 'birthday' => '',
'nationality_id' => null, 'region_id' => null,
'firstname' => '', 'country_id' => Country::default(),
'lastname' => '', 'other_country' => '',
'address' => '', 'main_phone' => '',
'further_address' => '', 'mobile_phone' => '',
'zip' => '', 'work_phone' => '',
'location' => '', 'children_phone' => '',
'birthday' => '', 'email' => '',
'region_id' => null, 'email_parents' => '',
'country_id' => Country::default(), 'fax' => '',
'other_country' => '', 'letter_address' => '',
'main_phone' => '', 'bill_kind' => null,
'mobile_phone' => '', 'subscription_id' => null,
'work_phone' => '', 'has_nami' => false,
'children_phone' => '', 'send_newspaper' => false,
'email' => '', 'joined_at' => now()->format('Y-m-d'),
'email_parents' => '', 'comment' => '',
'fax' => '', 'first_activity_id' => null,
'letter_address' => '', 'first_subactivity_id' => null,
'bill_kind' => null, 'efz' => null,
'subscription_id' => null, 'ps_at' => null,
'has_nami' => false, 'more_ps_at' => null,
'send_newspaper' => false, 'without_education_at' => null,
'joined_at' => now()->format('Y-m-d'), 'recertified_at' => null,
'comment' => '', 'without_efz_at' => null,
'first_activity_id' => null, 'has_vk' => false,
'first_subactivity_id' => null, 'has_svk' => false,
'efz' => null, 'multiply_pv' => false,
'ps_at' => null, 'multiply_more_pv' => false,
'more_ps_at' => null, ]
'without_education_at' => null,
'recertified_at' => null,
'without_efz_at' => null,
'has_vk' => false,
'has_svk' => false,
'multiply_pv' => false,
'multiply_more_pv' => false,
]; ];
} }
} }

View File

@ -153,8 +153,8 @@ export default {
}, },
data: function () { data: function () {
return { return {
original: {...this.data}, original: this.mode === 'create' ? {...this.meta.default} : {...this.data},
inner: {...this.data}, inner: this.mode === 'create' ? {...this.meta.default} : {...this.data},
active: 0, active: 0,
}; };
}, },

View File

@ -3,6 +3,7 @@
namespace Tests\EndToEnd; namespace Tests\EndToEnd;
use App\Activity; use App\Activity;
use App\Country;
use App\Group; use App\Group;
use App\Invoice\BillKind; use App\Invoice\BillKind;
use App\Invoice\Enums\InvoiceStatus; use App\Invoice\Enums\InvoiceStatus;
@ -16,9 +17,15 @@ use Tests\EndToEndTestCase;
class MemberIndexTest extends EndToEndTestCase class MemberIndexTest extends EndToEndTestCase
{ {
public function setUp(): void
{
parent::setUp();
Country::factory()->create(['name' => 'Deutschland']);
$this->withoutExceptionHandling()->login()->loginNami();
}
public function testItHandlesFullTextSearch(): void public function testItHandlesFullTextSearch(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults()->count(2)->create(['firstname' => 'Alexander']); Member::factory()->defaults()->count(2)->create(['firstname' => 'Alexander']);
Member::factory()->defaults()->create(['firstname' => 'Heinrich']); Member::factory()->defaults()->create(['firstname' => 'Heinrich']);
@ -29,9 +36,13 @@ class MemberIndexTest extends EndToEndTestCase
->assertInertiaCount('data.data', 1); ->assertInertiaCount('data.data', 1);
} }
public function testItGetsDefaultCountryFromDefaultModel(): void
{
$this->callFilter('member.index', [])->assertInertiaPath('data.meta.default.country_id', Country::firstWhere('name', 'Deutschland')->id);
}
public function testItHandlesAddress(): void public function testItHandlesAddress(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults()->create(['address' => '']); Member::factory()->defaults()->create(['address' => '']);
Member::factory()->defaults()->create(['zip' => '']); Member::factory()->defaults()->create(['zip' => '']);
Member::factory()->defaults()->create(['location' => '']); Member::factory()->defaults()->create(['location' => '']);
@ -52,7 +63,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItHandlesBirthday(): void public function testItHandlesBirthday(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults()->create(['birthday' => null]); Member::factory()->defaults()->create(['birthday' => null]);
Member::factory()->defaults()->count(2)->create(); Member::factory()->defaults()->count(2)->create();
@ -65,7 +75,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItHandlesBillKind(): void public function testItHandlesBillKind(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults()->postBillKind()->create(); Member::factory()->defaults()->postBillKind()->create();
Member::factory()->defaults()->emailBillKind()->count(2)->create(); Member::factory()->defaults()->emailBillKind()->count(2)->create();
@ -80,7 +89,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItHandlesGroupIds(): void public function testItHandlesGroupIds(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
$group = Group::factory()->create(); $group = Group::factory()->create();
$otherGroup = Group::factory()->create(); $otherGroup = Group::factory()->create();
$thirdGroup = Group::factory()->create(); $thirdGroup = Group::factory()->create();
@ -101,7 +109,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItHandlesActivitiesAndSubactivities(): void public function testItHandlesActivitiesAndSubactivities(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
$mitglied = Activity::factory()->name('€ Mitglied')->create(); $mitglied = Activity::factory()->name('€ Mitglied')->create();
$schnuppermitglied = Activity::factory()->name('Schnuppermitgliedschaft')->create(); $schnuppermitglied = Activity::factory()->name('Schnuppermitgliedschaft')->create();
$woelfling = Subactivity::factory()->name('Wölfling')->create(); $woelfling = Subactivity::factory()->name('Wölfling')->create();
@ -127,7 +134,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItHandlesActivityAndSubactivityForSingleMembership(): void public function testItHandlesActivityAndSubactivityForSingleMembership(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
$mitglied = Activity::factory()->name('€ Mitglied')->create(); $mitglied = Activity::factory()->name('€ Mitglied')->create();
$schnuppermitglied = Activity::factory()->name('Schnuppermitgliedschaft')->create(); $schnuppermitglied = Activity::factory()->name('Schnuppermitgliedschaft')->create();
$woelfling = Subactivity::factory()->name('Wölfling')->create(); $woelfling = Subactivity::factory()->name('Wölfling')->create();
@ -144,7 +150,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItIgnoresInactiveMemberships(): void public function testItIgnoresInactiveMemberships(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
$mitglied = Activity::factory()->name('€ Mitglied')->create(); $mitglied = Activity::factory()->name('€ Mitglied')->create();
$woelfling = Subactivity::factory()->name('Wölfling')->create(); $woelfling = Subactivity::factory()->name('Wölfling')->create();
Member::factory()->defaults()->has(Membership::factory()->for($mitglied)->for($woelfling)->ended())->create(); Member::factory()->defaults()->has(Membership::factory()->for($mitglied)->for($woelfling)->ended())->create();
@ -158,7 +163,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItListensForMembershipDeletion(): void public function testItListensForMembershipDeletion(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
$mitglied = Activity::factory()->name('€ Mitglied')->create(); $mitglied = Activity::factory()->name('€ Mitglied')->create();
$member = Member::factory()->defaults()->has(Membership::factory()->for($mitglied))->create(); $member = Member::factory()->defaults()->has(Membership::factory()->for($mitglied))->create();
$member->memberships->first()->delete(); $member->memberships->first()->delete();
@ -171,7 +175,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItFiltersForMemberships(): void public function testItFiltersForMemberships(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
$mitglied = Activity::factory()->create(); $mitglied = Activity::factory()->create();
$woelfling = Subactivity::factory()->create(); $woelfling = Subactivity::factory()->create();
$juffi = Subactivity::factory()->create(); $juffi = Subactivity::factory()->create();
@ -201,7 +204,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testGroupOfMembershipsFilterCanBeEmpty(): void public function testGroupOfMembershipsFilterCanBeEmpty(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
$mitglied = Activity::factory()->create(); $mitglied = Activity::factory()->create();
$woelfling = Subactivity::factory()->create(); $woelfling = Subactivity::factory()->create();
$group = Group::factory()->create(); $group = Group::factory()->create();
@ -221,7 +223,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItFiltersForSearchButNotForPayments(): void public function testItFiltersForSearchButNotForPayments(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults() Member::factory()->defaults()
->has(InvoicePosition::factory()->for(Invoice::factory())) ->has(InvoicePosition::factory()->for(Invoice::factory()))
->create(['firstname' => 'firstname']); ->create(['firstname' => 'firstname']);
@ -234,7 +235,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItIgnoresPaidInvoices(): void public function testItIgnoresPaidInvoices(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults() Member::factory()->defaults()
->has(InvoicePosition::factory()->for(Invoice::factory()->status(InvoiceStatus::PAID))) ->has(InvoicePosition::factory()->for(Invoice::factory()->status(InvoiceStatus::PAID)))
->create(); ->create();
@ -247,7 +247,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItIncludesMembers(): void public function testItIncludesMembers(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()->defaults()->create(['birthday' => null, 'location' => '']); $member = Member::factory()->defaults()->create(['birthday' => null, 'location' => '']);
sleep(1); sleep(1);
@ -259,7 +258,6 @@ class MemberIndexTest extends EndToEndTestCase
public function testItExcludesMembers(): void public function testItExcludesMembers(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()->defaults()->create(['birthday' => null]); $member = Member::factory()->defaults()->create(['birthday' => null]);
sleep(1); sleep(1);