adrema/tests/Feature/Member/IndexTest.php

76 lines
2.8 KiB
PHP
Raw Normal View History

2021-07-17 15:58:38 +02:00
<?php
namespace Tests\Feature\Member;
2022-03-20 16:33:56 +01:00
use App\Activity;
2021-11-20 01:43:20 +01:00
use App\Course\Models\Course;
use App\Course\Models\CourseMember;
2021-07-17 15:58:38 +02:00
use App\Member\Member;
2022-03-20 16:33:56 +01:00
use App\Member\Membership;
use App\Subactivity;
2022-02-12 01:08:56 +01:00
use Illuminate\Foundation\Testing\DatabaseTransactions;
2021-07-17 15:58:38 +02:00
use Tests\TestCase;
2022-02-11 01:24:09 +01:00
use Zoomyboy\LaravelNami\Backend\FakeBackend;
2021-07-17 15:58:38 +02:00
class IndexTest extends TestCase
{
2022-02-12 01:08:56 +01:00
use DatabaseTransactions;
2021-07-17 15:58:38 +02:00
public function testItGetsMembers(): void
{
2022-02-11 01:24:09 +01:00
$backend = app(FakeBackend::class)
->fakeMember([
'vorname' => '::firstname::',
'nachname' => '::lastname::',
'beitragsartId' => 300,
'geburtsDatum' => '2014-07-11 00:00:00',
'gruppierungId' => 1000,
'id' => 411,
'eintrittsdatum' => '2020-11-17 00:00:00',
'geschlechtId' => 303,
'landId' => 302,
'staatsangehoerigkeitId' => 291,
'zeitschriftenversand' => true,
'strasse' => '::street',
'plz' => '12346',
'ort' => '::location::',
'gruppierung' => '::group::',
'version' => 40,
]);
2021-07-17 15:58:38 +02:00
$this->withoutExceptionHandling();
2022-08-30 23:42:21 +02:00
$this->login()->loginNami();
2022-02-12 00:41:52 +01:00
Member::factory()->defaults()->has(CourseMember::factory()->for(Course::factory()), 'courses')->create(['firstname' => '::firstname::']);
2021-07-17 15:58:38 +02:00
2022-02-12 00:41:52 +01:00
$response = $this->get('/member');
2022-02-12 15:33:16 +01:00
$this->assertComponent('member/VIndex', $response);
2022-02-12 00:41:52 +01:00
$this->assertInertiaHas('::firstname::', $response, 'data.data.0.firstname');
2021-07-17 15:58:38 +02:00
}
2022-03-20 16:33:56 +01:00
public function testItShowsEfzForEfzMembership(): void
{
$this->withoutExceptionHandling();
2022-08-30 23:42:21 +02:00
$this->login()->loginNami();
2022-03-20 16:33:56 +01:00
$member = Member::factory()
->defaults()
2022-09-06 01:25:04 +02:00
->has(Membership::factory()->for(Subactivity::factory()->ageGroup())->for(Activity::factory()->state(['has_efz' => true])))
2022-03-20 16:33:56 +01:00
->create(['lastname' => 'A']);
Member::factory()
->defaults()
2022-09-06 01:25:04 +02:00
->has(Membership::factory()->for(Subactivity::factory()->ageGroup())->for(Activity::factory()->state(['has_efz' => false])))
2022-03-20 16:33:56 +01:00
->create(['lastname' => 'B']);
Member::factory()
->defaults()
->create(['lastname' => 'C']);
$response = $this->get('/member');
$this->assertInertiaHas(url("/member/{$member->id}/efz"), $response, 'data.data.0.efz_link');
$this->assertInertiaHas(null, $response, 'data.data.1.efz_link');
$this->assertInertiaHas(null, $response, 'data.data.2.efz_link');
2022-09-06 01:25:04 +02:00
$this->assertInertiaHas(true, $response, 'data.data.0.is_leader');
$this->assertInertiaHas(false, $response, 'data.data.1.is_leader');
$this->assertInertiaHas(false, $response, 'data.data.2.is_leader');
2022-03-20 16:33:56 +01:00
}
2021-07-17 15:58:38 +02:00
}