Files
portal-api/tests/Feature/Api/Admin/EmailHealthTest.php

43 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Api\Admin;
use App\Models\Setting;
use App\Models\User;
use App\Support\EmailHealth;
use Database\Seeders\TemplateSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Spatie\Permission\Models\Role;
use Tests\TestCase;
class EmailHealthTest extends TestCase
{
use RefreshDatabase;
public function test_health_flags_disabled_lifecycle_scenarios_and_clears_when_enabled(): void
{
$this->seed(TemplateSeeder::class);
Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']);
$admin = User::factory()->create();
$admin->assignRole('Full Administrator');
Setting::updateOrCreate(['key' => 'email_settings'], ['value' => json_encode(['auto_disabled' => ['service_expiry', 'auto_renew_failed']])]);
$rows = collect($this->actingAs($admin, 'admin')->getJson('/api/v1/administrator/email-templates/health')
->assertOk()
->json('data.scenarios'))->keyBy('key');
$this->assertFalse($rows['service_expiry']['auto_enabled']);
$this->assertFalse($rows['service_expiry']['ready']);
$this->assertTrue($rows['invoice_notification']['has_template']);
$this->assertSame(EmailHealth::LIFECYCLE_SCENARIOS, $rows->keys()->all());
Setting::updateOrCreate(['key' => 'email_settings'], ['value' => json_encode(['auto_disabled' => []])]);
$rows = collect(EmailHealth::report()['scenarios'])->keyBy('key');
$this->assertTrue($rows['service_expiry']['ready']);
}
}