seed(RoleSeeder::class); $this->organisation = Organisation::factory()->create(); $this->otherOrganisation = Organisation::factory()->create(); $this->orgAdmin = User::factory()->create(); $this->organisation->users()->attach($this->orgAdmin, ['role' => 'org_admin']); $this->outsider = User::factory()->create(); $this->otherOrganisation->users()->attach($this->outsider, ['role' => 'org_admin']); $this->event = Event::factory()->create(['organisation_id' => $this->organisation->id]); } public function test_index_returns_time_slots(): void { TimeSlot::factory()->count(3)->create(['event_id' => $this->event->id]); Sanctum::actingAs($this->orgAdmin); $response = $this->getJson("/api/v1/events/{$this->event->id}/time-slots"); $response->assertOk(); $this->assertCount(3, $response->json('data')); } public function test_store_creates_time_slot(): void { Sanctum::actingAs($this->orgAdmin); $response = $this->postJson("/api/v1/events/{$this->event->id}/time-slots", [ 'name' => 'Vrijdag Avond', 'person_type' => 'VOLUNTEER', 'date' => '2026-07-10', 'start_time' => '18:00', 'end_time' => '02:00', 'duration_hours' => 8, ]); $response->assertCreated() ->assertJson(['data' => [ 'name' => 'Vrijdag Avond', 'person_type' => 'VOLUNTEER', ]]); $this->assertDatabaseHas('time_slots', [ 'event_id' => $this->event->id, 'name' => 'Vrijdag Avond', ]); } public function test_store_invalid_person_type_returns_422(): void { Sanctum::actingAs($this->orgAdmin); $response = $this->postJson("/api/v1/events/{$this->event->id}/time-slots", [ 'name' => 'Test', 'person_type' => 'INVALID', 'date' => '2026-07-10', 'start_time' => '18:00', 'end_time' => '02:00', ]); $response->assertUnprocessable() ->assertJsonValidationErrors('person_type'); } public function test_store_invalid_date_format_returns_422(): void { Sanctum::actingAs($this->orgAdmin); $response = $this->postJson("/api/v1/events/{$this->event->id}/time-slots", [ 'name' => 'Test', 'person_type' => 'VOLUNTEER', 'date' => 'not-a-date', 'start_time' => '18:00', 'end_time' => '02:00', ]); $response->assertUnprocessable() ->assertJsonValidationErrors('date'); } public function test_update_time_slot(): void { $timeSlot = TimeSlot::factory()->create([ 'event_id' => $this->event->id, 'name' => 'Vrijdag Avond', ]); Sanctum::actingAs($this->orgAdmin); $response = $this->putJson("/api/v1/events/{$this->event->id}/time-slots/{$timeSlot->id}", [ 'name' => 'Vrijdag Avond Updated', ]); $response->assertOk() ->assertJson(['data' => ['name' => 'Vrijdag Avond Updated']]); } public function test_destroy_deletes_time_slot(): void { $timeSlot = TimeSlot::factory()->create(['event_id' => $this->event->id]); Sanctum::actingAs($this->orgAdmin); $response = $this->deleteJson("/api/v1/events/{$this->event->id}/time-slots/{$timeSlot->id}"); $response->assertNoContent(); $this->assertDatabaseMissing('time_slots', ['id' => $timeSlot->id]); } public function test_unauthenticated_returns_401(): void { $response = $this->getJson("/api/v1/events/{$this->event->id}/time-slots"); $response->assertUnauthorized(); } public function test_cross_org_returns_403(): void { Sanctum::actingAs($this->outsider); $response = $this->getJson("/api/v1/events/{$this->event->id}/time-slots"); $response->assertForbidden(); } }