Nine test files under tests/Feature/Artist/ exercising:
ArtistEngagementStateMachineTest 8 tests — terminal blocks, conditional
gates (Option/Contracted), full happy
path, cancel cascade
LaneCascadeServiceTest 5 tests — simple move, cascade-bump,
version mismatch, park, unpark
BumaVatCalculationTest 6 tests — D26 formula coverage:
Organisation/BookingAgency/NotApplicable,
VAT off, breakdown sum, zero fee
DemoteExpiredOptionsTest 4 tests — expired demote, future
untouched, non-Option untouched, run
twice → single option_expired entry
IdempotencyKey60sRedisTest 4 tests — missing header 400, first
cache, replay header, failed not cached
ArtistControllerTest 8 tests — index/create/destroy + cross-
tenant + duplicate detection + restore
StageControllerTest 7 tests — create + uniqueness, destroy
cascade-park, reorder permutation,
replaceDays orphan 409 + force_orphan
ArtistEngagementControllerTest 5 tests — index/create/update/destroy +
422 on invalid status transition
TimetableMoveControllerTest 3 tests — happy path with idempotency
header, missing header → 400, version
mismatch → 409
ArtistPolicyTest 6 tests — role checks, cross-tenant
denial, super_admin bypass, D27 active-
engagement gate
ActivityLogShapeTest 4 tests — performance.moved cascade
props, status_changed vs cancelled,
stage.day_added subject + props,
stage.reordered on Event subject
Bug fixes surfaced by Phase C:
Schema reality: events table uses `start_date`/`end_date` (date), not
`start_at`/`end_at`. Updated WithinEventBounds rule and the two stage_day
resolvers (LaneCascadeService + MoveTimetablePerformanceRequest) to
query the actual columns. ArtistResource.engagements_summary upcoming
filter likewise.
performances table has no organisation_id column (FK-chain via
engagement_id). Removed the org-id filter from the Rule::exists in
MoveTimetablePerformanceRequest; cross-tenant is caught by the policy
in TimetableMoveController.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
132 lines
4.1 KiB
PHP
132 lines
4.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Artist;
|
|
|
|
use App\Models\Artist;
|
|
use App\Models\ArtistEngagement;
|
|
use App\Models\Event;
|
|
use App\Models\Organisation;
|
|
use App\Models\Performance;
|
|
use App\Models\Stage;
|
|
use App\Models\StageDay;
|
|
use App\Models\User;
|
|
use Carbon\CarbonImmutable;
|
|
use Database\Seeders\RoleSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
final class TimetableMoveControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private Organisation $org;
|
|
|
|
private User $orgAdmin;
|
|
|
|
private Event $event;
|
|
|
|
private Stage $stage;
|
|
|
|
private Performance $perf;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->seed(RoleSeeder::class);
|
|
|
|
$this->org = Organisation::factory()->create();
|
|
$this->orgAdmin = User::factory()->create();
|
|
$this->org->users()->attach($this->orgAdmin, ['role' => 'org_admin']);
|
|
$this->event = Event::factory()->create([
|
|
'organisation_id' => $this->org->id,
|
|
'start_date' => CarbonImmutable::now()->subDay(),
|
|
'end_date' => CarbonImmutable::now()->addDays(30),
|
|
]);
|
|
$this->stage = Stage::factory()->create(['event_id' => $this->event->id]);
|
|
StageDay::query()->create(['stage_id' => $this->stage->id, 'event_id' => $this->event->id]);
|
|
|
|
$artist = Artist::factory()->create(['organisation_id' => $this->org->id]);
|
|
$eng = ArtistEngagement::factory()->create([
|
|
'artist_id' => $artist->id,
|
|
'event_id' => $this->event->id,
|
|
]);
|
|
$start = CarbonImmutable::now()->addDays(2)->setTime(20, 0);
|
|
$this->perf = Performance::factory()->create([
|
|
'engagement_id' => $eng->id,
|
|
'event_id' => $this->event->id,
|
|
'stage_id' => $this->stage->id,
|
|
'lane' => 0,
|
|
'start_at' => $start,
|
|
'end_at' => $start->addHour(),
|
|
'version' => 0,
|
|
]);
|
|
}
|
|
|
|
private function url(): string
|
|
{
|
|
return "/api/v1/organisations/{$this->org->id}/events/{$this->event->id}/timetable/move";
|
|
}
|
|
|
|
public function test_move_succeeds_with_idempotency_key(): void
|
|
{
|
|
Sanctum::actingAs($this->orgAdmin);
|
|
|
|
$newStart = CarbonImmutable::parse((string) $this->perf->start_at)->addHour();
|
|
$response = $this->postJson(
|
|
$this->url(),
|
|
[
|
|
'performance_id' => $this->perf->id,
|
|
'target_stage_id' => $this->stage->id,
|
|
'target_start_at' => $newStart->format('Y-m-d H:i:s'),
|
|
'target_end_at' => $newStart->addHour()->format('Y-m-d H:i:s'),
|
|
'target_lane' => 0,
|
|
'version' => 0,
|
|
],
|
|
['Idempotency-Key' => 'test-1'],
|
|
);
|
|
|
|
$response->assertOk();
|
|
}
|
|
|
|
public function test_move_without_idempotency_key_returns_400(): void
|
|
{
|
|
Sanctum::actingAs($this->orgAdmin);
|
|
|
|
$response = $this->postJson($this->url(), [
|
|
'performance_id' => $this->perf->id,
|
|
'target_stage_id' => $this->stage->id,
|
|
'target_start_at' => '2026-07-10 22:00:00',
|
|
'target_end_at' => '2026-07-10 23:00:00',
|
|
'target_lane' => 0,
|
|
'version' => 0,
|
|
]);
|
|
|
|
$response->assertStatus(400);
|
|
}
|
|
|
|
public function test_version_mismatch_returns_409(): void
|
|
{
|
|
Sanctum::actingAs($this->orgAdmin);
|
|
|
|
$newStart = CarbonImmutable::parse((string) $this->perf->start_at)->addHour();
|
|
$response = $this->postJson(
|
|
$this->url(),
|
|
[
|
|
'performance_id' => $this->perf->id,
|
|
'target_stage_id' => $this->stage->id,
|
|
'target_start_at' => $newStart->format('Y-m-d H:i:s'),
|
|
'target_end_at' => $newStart->addHour()->format('Y-m-d H:i:s'),
|
|
'target_lane' => 0,
|
|
'version' => 99,
|
|
],
|
|
['Idempotency-Key' => 'test-2'],
|
|
);
|
|
|
|
$response->assertStatus(409);
|
|
$this->assertSame('version_mismatch', $response->json('errors.conflict'));
|
|
}
|
|
}
|