TenantAtlas/tests/Unit/CircuitBreakerTest.php
Ahmed Darrazi de199ef476 fix(tests): remove per-file TestCase uses
Pest v4 discovery fails when unit tests re-bind the test case with uses(TestCase::class). Remove per-file bindings and keep RefreshDatabase where needed. Also update RunBackupScheduleJobTest to pass BulkOperationService when calling handle() manually.
2026-01-08 01:38:54 +01:00

46 lines
1.5 KiB
PHP

<?php
use App\Jobs\BulkPolicyDeleteJob;
use App\Jobs\BulkPolicyExportJob;
use App\Models\Tenant;
use App\Models\User;
use App\Services\BulkOperationService;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
test('bulk delete aborts when more than half of items fail', function () {
$tenant = Tenant::factory()->create();
$user = User::factory()->create();
$service = app(BulkOperationService::class);
$run = $service->createRun($tenant, $user, 'policy', 'delete', [100001, 100002, 100003, 100004, 100005, 100006, 100007, 100008, 100009, 100010], 10);
(new BulkPolicyDeleteJob($run->id))->handle($service);
$run->refresh();
expect($run->status)->toBe('aborted')
->and($run->failed)->toBe(6)
->and($run->processed_items)->toBe(6);
});
test('bulk export aborts when more than half of items fail', function () {
$tenant = Tenant::factory()->create();
$user = User::factory()->create();
$service = app(BulkOperationService::class);
$run = $service->createRun($tenant, $user, 'policy', 'export', [200001, 200002, 200003, 200004, 200005, 200006, 200007, 200008, 200009, 200010], 10);
(new BulkPolicyExportJob($run->id, 'Circuit Breaker Backup'))->handle($service);
$run->refresh();
expect($run->status)->toBe('aborted')
->and($run->failed)->toBe(6)
->and($run->processed_items)->toBe(6);
$this->assertDatabaseHas('backup_sets', [
'tenant_id' => $tenant->id,
'name' => 'Circuit Breaker Backup',
'status' => 'failed',
]);
});