Enforce task limits and update event form
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user