2026-05-24 12:17:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
2026-06-10 20:26:50 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-05-24 12:17:19 +00:00
|
|
|
use App\Actions\Automation\Node\RunDelayNode;
|
|
|
|
|
use App\Enums\Automation\NodeRun\Status;
|
|
|
|
|
use App\Models\AutomationRun;
|
|
|
|
|
|
|
|
|
|
it('returns sleep_until with duration in hours', function () {
|
|
|
|
|
$run = AutomationRun::factory()->create();
|
|
|
|
|
$handler = app(RunDelayNode::class);
|
|
|
|
|
|
|
|
|
|
$result = $handler($run, ['duration' => 2, 'unit' => 'hours']);
|
|
|
|
|
|
|
|
|
|
expect($result->status)->toBe(Status::Completed);
|
|
|
|
|
expect($result->sleepUntil)->not->toBeNull();
|
|
|
|
|
expect(now()->diffInMinutes($result->sleepUntil))->toBeGreaterThanOrEqual(119);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('supports minutes and days units', function () {
|
|
|
|
|
$run = AutomationRun::factory()->create();
|
|
|
|
|
$handler = app(RunDelayNode::class);
|
|
|
|
|
|
|
|
|
|
expect($handler($run, ['duration' => 30, 'unit' => 'minutes'])->sleepUntil)
|
|
|
|
|
->not->toBeNull();
|
|
|
|
|
expect(now()->diffInHours($handler($run, ['duration' => 1, 'unit' => 'days'])->sleepUntil))
|
|
|
|
|
->toBeGreaterThanOrEqual(23);
|
|
|
|
|
});
|
2026-06-13 12:56:18 +00:00
|
|
|
|
|
|
|
|
it('throws on an unknown delay unit', function () {
|
|
|
|
|
$run = AutomationRun::factory()->create();
|
|
|
|
|
|
|
|
|
|
expect(fn () => app(RunDelayNode::class)($run, ['duration' => 5, 'unit' => 'weeks']))
|
|
|
|
|
->toThrow(InvalidArgumentException::class);
|
|
|
|
|
});
|