<?php

use App\Models\BulkOperationRun;
use App\Models\Tenant;
use App\Models\User;
use App\Services\BulkOperationService;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);
it('can abort a bulk operation run', function () {
    $tenant = Tenant::factory()->create();
    $user = User::factory()->create();

    $run = BulkOperationRun::factory()->create([
        'tenant_id' => $tenant->id,
        'user_id' => $user->id,
        'status' => 'running',
    ]);

    app(BulkOperationService::class)->abort($run, 'threshold exceeded');

    expect($run->refresh()->status)->toBe('aborted');
});
