feat: email gửi tay/nhắc gia hạn, gói hosting, sửa dữ liệu sản phẩm
- Gửi email theo template cho 1 khách, tab lịch sử email, nhắc gia hạn dịch vụ hàng loạt - Mail lưu from/bcc/sent_by; mẫu MARKETING và mẫu cũ trong TemplateSeeder - Gói hosting: giới hạn, trạng thái, lấy plan Plesk qua CLI gateway - Backfill payment_method và ngày đơn hàng còn thiếu - Bổ sung field CPU/RAM/Disk/Băng thông cho loại sản phẩm vps và cloud Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8651dde6b1
commit
30898ea46f
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\Admin\Service;
|
||||
|
||||
use App\Mail\ServiceRenewalReminderMail;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Service;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RenewalReminderTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const BASE = '/api/v1/administrator/services/renewal-reminders';
|
||||
|
||||
private User $admin;
|
||||
private Service $soon;
|
||||
private Service $later;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->seed(\Database\Seeders\TemplateSeeder::class);
|
||||
|
||||
Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']);
|
||||
$this->admin = User::factory()->create();
|
||||
$this->admin->assignRole('Full Administrator');
|
||||
|
||||
$customer = Customer::factory()->create();
|
||||
$this->soon = Service::create(['customer_id' => $customer->id, 'status' => 'active', 'expires_at' => now()->addDays(5)]);
|
||||
$this->later = Service::create(['customer_id' => $customer->id, 'status' => 'active', 'expires_at' => now()->addDays(40)]);
|
||||
Service::create(['customer_id' => $customer->id, 'status' => 'suspended', 'expires_at' => now()->addDays(3)]);
|
||||
}
|
||||
|
||||
public function test_lists_active_services_expiring_within_days(): void
|
||||
{
|
||||
$this->actingAs($this->admin, 'admin')
|
||||
->getJson(self::BASE . '?days=30')
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.id', $this->soon->id)
|
||||
->assertJsonPath('data.0.days_left', 5);
|
||||
}
|
||||
|
||||
public function test_send_queues_reminders_bypassing_auto_disabled_scenario(): void
|
||||
{
|
||||
Mail::fake();
|
||||
Setting::updateOrCreate(['key' => 'email_settings'], ['value' => json_encode(['auto_disabled' => ['service_renewal_reminder']])]);
|
||||
|
||||
$this->actingAs($this->admin, 'admin')
|
||||
->postJson(self::BASE, ['service_ids' => [$this->soon->id, $this->later->id]])
|
||||
->assertOk();
|
||||
|
||||
Mail::assertQueued(ServiceRenewalReminderMail::class, 2);
|
||||
$this->assertDatabaseCount('mail', 2);
|
||||
$this->assertDatabaseHas('mail', ['customer_id' => $this->soon->customer_id, 'sent_by' => $this->admin->id]);
|
||||
}
|
||||
|
||||
public function test_send_is_rejected_when_mail_is_disabled(): void
|
||||
{
|
||||
Mail::fake();
|
||||
Setting::updateOrCreate(['key' => 'email_settings'], ['value' => json_encode(['mail_enabled' => false])]);
|
||||
|
||||
$this->actingAs($this->admin, 'admin')
|
||||
->postJson(self::BASE, ['service_ids' => [$this->soon->id]])
|
||||
->assertStatus(422);
|
||||
|
||||
Mail::assertNothingQueued();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user