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>
188 lines
5.7 KiB
PHP
188 lines
5.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Artist;
|
|
|
|
use App\Exceptions\Artist\VersionMismatchException;
|
|
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\Services\Artist\LaneCascadeService;
|
|
use Carbon\CarbonImmutable;
|
|
use Database\Seeders\RoleSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
final class LaneCascadeServiceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private LaneCascadeService $service;
|
|
|
|
private Organisation $org;
|
|
|
|
private Event $event;
|
|
|
|
private Stage $stage;
|
|
|
|
private ArtistEngagement $engagement;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->seed(RoleSeeder::class);
|
|
|
|
$this->service = $this->app->make(LaneCascadeService::class);
|
|
$this->org = Organisation::factory()->create();
|
|
$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]);
|
|
$this->engagement = ArtistEngagement::factory()->create([
|
|
'artist_id' => $artist->id,
|
|
'event_id' => $this->event->id,
|
|
]);
|
|
}
|
|
|
|
public function test_simple_move_no_overlap_succeeds(): void
|
|
{
|
|
$perf = Performance::factory()->create([
|
|
'engagement_id' => $this->engagement->id,
|
|
'event_id' => $this->event->id,
|
|
'stage_id' => $this->stage->id,
|
|
'lane' => 0,
|
|
'version' => 0,
|
|
]);
|
|
|
|
$start = CarbonImmutable::now()->addDays(2)->setTime(20, 0);
|
|
$result = $this->service->move(
|
|
performance: $perf,
|
|
targetStage: $this->stage,
|
|
start: $start,
|
|
end: $start->addHour(),
|
|
targetLane: 0,
|
|
clientVersion: 0,
|
|
);
|
|
|
|
$this->assertSame([], $result->cascaded);
|
|
$this->assertGreaterThan(0, $result->moved->version);
|
|
}
|
|
|
|
public function test_overlap_cascades_existing_to_higher_lane(): void
|
|
{
|
|
$start = CarbonImmutable::now()->addDays(3)->setTime(22, 0);
|
|
|
|
$existing = Performance::factory()->create([
|
|
'engagement_id' => $this->engagement->id,
|
|
'event_id' => $this->event->id,
|
|
'stage_id' => $this->stage->id,
|
|
'lane' => 0,
|
|
'start_at' => $start,
|
|
'end_at' => $start->addHour(),
|
|
'version' => 0,
|
|
]);
|
|
|
|
$other = Performance::factory()->create([
|
|
'engagement_id' => $this->engagement->id,
|
|
'event_id' => $this->event->id,
|
|
'stage_id' => null, // parked
|
|
'lane' => 0,
|
|
'start_at' => $start,
|
|
'end_at' => $start->addHour(),
|
|
'version' => 0,
|
|
]);
|
|
|
|
$result = $this->service->move(
|
|
performance: $other,
|
|
targetStage: $this->stage,
|
|
start: $start->addMinutes(15),
|
|
end: $start->addMinutes(75),
|
|
targetLane: 0,
|
|
clientVersion: 0,
|
|
);
|
|
|
|
$this->assertCount(1, $result->cascaded);
|
|
$this->assertSame((string) $existing->id, (string) $result->cascaded[0]->id);
|
|
$this->assertSame(1, (int) $result->cascaded[0]->lane);
|
|
}
|
|
|
|
public function test_version_mismatch_throws(): void
|
|
{
|
|
$perf = Performance::factory()->create([
|
|
'engagement_id' => $this->engagement->id,
|
|
'event_id' => $this->event->id,
|
|
'stage_id' => $this->stage->id,
|
|
'lane' => 0,
|
|
'version' => 5,
|
|
]);
|
|
|
|
$this->expectException(VersionMismatchException::class);
|
|
|
|
$this->service->move(
|
|
performance: $perf,
|
|
targetStage: $this->stage,
|
|
start: CarbonImmutable::parse((string) $perf->start_at),
|
|
end: CarbonImmutable::parse((string) $perf->end_at),
|
|
targetLane: 0,
|
|
clientVersion: 4,
|
|
);
|
|
}
|
|
|
|
public function test_park_clears_stage_id(): void
|
|
{
|
|
$perf = Performance::factory()->create([
|
|
'engagement_id' => $this->engagement->id,
|
|
'event_id' => $this->event->id,
|
|
'stage_id' => $this->stage->id,
|
|
'lane' => 2,
|
|
'version' => 0,
|
|
]);
|
|
|
|
$result = $this->service->move(
|
|
performance: $perf,
|
|
targetStage: null,
|
|
start: null,
|
|
end: null,
|
|
targetLane: null,
|
|
clientVersion: 0,
|
|
);
|
|
|
|
$this->assertNull($result->moved->stage_id);
|
|
$this->assertSame([], $result->cascaded);
|
|
$this->assertSame(2, (int) $result->moved->lane);
|
|
}
|
|
|
|
public function test_unpark_to_stage_succeeds(): void
|
|
{
|
|
$perf = Performance::factory()->create([
|
|
'engagement_id' => $this->engagement->id,
|
|
'event_id' => $this->event->id,
|
|
'stage_id' => null,
|
|
'lane' => 0,
|
|
'version' => 0,
|
|
]);
|
|
|
|
$start = CarbonImmutable::now()->addDays(4)->setTime(21, 0);
|
|
$result = $this->service->move(
|
|
performance: $perf,
|
|
targetStage: $this->stage,
|
|
start: $start,
|
|
end: $start->addHour(),
|
|
targetLane: 0,
|
|
clientVersion: 0,
|
|
);
|
|
|
|
$this->assertSame((string) $this->stage->id, (string) $result->moved->stage_id);
|
|
}
|
|
}
|