From cbd6fe9b0f12fca33787faecf660a8541d66466e Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 18 Nov 2022 22:34:50 +0100 Subject: [PATCH] Mod member ShowTest --- app/Member/Actions/MemberShowAction.php | 2 +- app/Payment/PaymentResource.php | 3 +-- database/factories/Payment/PaymentFactory.php | 2 +- tests/Feature/Member/ShowTest.php | 11 +++++++++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/Member/Actions/MemberShowAction.php b/app/Member/Actions/MemberShowAction.php index 5cfa950f..8d0d32b0 100644 --- a/app/Member/Actions/MemberShowAction.php +++ b/app/Member/Actions/MemberShowAction.php @@ -18,7 +18,7 @@ class MemberShowAction public function handle(Member $member): array { return [ - 'data' => new MemberResource($member->load('memberships')), + 'data' => new MemberResource($member->load('memberships')->load('payments.subscription')), 'toolbar' => [['href' => route('member.index'), 'label' => 'Zurück', 'color' => 'primary', 'icon' => 'undo']], ]; } diff --git a/app/Payment/PaymentResource.php b/app/Payment/PaymentResource.php index 3cc05deb..120e90a4 100644 --- a/app/Payment/PaymentResource.php +++ b/app/Payment/PaymentResource.php @@ -19,8 +19,7 @@ class PaymentResource extends JsonResource public function toArray($request) { return [ - 'subscription_id' => $this->subscription_id, - 'subscription_name' => $this->subscription->name, + 'subscription' => new SubscriptionResource($this->whenLoaded('subscription')), 'status_name' => $this->status->name, 'status_id' => $this->status->id, 'nr' => $this->nr, diff --git a/database/factories/Payment/PaymentFactory.php b/database/factories/Payment/PaymentFactory.php index c930d114..8016ec72 100644 --- a/database/factories/Payment/PaymentFactory.php +++ b/database/factories/Payment/PaymentFactory.php @@ -40,7 +40,7 @@ class PaymentFactory extends Factory public function subscription(string $name, int $amount): self { return $this->for( - Subscription::factory()->state(['name' => $name, 'amount' => $amount])->for(Fee::first()), + Subscription::factory()->state(['name' => $name, 'amount' => $amount])->for(Fee::factory()) ); } } diff --git a/tests/Feature/Member/ShowTest.php b/tests/Feature/Member/ShowTest.php index cbe3bd07..c8c7d565 100644 --- a/tests/Feature/Member/ShowTest.php +++ b/tests/Feature/Member/ShowTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Member; use App\Member\Member; use App\Member\Membership; +use App\Payment\Payment; use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; @@ -16,6 +17,7 @@ class ShowTest extends TestCase $this->withoutExceptionHandling()->login()->loginNami(); $member = Member::factory() ->has(Membership::factory()->in('€ LeiterIn', 5, 'Jungpfadfinder', 88)->state(['created_at' => '2022-11-19 05:00:00'])) + ->has(Payment::factory()->notPaid()->nr('2019')->subscription('Free', 1050)) ->defaults()->create(['firstname' => 'Max']); $response = $this->get("/member/{$member->id}"); @@ -26,5 +28,14 @@ class ShowTest extends TestCase 'id' => $member->memberships->first()->id, 'human_date' => '19.11.2022', ], $response, 'data.memberships.0'); + $this->assertInertiaHas([ + 'subscription' => [ + 'name' => 'Free', + 'id' => $member->payments->first()->subscription->id, + 'amount' => 1050, + ], + 'status_name' => 'Nicht bezahlt', + 'nr' => '2019', + ], $response, 'data.payments.0'); } }