trypost/tests/Feature/Automation/Node/DelayNodeTest.php
Paulo Castellano 31b6544c57 Cover node-run error paths and align webhook failure handling
Wrap the webhook HTTP send in a try/catch so a connection error returns
a clean failed result (reason: request_failed) instead of bubbling up as
a job failure — matching the HTTP request node.

Add tests for the gaps in node-run coverage:
- HTTP request: basic auth, PUT/PATCH/DELETE, non-2xx responses,
  connection exceptions, and an items_path that doesn't resolve to a list.
- Webhook: every HTTP method, header expression resolution, and the new
  connection-failure path.
- Fetch RSS: non-2xx feed responses, malformed XML, items without a
  publish date (skipped), and the link fallback when an item has no guid.
- Delay: unknown unit throws.
- Publish: dry runs don't publish or queue.
2026-06-13 09:56:18 -03:00

35 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
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);
});
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);
});