create(); $participant = User::factory()->create(); $dynamic = Dynamic::factory()->create(); $dynamic->participants()->attach($owner->id, ['role' => 'owner', 'display_name' => 'The Boss']); $dynamic->participants()->attach($participant->id, ['role' => 'participant']); $this->actingAs($owner); $response = $this->get(route('dynamics.users.show', [$dynamic->uuid, $participant->uuid])); $response->assertOk(); $response->assertInertia(fn ($page) => $page ->component('Dynamics/Participants/Show') ->has('dynamic') ->where('participant.id', $participant->id) ->where('participant.name', $participant->name) ->where('participant.display_name', null) ->where('participant.role', 'participant') ->has('mutations') ); }); test('non-participant cannot view participant detail page in dynamic', function () { $owner = User::factory()->create(); $participant = User::factory()->create(); $outsider = User::factory()->create(); $dynamic = Dynamic::factory()->create(); $dynamic->participants()->attach($owner->id, ['role' => 'owner']); $dynamic->participants()->attach($participant->id, ['role' => 'participant']); $this->actingAs($outsider); $response = $this->get(route('dynamics.users.show', [$dynamic->uuid, $participant->uuid])); $response->assertStatus(403); }); test('participant detail page displays their recent mutations in dynamic', function () { $owner = User::factory()->create(); $participant = User::factory()->create(); $dynamic = Dynamic::factory()->create(); $ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]); $dynamic->participants()->attach($owner->id, ['role' => 'owner']); $dynamic->participants()->attach($participant->id, ['role' => 'participant', 'display_name' => 'Bitch']); // Create mutations in this dynamic $mutation1 = Mutation::factory()->create([ 'ledger_id' => $ledger->id, 'user_id' => $participant->id, 'amount' => 10, 'description' => 'Chore 1', ]); $mutation2 = Mutation::factory()->create([ 'ledger_id' => $ledger->id, 'user_id' => $participant->id, 'amount' => -5, 'description' => 'Infraction 1', ]); // Create a mutation in another dynamic (should NOT be displayed) $otherDynamic = Dynamic::factory()->create(); $otherLedger = Ledger::factory()->create(['dynamic_id' => $otherDynamic->id]); $otherDynamic->participants()->attach($participant->id, ['role' => 'participant']); $mutation3 = Mutation::factory()->create([ 'ledger_id' => $otherLedger->id, 'user_id' => $participant->id, 'amount' => 100, 'description' => 'Other dynamic chore', ]); $this->actingAs($owner); $response = $this->get(route('dynamics.users.show', [$dynamic->uuid, $participant->uuid])); $response->assertOk(); $response->assertInertia(fn ($page) => $page ->component('Dynamics/Participants/Show') ->where('participant.display_name', 'Bitch') ->has('mutations', 2) ->where('mutations.0.description', 'Infraction 1') // Ordered latest first ->where('mutations.1.description', 'Chore 1') ); });