2022-08-12 22:07:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Member;
|
|
|
|
|
|
|
|
use App\Activity;
|
|
|
|
use App\Country;
|
|
|
|
use App\Fee;
|
|
|
|
use App\Gender;
|
2022-11-16 22:59:49 +01:00
|
|
|
use App\Member\Actions\NamiPutMemberAction;
|
2022-08-12 22:07:59 +02:00
|
|
|
use App\Member\Member;
|
|
|
|
use App\Nationality;
|
|
|
|
use App\Payment\Subscription;
|
|
|
|
use App\Region;
|
|
|
|
use App\Subactivity;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\Lib\MergesAttributes;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class StoreTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
|
|
|
use MergesAttributes;
|
|
|
|
|
|
|
|
public function testItCanStoreAMember(): void
|
|
|
|
{
|
|
|
|
Fee::factory()->create();
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
$country = Country::factory()->create();
|
|
|
|
$gender = Gender::factory()->create();
|
|
|
|
$region = Region::factory()->create();
|
|
|
|
$nationality = Nationality::factory()->create();
|
|
|
|
$activity = Activity::factory()->create();
|
|
|
|
$subactivity = Subactivity::factory()->create();
|
|
|
|
$subscription = Subscription::factory()->create();
|
2022-11-16 22:59:49 +01:00
|
|
|
NamiPutMemberAction::allowToRun();
|
2022-08-12 22:07:59 +02:00
|
|
|
|
|
|
|
$response = $this
|
|
|
|
->from('/member/create')
|
|
|
|
->post('/member', $this->attributes([
|
|
|
|
'country_id' => $country->id,
|
|
|
|
'gender_id' => $gender->id,
|
|
|
|
'region_id' => $region->id,
|
|
|
|
'nationality_id' => $nationality->id,
|
|
|
|
'first_activity_id' => $activity->id,
|
|
|
|
'first_subactivity_id' => $subactivity->id,
|
|
|
|
'subscription_id' => $subscription->id,
|
2022-12-06 23:11:57 +01:00
|
|
|
'bill_kind' => 'Post',
|
2023-02-27 22:40:47 +01:00
|
|
|
'salutation' => 'Doktor',
|
2023-02-27 23:15:57 +01:00
|
|
|
'comment' => 'Lorem bla',
|
2022-08-12 22:07:59 +02:00
|
|
|
]));
|
|
|
|
|
2023-02-17 12:29:33 +01:00
|
|
|
$response->assertRedirect('/member')->assertSessionHasNoErrors();
|
2022-08-12 22:07:59 +02:00
|
|
|
$member = Member::firstWhere('firstname', 'Joe');
|
|
|
|
$this->assertDatabaseHas('members', [
|
|
|
|
'address' => 'Bavert 50',
|
2022-12-06 23:11:57 +01:00
|
|
|
'bill_kind' => 'Post',
|
2022-08-12 22:07:59 +02:00
|
|
|
'birthday' => '2013-02-19',
|
|
|
|
'children_phone' => '+49 123 44444',
|
|
|
|
'country_id' => $country->id,
|
|
|
|
'email_parents' => 'osloot@aol.com',
|
|
|
|
'firstname' => 'Joe',
|
|
|
|
'gender_id' => $gender->id,
|
|
|
|
'joined_at' => '2022-08-12',
|
|
|
|
'lastname' => 'Muster',
|
|
|
|
'letter_address' => null,
|
|
|
|
'location' => 'Solingen',
|
|
|
|
'main_phone' => '+49 212 2334322',
|
|
|
|
'mobile_phone' => '+49 157 53180451',
|
|
|
|
'nationality_id' => $nationality->id,
|
|
|
|
'region_id' => $region->id,
|
|
|
|
'send_newspaper' => '1',
|
|
|
|
'subscription_id' => $subscription->id,
|
|
|
|
'zip' => '42719',
|
|
|
|
'fax' => '+49 666',
|
2023-02-27 22:40:47 +01:00
|
|
|
'salutation' => 'Doktor',
|
2023-02-27 23:15:57 +01:00
|
|
|
'comment' => 'Lorem bla',
|
2022-08-12 22:07:59 +02:00
|
|
|
]);
|
2022-11-16 22:59:49 +01:00
|
|
|
NamiPutMemberAction::spy()->shouldHaveReceived('handle')->withArgs(fn (Member $memberParam, Activity $activityParam, Subactivity $subactivityParam) => $memberParam->is($member)
|
|
|
|
&& $activityParam->is($activity)
|
|
|
|
&& $subactivityParam->is($subactivity)
|
|
|
|
)->once();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItCanStoreAMemberWithoutNami(): void
|
|
|
|
{
|
|
|
|
$this->withoutExceptionHandling()->login()->loginNami();
|
|
|
|
$activity = Activity::factory()->create();
|
|
|
|
$subactivity = Subactivity::factory()->create();
|
|
|
|
|
|
|
|
$response = $this
|
|
|
|
->from('/member/create')
|
|
|
|
->post('/member', $this->attributes([
|
|
|
|
'first_activity_id' => $activity->id,
|
|
|
|
'first_subactivity_id' => $subactivity->id,
|
|
|
|
'has_nami' => false,
|
|
|
|
]));
|
|
|
|
|
2023-02-17 12:29:33 +01:00
|
|
|
$response->assertSessionHasNoErrors();
|
2022-11-16 22:59:49 +01:00
|
|
|
$this->assertDatabaseHas('members', [
|
|
|
|
'nami_id' => null,
|
|
|
|
]);
|
|
|
|
NamiPutMemberAction::spy()->shouldNotHaveReceived('handle');
|
|
|
|
}
|
|
|
|
|
2023-02-14 13:57:21 +01:00
|
|
|
public function testItRequiresFields(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami();
|
|
|
|
|
2023-02-17 12:29:33 +01:00
|
|
|
$this
|
2023-02-14 13:57:21 +01:00
|
|
|
->post('/member', $this->attributes([
|
|
|
|
'nationality_id' => null,
|
2023-02-17 12:29:33 +01:00
|
|
|
]))
|
|
|
|
->assertSessionHasErrors(['nationality_id']);
|
2023-02-14 13:57:21 +01:00
|
|
|
}
|
|
|
|
|
2022-11-16 22:59:49 +01:00
|
|
|
public function testSubscriptionIsRequiredIfFirstActivityIsPaid(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami();
|
2023-02-17 12:29:33 +01:00
|
|
|
$activity = Activity::factory()->name('€ Mitglied')->create();
|
2022-11-16 22:59:49 +01:00
|
|
|
$subactivity = Subactivity::factory()->create();
|
|
|
|
|
2023-02-17 12:29:33 +01:00
|
|
|
$this
|
2022-11-16 22:59:49 +01:00
|
|
|
->from('/member/create')
|
|
|
|
->post('/member', $this->attributes([
|
|
|
|
'first_activity_id' => $activity->id,
|
|
|
|
'first_subactivity_id' => $subactivity->id,
|
|
|
|
'subscription_id' => null,
|
2023-02-17 12:29:33 +01:00
|
|
|
]))
|
|
|
|
->assertSessionHasErrors(['subscription_id' => 'Beitragsart ist erforderlich.']);
|
2022-08-12 22:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function defaults(): array
|
|
|
|
{
|
2023-02-17 12:29:33 +01:00
|
|
|
$country = Country::factory()->create();
|
|
|
|
$nationality = Nationality::factory()->create();
|
|
|
|
$subscription = Subscription::factory()->create();
|
|
|
|
|
2022-08-12 22:07:59 +02:00
|
|
|
return [
|
|
|
|
'address' => 'Bavert 50',
|
|
|
|
'birthday' => '2013-02-19',
|
|
|
|
'children_phone' => '+49 123 44444',
|
|
|
|
'efz' => '',
|
|
|
|
'email' => '',
|
|
|
|
'email_parents' => 'osloot@aol.com',
|
|
|
|
'fax' => '+49 666',
|
|
|
|
'firstname' => 'Joe',
|
|
|
|
'further_address' => '',
|
|
|
|
'has_nami' => true,
|
|
|
|
'has_svk' => false,
|
|
|
|
'has_vk' => false,
|
|
|
|
'joined_at' => '2022-08-12',
|
|
|
|
'lastname' => 'Muster',
|
|
|
|
'letter_address' => '',
|
|
|
|
'location' => 'Solingen',
|
|
|
|
'main_phone' => '+49 212 2334322',
|
|
|
|
'mobile_phone' => '+49 157 53180451',
|
|
|
|
'more_ps_at' => '',
|
|
|
|
'multiply_more_pv' => false,
|
|
|
|
'multiply_pv' => false,
|
|
|
|
'other_country' => '',
|
|
|
|
'ps_at' => '',
|
|
|
|
'send_newspaper' => true,
|
|
|
|
'without_education_at' => '',
|
|
|
|
'without_efz_at' => '',
|
|
|
|
'work_phone' => '',
|
|
|
|
'zip' => '42719',
|
2023-02-17 12:29:33 +01:00
|
|
|
'country_id' => $country->id,
|
|
|
|
'nationality_id' => $nationality->id,
|
|
|
|
'subscription_id' => $subscription->id,
|
2022-08-12 22:07:59 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|