61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Filament\Pages\DriftLanding;
|
|
use App\Jobs\GenerateDriftFindingsJob;
|
|
use App\Models\InventorySyncRun;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Livewire\Livewire;
|
|
|
|
test('opening Drift dispatches generation when findings are missing', function () {
|
|
Queue::fake();
|
|
|
|
[$user, $tenant] = createUserWithTenant(role: 'manager');
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$scopeKey = hash('sha256', 'scope-dispatch');
|
|
|
|
$baseline = InventorySyncRun::factory()->for($tenant)->create([
|
|
'selection_hash' => $scopeKey,
|
|
'status' => InventorySyncRun::STATUS_SUCCESS,
|
|
'finished_at' => now()->subDays(2),
|
|
]);
|
|
|
|
$current = InventorySyncRun::factory()->for($tenant)->create([
|
|
'selection_hash' => $scopeKey,
|
|
'status' => InventorySyncRun::STATUS_SUCCESS,
|
|
'finished_at' => now()->subDay(),
|
|
]);
|
|
|
|
Livewire::test(DriftLanding::class);
|
|
|
|
Queue::assertPushed(GenerateDriftFindingsJob::class, function (GenerateDriftFindingsJob $job) use ($tenant, $user, $baseline, $current, $scopeKey): bool {
|
|
return $job->tenantId === (int) $tenant->getKey()
|
|
&& $job->userId === (int) $user->getKey()
|
|
&& $job->baselineRunId === (int) $baseline->getKey()
|
|
&& $job->currentRunId === (int) $current->getKey()
|
|
&& $job->scopeKey === $scopeKey;
|
|
});
|
|
});
|
|
|
|
test('opening Drift does not dispatch generation when fewer than two successful runs exist', function () {
|
|
Queue::fake();
|
|
|
|
[$user, $tenant] = createUserWithTenant(role: 'manager');
|
|
$this->actingAs($user);
|
|
Filament::setTenant($tenant, true);
|
|
|
|
$scopeKey = hash('sha256', 'scope-blocked');
|
|
|
|
InventorySyncRun::factory()->for($tenant)->create([
|
|
'selection_hash' => $scopeKey,
|
|
'status' => InventorySyncRun::STATUS_SUCCESS,
|
|
'finished_at' => now()->subDay(),
|
|
]);
|
|
|
|
Livewire::test(DriftLanding::class);
|
|
|
|
Queue::assertNothingPushed();
|
|
});
|