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

37 lines
1.5 KiB
PHP

<?php
use App\Enums\Automation\Status;
use App\Models\Automation;
use App\Models\AutomationNodeRun;
use App\Models\AutomationRun;
use App\Models\AutomationTriggerItem;
use Illuminate\Database\UniqueConstraintViolationException;
it('persists automation with json columns and enum cast', function () {
$automation = Automation::factory()->withScheduleTrigger()->create();
expect($automation->status)->toBe(Status::Draft);
expect($automation->nodes)->toBeArray();
expect($automation->nodes[0]['type'])->toBe('trigger');
});
it('relates trigger items, runs and node runs', function () {
$automation = Automation::factory()->create();
$item = AutomationTriggerItem::factory()->for($automation)->create();
$run = AutomationRun::factory()->for($automation)->create(['trigger_item_id' => $item->id]);
$nodeRun = AutomationNodeRun::factory()->for($run, 'run')->create();
expect($automation->triggerItems)->toHaveCount(1);
expect($automation->runs)->toHaveCount(1);
expect($run->triggerItem->id)->toBe($item->id);
expect($run->nodeRuns)->toHaveCount(1);
expect($nodeRun->run->id)->toBe($run->id);
});
it('enforces unique item_key per automation', function () {
$automation = Automation::factory()->create();
AutomationTriggerItem::factory()->for($automation)->create(['item_key' => 'abc']);
expect(fn () => AutomationTriggerItem::factory()->for($automation)->create(['item_key' => 'abc']))
->toThrow(UniqueConstraintViolationException::class);
});