HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/ai.naniguide.com/tests/Feature/AdAutomationRuleFeatureTest.php
<?php

use App\Model\AdAutomationRule;

test('ad automation triggers are valid', function () {
    expect(AdAutomationRule::TRIGGERS)->toBe(['email_open', 'email_click', 'email_unsubscribe', 'purchase']);
});

test('ad automation actions are valid', function () {
    expect(AdAutomationRule::ACTIONS)->toBe(['add_to_audience', 'remove_from_audience', 'start_campaign', 'pause_campaign']);
});

test('ad automation fillable fields are correct', function () {
    $rule = new AdAutomationRule();
    expect($rule->getFillable())->toContain('name', 'trigger_event', 'action_type', 'customer_id', 'status', 'conditions');
});

test('ad automation casts are correct', function () {
    $rule = new AdAutomationRule();
    $casts = $rule->getCasts();
    expect($casts['conditions'])->toBe('json');
    expect($casts)->toHaveKey('last_triggered_at');
});

test('ad automation status badge accessor works', function () {
    $rule = new AdAutomationRule();
    $rule->status = 'active';
    expect($rule->status_badge)->toBe('green');
    $rule->status = 'paused';
    expect($rule->status_badge)->toBe('orange');
    $rule->status = 'disabled';
    expect($rule->status_badge)->toBe('red');
});

test('ad automation trigger label accessor works', function () {
    $rule = new AdAutomationRule();
    $rule->trigger_event = 'email_open';
    expect($rule->trigger_label)->toBe('Email Open');
    $rule->trigger_event = 'email_click';
    expect($rule->trigger_label)->toBe('Email Click');
});

test('ad automation action label accessor works', function () {
    $rule = new AdAutomationRule();
    $rule->action_type = 'add_to_audience';
    expect($rule->action_label)->toBe('Add To Audience');
});

test('ad automation can be created via factory', function () {
    $rule = AdAutomationRule::factory()->make(['customer_id' => 1]);
    expect($rule->name)->not->toBeEmpty();
    expect($rule->trigger_event)->toBeIn(AdAutomationRule::TRIGGERS);
    expect($rule->action_type)->toBeIn(AdAutomationRule::ACTIONS);
});