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/be.naniguide.com/tests/Feature/AdPixelFeatureTest.php
<?php

use App\Model\AdPixel;
use App\Model\AdConversion;

test('ad pixel statuses are valid constants', function () {
    expect(AdPixel::STATUS_ACTIVE)->toBe('active');
    expect(AdPixel::STATUS_INACTIVE)->toBe('inactive');
    expect(AdPixel::STATUS_ERROR)->toBe('error');
});

test('ad pixel fillable fields are correct', function () {
    $pixel = new AdPixel();
    expect($pixel->getFillable())->toContain('platform', 'pixel_id', 'access_token', 'customer_id', 'status', 'settings');
});

test('ad pixel casts include encrypted access token', function () {
    $pixel = new AdPixel();
    $casts = $pixel->getCasts();
    expect($casts['access_token'])->toBe('encrypted');
    expect($casts['settings'])->toBe('json');
    expect($casts)->toHaveKey('last_verified_at');
});

test('ad pixel status badge accessor works', function () {
    $pixel = new AdPixel();
    $pixel->status = 'active';
    expect($pixel->status_badge)->toBe('green');
    $pixel->status = 'inactive';
    expect($pixel->status_badge)->toBe('orange');
    $pixel->status = 'error';
    expect($pixel->status_badge)->toBe('red');
});

test('ad pixel platform label accessor works', function () {
    $pixel = new AdPixel();
    $pixel->platform = 'meta';
    expect($pixel->platform_label)->toBe('Meta (Facebook/Instagram)');
});

test('ad pixel can be created via factory', function () {
    $pixel = AdPixel::factory()->make(['customer_id' => 1]);
    expect($pixel->pixel_id)->not->toBeEmpty();
    expect($pixel->status)->toBe(AdPixel::STATUS_ACTIVE);
});

test('ad conversion fillable fields are correct', function () {
    $conversion = new AdConversion();
    expect($conversion->getFillable())->toContain('ad_pixel_id', 'event_name', 'value', 'currency', 'attribution');
});

test('ad conversion casts attribution as json', function () {
    $conversion = new AdConversion();
    $casts = $conversion->getCasts();
    expect($casts['attribution'])->toBe('json');
    expect($casts['value'])->toBe('decimal:2');
});