trypost/tests/Feature/Automation/Node/WebhookNodeTest.php
Paulo Castellano b23ab0166e feat(automations): implement automation features and UI enhancements
- Added new automation-related routes and controllers for managing automations.
- Introduced automation nodes in the UI with distinct styles and interactions.
- Updated sidebar to include navigation for automations.
- Enhanced post creation logic to support automation metadata.
- Refactored content type and platform enums into types for better type safety.
- Added localization for automation-related terms in English, Spanish, and Portuguese.
- Improved error handling in various components to accommodate new features.
2026-05-24 09:17:19 -03:00

55 lines
1.8 KiB
PHP

<?php
use App\Actions\Automation\Node\RunWebhookNode;
use App\Enums\Automation\NodeRun\Status;
use App\Models\AutomationRun;
use Illuminate\Support\Facades\Http;
it('posts interpolated payload to the configured url', function () {
Http::fake([
'hooks.example.com/*' => Http::response(['ok' => true], 200),
]);
$run = AutomationRun::factory()->create([
'context' => ['trigger' => ['title' => 'Hello'], 'generated' => ['post_url' => 'https://t.it/p/1']],
]);
$result = app(RunWebhookNode::class)($run, [
'url' => 'https://hooks.example.com/test',
'method' => 'POST',
'headers' => ['X-Source' => 'TryPost'],
'payload_template' => '{"title":"{{ trigger.title }}","post_url":"{{ generated.post_url }}"}',
]);
expect($result->status)->toBe(Status::Completed);
Http::assertSent(fn ($request) => $request['title'] === 'Hello' && $request['post_url'] === 'https://t.it/p/1');
});
it('fails on 5xx response', function () {
Http::fake(['hooks.example.com/*' => Http::response('err', 500)]);
$run = AutomationRun::factory()->create();
$result = app(RunWebhookNode::class)($run, [
'url' => 'https://hooks.example.com/test',
'method' => 'POST',
'payload_template' => '{}',
]);
expect($result->status)->toBe(Status::Failed);
});
it('treats 4xx responses as completed (only 5xx fails)', function () {
Http::fake(['hooks.example.com/*' => Http::response('not found', 404)]);
$run = AutomationRun::factory()->create();
$result = app(RunWebhookNode::class)($run, [
'url' => 'https://hooks.example.com/test',
'method' => 'POST',
'payload_template' => '{}',
]);
expect($result->status->value)->toBe('completed');
expect($result->output['webhook']['status'])->toBe(404);
});