2023-02-05 23:35:08 +01:00
|
|
|
<?php
|
|
|
|
|
2023-02-07 01:41:29 +01:00
|
|
|
namespace Tests\Feature\Member;
|
2023-02-05 23:35:08 +01:00
|
|
|
|
|
|
|
use App\Actions\PullMemberAction;
|
|
|
|
use App\Country;
|
|
|
|
use App\Fee;
|
|
|
|
use App\Gender;
|
|
|
|
use App\Group;
|
|
|
|
use App\Nationality;
|
|
|
|
use App\Payment\Subscription;
|
|
|
|
use App\Region;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\TestCase;
|
|
|
|
use Zoomyboy\LaravelNami\Fakes\MemberFake;
|
|
|
|
|
|
|
|
class PullMemberActionTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2024-02-22 11:13:20 +01:00
|
|
|
Subscription::factory()->name('test')->forFee(300)->create();
|
2023-02-05 23:35:08 +01:00
|
|
|
Gender::factory()->inNami(303)->create();
|
|
|
|
Country::factory()->inNami(302)->create();
|
|
|
|
Nationality::factory()->inNami(1054)->create();
|
|
|
|
$this->loginNami();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFetchNormalMember(): void
|
|
|
|
{
|
|
|
|
app(MemberFake::class)->shows(1000, 1001, [
|
|
|
|
'vorname' => '::firstname::',
|
|
|
|
'nachname' => '::lastname::',
|
|
|
|
'beitragsartId' => 300,
|
|
|
|
'geburtsDatum' => '2014-07-11 00:00:00',
|
|
|
|
'gruppierungId' => 1000,
|
|
|
|
'geschlechtId' => 303,
|
|
|
|
'id' => 1001,
|
|
|
|
'eintrittsdatum' => '2020-11-17 00:00:00',
|
|
|
|
'landId' => 302,
|
|
|
|
'staatsangehoerigkeitId' => 1054,
|
|
|
|
'zeitschriftenversand' => true,
|
|
|
|
'strasse' => '::street::',
|
|
|
|
'plz' => '12346',
|
|
|
|
'ort' => '::location::',
|
|
|
|
'version' => 40,
|
|
|
|
'gruppierung' => 'SG Wald',
|
2023-03-02 23:14:25 +01:00
|
|
|
'mitgliedsNummer' => 53,
|
2023-02-05 23:35:08 +01:00
|
|
|
]);
|
|
|
|
|
2023-02-07 01:39:39 +01:00
|
|
|
$member = app(PullMemberAction::class)->handle(1000, 1001);
|
2023-02-05 23:35:08 +01:00
|
|
|
|
|
|
|
$this->assertDatabaseHas('members', [
|
|
|
|
'firstname' => '::firstname::',
|
|
|
|
'lastname' => '::lastname::',
|
|
|
|
'subscription_id' => Subscription::firstWhere('name', 'test')->id,
|
|
|
|
'birthday' => '2014-07-11',
|
|
|
|
'group_id' => Group::nami(1000)->id,
|
|
|
|
'gender_id' => Gender::nami(303)->id,
|
|
|
|
'nami_id' => 1001,
|
|
|
|
'joined_at' => '2020-11-17',
|
|
|
|
'country_id' => Country::nami(302)->id,
|
|
|
|
'nationality_id' => Nationality::nami(1054)->id,
|
|
|
|
'send_newspaper' => 1,
|
|
|
|
'address' => '::street::',
|
|
|
|
'zip' => '12346',
|
|
|
|
'location' => '::location::',
|
|
|
|
'version' => '40',
|
2023-03-02 23:14:25 +01:00
|
|
|
'mitgliedsnr' => 53,
|
2023-02-05 23:35:08 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('groups', [
|
|
|
|
'name' => 'SG Wald',
|
|
|
|
'nami_id' => 1000,
|
2023-12-30 18:46:47 +01:00
|
|
|
'inner_name' => 'SG Wald',
|
2023-02-05 23:35:08 +01:00
|
|
|
]);
|
2023-02-07 01:39:39 +01:00
|
|
|
$this->assertEquals(1001, $member->nami_id);
|
2023-02-05 23:35:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRegionIdIsSetToNull(): void
|
|
|
|
{
|
|
|
|
Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]);
|
|
|
|
app(MemberFake::class)->shows(1000, 1001, [
|
|
|
|
'regionId' => 999,
|
|
|
|
]);
|
|
|
|
|
|
|
|
app(PullMemberAction::class)->handle(1000, 1001);
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('members', [
|
|
|
|
'region_id' => null,
|
|
|
|
]);
|
|
|
|
}
|
2023-03-06 09:49:03 +01:00
|
|
|
|
|
|
|
public function testItSetsFirstSubscriptionFromFee(): void
|
|
|
|
{
|
|
|
|
Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]);
|
2024-02-22 11:13:20 +01:00
|
|
|
$should = Subscription::factory()->forFee(55)->create();
|
2023-03-06 09:49:03 +01:00
|
|
|
app(MemberFake::class)->shows(1000, 1001, [
|
|
|
|
'beitragsartId' => 55,
|
|
|
|
]);
|
|
|
|
|
|
|
|
app(PullMemberAction::class)->handle(1000, 1001);
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('members', [
|
|
|
|
'subscription_id' => $should->id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItCreatesSubscriptionOnTheFly(): void
|
|
|
|
{
|
|
|
|
Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]);
|
|
|
|
app(MemberFake::class)->shows(1000, 1001, [
|
|
|
|
'beitragsartId' => 55,
|
|
|
|
'beitragsart' => 'Lala',
|
|
|
|
]);
|
|
|
|
|
|
|
|
app(PullMemberAction::class)->handle(1000, 1001);
|
|
|
|
|
|
|
|
$fee = Fee::where('nami_id', 55)->firstOrFail();
|
|
|
|
$subscription = Subscription::where('fee_id', $fee->id)->firstOrFail();
|
|
|
|
$this->assertDatabaseHas('subscriptions', [
|
|
|
|
'fee_id' => $fee->id,
|
|
|
|
'name' => 'Lala',
|
|
|
|
]);
|
|
|
|
$this->assertDatabaseHas('subscription_children', [
|
|
|
|
'name' => 'Lala',
|
|
|
|
'amount' => 1000,
|
|
|
|
'parent_id' => $subscription->id,
|
|
|
|
]);
|
2023-03-06 09:49:43 +01:00
|
|
|
$this->assertDatabaseHas('members', [
|
|
|
|
'subscription_id' => $subscription->id,
|
|
|
|
]);
|
2023-03-06 09:49:03 +01:00
|
|
|
}
|
2023-03-06 15:18:48 +01:00
|
|
|
|
|
|
|
public function testItPullsMemberWithNoSubscription(): void
|
|
|
|
{
|
|
|
|
Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]);
|
|
|
|
app(MemberFake::class)->shows(1000, 1001, [
|
|
|
|
'beitragsartId' => null,
|
|
|
|
'beitragsart' => null,
|
|
|
|
]);
|
|
|
|
|
|
|
|
app(PullMemberAction::class)->handle(1000, 1001);
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('members', [
|
|
|
|
'subscription_id' => null,
|
|
|
|
]);
|
|
|
|
}
|
2023-02-05 23:35:08 +01:00
|
|
|
}
|