seed(RoleSeeder::class); $this->organisation = Organisation::factory()->create(); $this->volunteerCrowdType = CrowdType::factory()->systemType('VOLUNTEER')->create([ 'organisation_id' => $this->organisation->id, ]); $this->event = Event::factory()->create([ 'organisation_id' => $this->organisation->id, 'status' => 'published', ]); } public function test_auth_me_includes_portal_events(): void { $user = User::factory()->create(); Person::factory()->approved()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->volunteerCrowdType->id, 'user_id' => $user->id, 'email' => $user->email, ]); Sanctum::actingAs($user); $response = $this->getJson('/api/v1/auth/me'); $response->assertOk(); $response->assertJsonCount(1, 'data.portal_events'); $response->assertJsonPath('data.portal_events.0.event_id', $this->event->id); $response->assertJsonPath('data.portal_events.0.event_name', $this->event->name); $response->assertJsonPath('data.portal_events.0.event_slug', $this->event->slug); $response->assertJsonPath('data.portal_events.0.organisation_name', $this->organisation->name); $response->assertJsonPath('data.portal_events.0.person_status', 'approved'); } public function test_portal_events_contains_correct_event_dates(): void { $user = User::factory()->create(); Person::factory()->approved()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->volunteerCrowdType->id, 'user_id' => $user->id, 'email' => $user->email, ]); Sanctum::actingAs($user); $response = $this->getJson('/api/v1/auth/me'); $response->assertOk(); $response->assertJsonPath('data.portal_events.0.start_date', $this->event->start_date->toDateString()); $response->assertJsonPath('data.portal_events.0.end_date', $this->event->end_date->toDateString()); } public function test_portal_events_only_includes_own_events(): void { $user = User::factory()->create(); $otherUser = User::factory()->create(); Person::factory()->approved()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->volunteerCrowdType->id, 'user_id' => $user->id, 'email' => $user->email, ]); // Other user's person record — should not appear Person::factory()->approved()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->volunteerCrowdType->id, 'user_id' => $otherUser->id, 'email' => $otherUser->email, ]); Sanctum::actingAs($user); $response = $this->getJson('/api/v1/auth/me'); $response->assertOk(); $response->assertJsonCount(1, 'data.portal_events'); $response->assertJsonPath('data.portal_events.0.person_status', 'approved'); } public function test_portal_events_empty_when_no_persons(): void { $user = User::factory()->create(); Sanctum::actingAs($user); $response = $this->getJson('/api/v1/auth/me'); $response->assertOk(); $response->assertJsonCount(0, 'data.portal_events'); } public function test_portal_events_includes_multiple_events(): void { $user = User::factory()->create(); $secondEvent = Event::factory()->create([ 'organisation_id' => $this->organisation->id, 'status' => 'published', ]); Person::factory()->approved()->create([ 'event_id' => $this->event->id, 'crowd_type_id' => $this->volunteerCrowdType->id, 'user_id' => $user->id, 'email' => $user->email, ]); Person::factory()->create([ 'event_id' => $secondEvent->id, 'crowd_type_id' => $this->volunteerCrowdType->id, 'user_id' => $user->id, 'email' => $user->email, 'status' => 'pending', ]); Sanctum::actingAs($user); $response = $this->getJson('/api/v1/auth/me'); $response->assertOk(); $response->assertJsonCount(2, 'data.portal_events'); } public function test_unauthenticated_returns_401(): void { $response = $this->getJson('/api/v1/auth/me'); $response->assertStatus(401); } }