Add member indexTest

This commit is contained in:
philipp lang 2022-11-16 22:28:42 +01:00
parent 6e7601e3d4
commit 259591393f
3 changed files with 36 additions and 20 deletions
app
tests/Feature/Member

View File

@ -57,9 +57,7 @@ class MemberResource extends JsonResource
'payments' => PaymentResource::collection($this->whenLoaded('payments')),
'memberships' => MembershipResource::collection($this->whenLoaded('memberships')),
'pending_payment' => $this->pending_payment ? number_format($this->pending_payment / 100, 2, ',', '.').' €' : null,
'first_activity_id' => $this->first_activity_id,
'first_subactivity_id' => $this->first_subactivity_id,
'age_group_icon' => $this->age_group_icon,
'age_group_icon' => $this->ageGroupMemberships->first()?->subactivity->slug,
'courses' => CourseResource::collection($this->whenLoaded('courses')),
'efz' => $this->efz,
'efz_link' => $this->getEfzLink(),
@ -72,7 +70,7 @@ class MemberResource extends JsonResource
'multiply_pv' => $this->multiply_pv,
'multiply_more_pv' => $this->multiply_more_pv,
'age' => $this->getModel()->getAge(),
'is_leader' => $this->is_leader,
'is_leader' => $this->leaderMemberships->count() > 0,
];
}
}

View File

@ -23,7 +23,7 @@ class MembershipResource extends JsonResource
'activity_id' => $this->activity_id,
'activity_name' => $this->activity->name,
'subactivity_id' => $this->subactivity_id,
'subactivity_name' => optional($this->subactivity)->name,
'subactivity_name' => $this->subactivity?->name,
'human_date' => $this->created_at->format('d.m.Y'),
];
}

View File

@ -8,6 +8,7 @@ use App\Course\Models\CourseMember;
use App\Member\Member;
use App\Member\Membership;
use App\Subactivity;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
use Zoomyboy\LaravelNami\Backend\FakeBackend;
@ -37,8 +38,7 @@ class IndexTest extends TestCase
'gruppierung' => '::group::',
'version' => 40,
]);
$this->withoutExceptionHandling();
$this->login()->loginNami();
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults()->has(CourseMember::factory()->for(Course::factory()), 'courses')->create(['firstname' => '::firstname::']);
$response = $this->get('/member');
@ -49,15 +49,14 @@ class IndexTest extends TestCase
public function testItShowsEfzForEfzMembership(): void
{
$this->withoutExceptionHandling();
$this->login()->loginNami();
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()
->defaults()
->has(Membership::factory()->for(Subactivity::factory()->ageGroup())->for(Activity::factory()->state(['has_efz' => true])))
->has(Membership::factory()->in('€ LeiterIn', 455, 'Pfadfinder', 15))
->create(['lastname' => 'A']);
Member::factory()
->defaults()
->has(Membership::factory()->for(Subactivity::factory()->ageGroup())->for(Activity::factory()->state(['has_efz' => false])))
->has(Membership::factory()->in('€ Mitglied', 456, 'Pfadfinder', 16))
->create(['lastname' => 'B']);
Member::factory()
->defaults()
@ -75,11 +74,10 @@ class IndexTest extends TestCase
public function testItShowsAgeGroupIcon(): void
{
$this->withoutExceptionHandling();
$this->login()->loginNami();
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()
->defaults()
->has(Membership::factory()->for(Subactivity::factory()->ageGroup()->name('Wölfling'))->for(Activity::factory()->state(['has_efz' => false])))
->has(Membership::factory()->in('€ Mitglied', 123, 'Wölfling', 12))
->create();
$response = $this->get('/member');
@ -89,15 +87,35 @@ class IndexTest extends TestCase
public function testItShowsActivitiesAndSubactivities(): void
{
$this->withoutExceptionHandling();
$this->login()->loginNami();
$activity = Activity::factory()->hasAttached(Subactivity::factory()->name('SG Nahost')->ageGroup()->filterable())->name('Mitglied')->create();
$this->withoutExceptionHandling()->login()->loginNami();
$activity = Activity::factory()->hasAttached(Subactivity::factory()->name('Biber'))->name('€ Mitglied')->create();
$subactivity = $activity->subactivities->first();
$response = $this->get('/member');
$this->assertInertiaHas('SG Nahost', $response, "subactivities.{$activity->id}.{$subactivity->id}");
$this->assertInertiaHas('SG Nahost', $response, "filterSubactivities.{$subactivity->id}");
$this->assertInertiaHas('Mitglied', $response, "activities.{$activity->id}");
$this->assertInertiaHas('Biber', $response, "subactivities.{$activity->id}.{$subactivity->id}");
$this->assertInertiaHas('Biber', $response, "filterSubactivities.{$subactivity->id}");
$this->assertInertiaHas('€ Mitglied', $response, "activities.{$activity->id}");
}
public function testItShowsActivityAndSubactivityNamesOfMember(): void
{
Carbon::setTestNow(Carbon::parse('2022-11-02 03:00:00'));
$this->withoutExceptionHandling()->login()->loginNami();
$member = Member::factory()
->defaults()
->has(Membership::factory()->in('€ Mitglied', 122, 'Wölfling', 234))
->create();
$response = $this->get('/member');
$this->assertInertiaHas([
'activity' => $member->memberships->first()->activity_id,
'subactivity' => $member->memberships->first()->subactivity_id,
'activity_name' => '€ Mitglied',
'subactivity_name' => 'Wölfling',
'human_date' => '02.11.2022',
'id' => $member->memberships->first()->id,
], $response, 'data.data.0.memberships.0');
}
}