diff --git a/app/Member/Actions/MemberShowAction.php b/app/Member/Actions/MemberShowAction.php index 55515e60..9b7ce5a1 100644 --- a/app/Member/Actions/MemberShowAction.php +++ b/app/Member/Actions/MemberShowAction.php @@ -4,38 +4,24 @@ namespace App\Member\Actions; use App\Member\Member; use App\Member\MemberResource; -use Inertia\Inertia; -use Inertia\Response; +use Illuminate\Http\JsonResponse; use Lorisleiva\Actions\Concerns\AsAction; class MemberShowAction { use AsAction; - /** - * @return array{data: MemberResource} - */ - public function handle(Member $member): array + public function asController(Member $member): JsonResponse { - return [ - 'data' => new MemberResource( - $member - ->load('memberships') - ->load('invoicePositions.invoice') - ->load('nationality') - ->load('region') - ->load('subscription') - ->load('courses.course') - ), + return response()->json([ + 'data' => new MemberResource($member + ->load('memberships') + ->load('invoicePositions.invoice') + ->load('nationality') + ->load('region') + ->load('subscription') + ->load('courses.course')), 'meta' => MemberResource::meta(), - ]; - } - - public function asController(Member $member): Response - { - session()->put('menu', 'member'); - session()->put('title', 'Mitglied ' . $member->fullname); - - return Inertia::render('member/ShowView', $this->handle($member)); + ]); } } diff --git a/app/Member/MemberController.php b/app/Member/MemberController.php index 19bf94b0..231759c5 100644 --- a/app/Member/MemberController.php +++ b/app/Member/MemberController.php @@ -27,17 +27,6 @@ class MemberController extends Controller ]); } - public function create(): Response - { - session()->put('menu', 'member'); - session()->put('title', 'Mitglied erstellen'); - - return Inertia::render('member/VForm', [ - 'mode' => 'create', - 'meta' => MemberResource::meta(), - ]); - } - public function store(MemberRequest $request, NamiSettings $settings): RedirectResponse { $request->persistCreate($settings); @@ -45,19 +34,6 @@ class MemberController extends Controller return redirect()->route('member.index'); } - public function edit(Member $member, Request $request): Response - { - session()->put('menu', 'member'); - session()->put('title', "Mitglied {$member->firstname} {$member->lastname} bearbeiten"); - - return Inertia::render('member/VForm', [ - 'data' => new MemberResource($member), - 'mode' => 'edit', - 'conflict' => '1' === $request->query('conflict', '0'), - 'meta' => MemberResource::meta(), - ]); - } - public function update(Member $member, MemberRequest $request): RedirectResponse { try { diff --git a/routes/web.php b/routes/web.php index 7996811b..2bf4b69c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -90,7 +90,7 @@ Route::group(['middleware' => 'auth:web'], function (): void { Route::post('/nami/search', NamiSearchAction::class)->name('nami.search'); Route::get('/initialize', InitializeFormAction::class)->name('initialize.form'); Route::post('/initialize', InitializeAction::class)->name('initialize.store'); - Route::resource('member', MemberController::class)->except('show', 'destroy'); + Route::resource('member', MemberController::class)->except('show', 'destroy', 'edit', 'create'); Route::delete('/member/{member}', MemberDeleteAction::class); Route::get('/member/{member}', MemberShowAction::class)->name('member.show'); Route::resource('subscription', SubscriptionController::class); diff --git a/tests/EndToEnd/MemberIndexTest.php b/tests/EndToEnd/MemberIndexTest.php index a790c111..f1924651 100644 --- a/tests/EndToEnd/MemberIndexTest.php +++ b/tests/EndToEnd/MemberIndexTest.php @@ -36,9 +36,11 @@ class MemberIndexTest extends EndToEndTestCase ->assertInertiaCount('data.data', 1); } - public function testItGetsDefaultCountryFromDefaultModel(): void + public function testItGetsDefault(): void { - $this->callFilter('member.index', [])->assertInertiaPath('data.meta.default.country_id', Country::firstWhere('name', 'Deutschland')->id); + $this->callFilter('member.index', []) + ->assertInertiaPath('data.meta.default.country_id', Country::firstWhere('name', 'Deutschland')->id) + ->assertInertiaPath('data.meta.default.address', ''); } public function testItHandlesAddress(): void @@ -264,4 +266,24 @@ class MemberIndexTest extends EndToEndTestCase $this->callFilter('member.index', ['hasBirthday' => false, 'exclude' => [$member->id]]) ->assertInertiaCount('data.data', 0); } + + public function testItDisplaysActivityMeta(): void + { + $activity = Activity::factory()->inNami(5)->hasAttached(Subactivity::factory()->inNami(23)->name('Biber'))->name('€ Mitglied')->create(); + $subactivity = $activity->subactivities->first(); + + $this->callFilter('member.index', []) + ->assertInertiaPath("data.meta.formSubactivities.{$activity->id}.{$subactivity->id}", 'Biber') + ->assertInertiaPath("data.meta.formActivities.{$activity->id}", '€ Mitglied') + ->assertInertiaPath('data.meta.billKinds.0', ['id' => 'E-Mail', 'name' => 'E-Mail']); + } + + public function testItDoesntDisplayActivitiesAndSubactivitiesNotInNami(): void + { + Activity::factory()->hasAttached(Subactivity::factory()->name('Biber'))->name('€ Mitglied')->create(); + + $this->callFilter('member.index', []) + ->assertInertiaCount('data.meta.formCreateSubactivities', 0) + ->assertInertiaCount('data.meta.formCreateActivities', 0); + } } diff --git a/tests/Feature/Member/ShowTest.php b/tests/Feature/Member/ShowTest.php index 7be28c6d..4c0e431f 100644 --- a/tests/Feature/Member/ShowTest.php +++ b/tests/Feature/Member/ShowTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Member; +use App\Activity; use App\Country; use App\Course\Models\Course; use App\Course\Models\CourseMember; @@ -14,6 +15,7 @@ use App\Member\Membership; use App\Nationality; use App\Payment\Subscription; use App\Region; +use App\Subactivity; use Carbon\Carbon; use Generator; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -75,70 +77,58 @@ class ShowTest extends TestCase 'mitgliedsnr' => 998, 'lon' => 19.05, 'lat' => 14.053, + 'comment' => 'Lorem bla' ]); - $response = $this->get("/member/{$member->id}"); - - $this->assertInertiaHas([ - 'birthday_human' => '20.04.1991', - 'age' => 14, - 'group_name' => 'Stamm Beispiel', - 'full_address' => 'Itterstr 3, 42719 Solingen', - 'region' => ['name' => 'NRW'], - 'other_country' => 'other', - 'main_phone' => '+49 212 1266775', - 'mobile_phone' => '+49 212 1266776', - 'work_phone' => '+49 212 1266777', - 'children_phone' => '+49 212 1266778', - 'email' => 'a@b.de', - 'email_parents' => 'b@c.de', - 'fax' => '+49 212 1255674', - 'fullname' => 'Herr Max Muster', - 'efz_human' => '20.09.2022', - 'ps_at_human' => '20.04.2022', - 'more_ps_at_human' => '02.06.2022', - 'without_education_at_human' => '03.06.2022', - 'without_efz_at_human' => '04.06.2022', - 'recertified_at_human' => '13.06.2022', - 'has_vk' => true, - 'has_svk' => true, - 'multiply_pv' => true, - 'multiply_more_pv' => true, - 'has_nami' => true, - 'nami_id' => 123, - 'send_newspaper' => true, - 'joined_at_human' => '11.06.2022', - 'bill_kind_name' => 'Post', - 'mitgliedsnr' => 998, - 'lon' => 19.05, - 'lat' => 14.053, - 'subscription' => [ - 'name' => 'Sub', - ], - ], $response, 'data'); - $this->assertInertiaHas([ - 'activity_name' => '€ LeiterIn', - 'subactivity_name' => 'Jungpfadfinder', - 'id' => $member->memberships->first()->id, - 'human_date' => '19.11.2022', - 'promised_at' => now()->format('Y-m-d'), - ], $response, 'data.memberships.0'); - $this->assertInertiaHas([ - 'organizer' => 'DPSG', - 'event_name' => 'Wochenende', - 'completed_at_human' => '03.03.2022', - 'course' => [ - 'name' => ' Baustein 2e - Gewalt gegen Kinder und Jugendliche: Vertiefung, Prävention ', - 'short_name' => '2e', - ], - ], $response, 'data.courses.0'); - $this->assertInertiaHas([ - 'description' => 'uu', - 'price_human' => '10,50 €', - 'invoice' => [ - 'status' => 'Neu', - ] - ], $response, 'data.invoicePositions.0'); + $this->getJson(route('member.show', ['member' => $member])) + ->assertJsonPath('data.firstname', 'Max') + ->assertJsonPath('data.birthday_human', '20.04.1991') + ->assertJsonPath('data.age', 14) + ->assertJsonPath('data.group_name', 'Stamm Beispiel') + ->assertJsonPath('data.full_address', 'Itterstr 3, 42719 Solingen') + ->assertJsonPath('data.region.name', 'NRW') + ->assertJsonPath('data.other_country', 'other') + ->assertJsonPath('data.main_phone', '+49 212 1266775') + ->assertJsonPath('data.mobile_phone', '+49 212 1266776') + ->assertJsonPath('data.work_phone', '+49 212 1266777') + ->assertJsonPath('data.children_phone', '+49 212 1266778') + ->assertJsonPath('data.email', 'a@b.de') + ->assertJsonPath('data.email_parents', 'b@c.de') + ->assertJsonPath('data.fax', '+49 212 1255674') + ->assertJsonPath('data.fullname', 'Herr Max Muster') + ->assertJsonPath('data.efz_human', '20.09.2022') + ->assertJsonPath('data.ps_at_human', '20.04.2022') + ->assertJsonPath('data.more_ps_at_human', '02.06.2022') + ->assertJsonPath('data.without_education_at_human', '03.06.2022') + ->assertJsonPath('data.without_efz_at_human', '04.06.2022') + ->assertJsonPath('data.recertified_at_human', '13.06.2022') + ->assertJsonPath('data.has_vk', true) + ->assertJsonPath('data.has_svk', true) + ->assertJsonPath('data.multiply_pv', true) + ->assertJsonPath('data.multiply_more_pv', true) + ->assertJsonPath('data.has_nami', true) + ->assertJsonPath('data.nami_id', 123) + ->assertJsonPath('data.send_newspaper', true) + ->assertJsonPath('data.joined_at_human', '11.06.2022') + ->assertJsonPath('data.bill_kind_name', 'Post') + ->assertJsonPath('data.mitgliedsnr', 998) + ->assertJsonPath('data.lon', 19.05) + ->assertJsonPath('data.lat', 14.053) + ->assertJsonPath('data.subscription.name', 'Sub') + ->assertJsonPath('data.comment', 'Lorem bla') + ->assertJsonPath('data.memberships.0.activity_name', '€ LeiterIn') + ->assertJsonPath('data.memberships.0.subactivity_name', 'Jungpfadfinder') + ->assertJsonPath('data.memberships.0.id', $member->memberships->first()->id) + ->assertJsonPath('data.memberships.0.human_date', '19.11.2022') + ->assertJsonPath('data.memberships.0.promised_at', now()->format('Y-m-d')) + ->assertJsonPath('data.courses.0.organizer', 'DPSG') + ->assertJsonPath('data.courses.0.event_name', 'Wochenende') + ->assertJsonPath('data.courses.0.completed_at_human', '03.03.2022') + ->assertJsonPath('data.courses.0.course.name', ' Baustein 2e - Gewalt gegen Kinder und Jugendliche: Vertiefung, Prävention ') + ->assertJsonPath('data.courses.0.course.short_name', '2e') + ->assertJsonPath('data.invoicePositions.0.description', 'uu') + ->assertJsonPath('data.invoicePositions.0.price_human', '10,50 €') + ->assertJsonPath('data.invoicePositions.0.invoice.status', 'Neu'); } public function testItShowsMinimalSingleMember(): void @@ -150,24 +140,14 @@ class ShowTest extends TestCase ->for(Subscription::factory()->forFee()) ->create(['firstname' => 'Max', 'lastname' => 'Muster']); - $response = $this->get("/member/{$member->id}"); - - $this->assertInertiaHas([ - 'region' => ['name' => '-- kein --'], - 'fullname' => 'Max Muster', - 'nationality' => [ - 'name' => 'deutsch', - ], - 'efz_human' => null, - 'ps_at_human' => null, - 'more_ps_at_human' => null, - 'without_education_at_human' => null, - 'without_efz_at_human' => null, - 'has_vk' => false, - 'has_svk' => false, - 'multiply_pv' => false, - 'multiply_more_pv' => false, - ], $response, 'data'); + $this->get(route('member.show', ['member' => $member])) + ->assertJsonPath('data.has_vk', false) + ->assertJsonPath('data.has_svk', false) + ->assertJsonPath('data.multiply_pv', false) + ->assertJsonPath('data.multiply_more_pv', false) + ->assertJsonPath('data.nationality.name', 'deutsch') + ->assertJsonPath('data.region.name', '-- kein --') + ->assertJsonPath('data.fullname', 'Max Muster'); } public function membershipDataProvider(): Generator @@ -188,8 +168,21 @@ class ShowTest extends TestCase ->has(Membership::factory()->in('€ LeiterIn', 455, 'Pfadfinder', 15)->state(['from' => $from, 'to' => $to])) ->create(); - $response = $this->get("/member/{$member->id}"); + $this->get(route('member.show', ['member' => $member])) + ->assertJsonPath('data.memberships.0.is_active', $isActive); + } - $this->assertInertiaHas($isActive, $response, 'data.memberships.0.is_active'); + public function testItDisplaysMeta(): void + { + $this->withoutExceptionHandling(); + $this->login()->loginNami(); + $member = Member::factory()->defaults()->create(['salutation' => 'Doktor', 'firstname' => 'Max', 'comment' => 'Lorem bla']); + $activity = Activity::factory()->inNami(66)->hasAttached(Subactivity::factory()->inNami(56)->name('Biber'))->name('€ Mitglied')->create(); + $subactivity = $activity->subactivities->first(); + + $this->get(route('member.show', ['member' => $member])) + ->assertJsonPath("meta.formActivities.{$activity->id}", '€ Mitglied') + ->assertJsonPath("meta.formSubactivities.{$activity->id}.{$subactivity->id}", 'Biber') + ->assertJsonPath("meta.billKinds.0", ['id' => 'E-Mail', 'name' => 'E-Mail']); } }