- Crowd Types + Persons CRUD (73 tests) - Festival Sections + Time Slots + Shifts CRUD met assign/claim flow (84 tests) - Invite Flow + Member Management met InvitationService (109 tests) - Schema v1.6 migraties volledig uitgevoerd - DevSeeder bijgewerkt met crowd types voor testorganisatie
157 lines
4.6 KiB
PHP
157 lines
4.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\TimeSlot;
|
|
|
|
use App\Models\Event;
|
|
use App\Models\Organisation;
|
|
use App\Models\TimeSlot;
|
|
use App\Models\User;
|
|
use Database\Seeders\RoleSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class TimeSlotTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private User $orgAdmin;
|
|
private User $outsider;
|
|
private Organisation $organisation;
|
|
private Organisation $otherOrganisation;
|
|
private Event $event;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->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();
|
|
}
|
|
}
|