trypost/tests/Unit/Automation/ExpressionResolverTest.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

50 lines
1.6 KiB
PHP

<?php
use App\Services\Automation\ExpressionResolver;
beforeEach(function () {
$this->resolver = new ExpressionResolver;
});
it('substitutes trigger and generated variables', function () {
$template = 'Title: {{ trigger.title }} | Post: {{ generated.post_url }}';
$context = [
'trigger' => ['title' => 'Hello World'],
'generated' => ['post_url' => 'https://example.com/p/1'],
];
expect($this->resolver->resolve($template, $context))
->toBe('Title: Hello World | Post: https://example.com/p/1');
});
it('supports nested paths', function () {
$template = 'Author: {{ trigger.author.name }}';
$context = ['trigger' => ['author' => ['name' => 'Paulo']]];
expect($this->resolver->resolve($template, $context))->toBe('Author: Paulo');
});
it('returns empty string for missing variables', function () {
$template = 'Missing: {{ trigger.missing }}';
expect($this->resolver->resolve($template, []))->toBe('Missing: ');
});
it('supports now and today helpers', function () {
$now = $this->resolver->resolve('{{ now }}', []);
$today = $this->resolver->resolve('{{ today }}', []);
expect($now)->toMatch('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/');
expect($today)->toMatch('/^\d{4}-\d{2}-\d{2}$/');
});
it('handles non-string values by casting', function () {
$template = 'Count: {{ trigger.count }}';
$context = ['trigger' => ['count' => 42]];
expect($this->resolver->resolve($template, $context))->toBe('Count: 42');
});
it('passes through templates with no variables', function () {
expect($this->resolver->resolve('plain text', []))->toBe('plain text');
});