trypost/tests/Feature/Automation/Node/ConditionNodeTest.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

86 lines
2.7 KiB
PHP

<?php
use App\Actions\Automation\Node\RunConditionNode;
use App\Models\AutomationRun;
it('routes to yes when contains matches', function () {
$run = AutomationRun::factory()->create([
'context' => ['trigger' => ['title' => 'Stripe Radar update']],
]);
$result = app(RunConditionNode::class)($run, [
'field' => '{{ trigger.title }}',
'operator' => 'contains',
'value' => 'Stripe',
]);
expect($result->nextHandle)->toBe('yes');
});
it('routes to no when contains does not match', function () {
$run = AutomationRun::factory()->create([
'context' => ['trigger' => ['title' => 'Facebook update']],
]);
$result = app(RunConditionNode::class)($run, [
'field' => '{{ trigger.title }}',
'operator' => 'contains',
'value' => 'Stripe',
]);
expect($result->nextHandle)->toBe('no');
});
it('supports equals and regex match operators', function () {
$run = AutomationRun::factory()->create([
'context' => ['trigger' => ['kind' => 'post']],
]);
expect(app(RunConditionNode::class)($run, [
'field' => '{{ trigger.kind }}', 'operator' => 'equals', 'value' => 'post',
])->nextHandle)->toBe('yes');
expect(app(RunConditionNode::class)($run, [
'field' => '{{ trigger.kind }}', 'operator' => 'matches', 'value' => '^p.*t$',
])->nextHandle)->toBe('yes');
});
it('supports greater_than for numerics', function () {
$run = AutomationRun::factory()->create([
'context' => ['trigger' => ['score' => 80]],
]);
expect(app(RunConditionNode::class)($run, [
'field' => '{{ trigger.score }}', 'operator' => 'greater_than', 'value' => '50',
])->nextHandle)->toBe('yes');
});
it('supports not_contains', function () {
$run = AutomationRun::factory()->create([
'context' => ['trigger' => ['title' => 'Facebook update']],
]);
expect(app(RunConditionNode::class)($run, [
'field' => '{{ trigger.title }}', 'operator' => 'not_contains', 'value' => 'Stripe',
])->nextHandle)->toBe('yes');
});
it('supports not_equals', function () {
$run = AutomationRun::factory()->create([
'context' => ['trigger' => ['kind' => 'post']],
]);
expect(app(RunConditionNode::class)($run, [
'field' => '{{ trigger.kind }}', 'operator' => 'not_equals', 'value' => 'media',
])->nextHandle)->toBe('yes');
});
it('supports less_than for numerics', function () {
$run = AutomationRun::factory()->create([
'context' => ['trigger' => ['score' => 20]],
]);
expect(app(RunConditionNode::class)($run, [
'field' => '{{ trigger.score }}', 'operator' => 'less_than', 'value' => '50',
])->nextHandle)->toBe('yes');
});