Enforce task limits and update event form
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-21 09:49:30 +01:00
parent 0b1430e64d
commit 1c5412e82c
15 changed files with 491 additions and 52 deletions

View File

@@ -3,6 +3,8 @@
namespace Tests\Feature\Tenant;
use App\Models\Event;
use App\Models\EventPackage;
use App\Models\Package;
use App\Models\Task;
use App\Models\TaskCollection;
use App\Models\Tenant;
@@ -232,6 +234,76 @@ class TaskApiTest extends TenantTestCase
$this->assertEquals(3, $event->tasks()->count());
}
#[Test]
public function task_assignment_respects_package_task_limit()
{
$package = Package::factory()->endcustomer()->create([
'max_tasks' => 1,
]);
$event = Event::factory()->create([
'tenant_id' => $this->tenant->id,
]);
EventPackage::create([
'event_id' => $event->id,
'package_id' => $package->id,
'purchased_price' => $package->price,
'purchased_at' => now(),
]);
$existingTask = Task::factory()->create([
'tenant_id' => $this->tenant->id,
'priority' => 'medium',
]);
$event->tasks()->attach($existingTask->id);
$nextTask = Task::factory()->create([
'tenant_id' => $this->tenant->id,
'priority' => 'medium',
]);
$response = $this->withHeaders(['Authorization' => 'Bearer '.$this->token])
->postJson("/api/v1/tenant/tasks/{$nextTask->id}/assign-event/{$event->id}");
$response->assertStatus(402)
->assertJsonPath('error.code', 'task_limit_exceeded');
}
#[Test]
public function task_collection_import_skips_tasks_over_limit()
{
$package = Package::factory()->endcustomer()->create([
'max_tasks' => 2,
]);
$event = Event::factory()->create([
'tenant_id' => $this->tenant->id,
]);
EventPackage::create([
'event_id' => $event->id,
'package_id' => $package->id,
'purchased_price' => $package->price,
'purchased_at' => now(),
]);
$collection = TaskCollection::factory()->create([
'tenant_id' => null,
'event_type_id' => $event->event_type_id,
]);
$tasks = Task::factory(4)->create([
'tenant_id' => null,
'event_type_id' => $event->event_type_id,
]);
$collection->tasks()->attach($tasks->pluck('id')->all());
$response = $this->withHeaders(['Authorization' => 'Bearer '.$this->token])
->postJson("/api/v1/tenant/task-collections/{$collection->id}/activate", [
'event_slug' => $event->slug,
]);
$response->assertStatus(200);
$this->assertSame(2, $event->tasks()->count());
}
#[Test]
public function can_get_tasks_for_specific_event()
{