Files
portal-api/tests/Feature/Api/Admin/MailCampaignRenewalServicesTest.php
baodev0andClaude Sonnet 5.5 55a834a2f8 feat: nhắc gia hạn QR theo dịch vụ, failover server hosting, CCCD admin, log cấp phát dịch vụ
- Mail campaign: mẫu nhắc gia hạn thanh toán QR, chọn dịch vụ + chu kỳ từng dòng (renewal_services)
- Hosting: nhiều server Plesk cho một gói (service_plan_servers), chuyển server khi server chết
- Admin xem/sửa giấy tờ định danh khách, tuỳ chọn gia hạn cho khách, nhật ký cấp phát dịch vụ
- Đánh dấu mẫu email dịch vụ là non-marketing

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 18:36:41 +07:00

65 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Api\Admin;
use App\Models\Customer;
use App\Models\Product;
use App\Models\Service;
use App\Models\Template;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use Tests\TestCase;
class MailCampaignRenewalServicesTest extends TestCase
{
use RefreshDatabase;
private function admin(): User
{
$role = Role::create(['name' => 'role-' . uniqid(), 'guard_name' => 'admin']);
$role->givePermissionTo(Permission::firstOrCreate(['name' => 'mail-campaign.create', 'guard_name' => 'admin']));
$admin = User::factory()->create();
$admin->assignRole($role);
return $admin;
}
public function test_renewal_services_listing_only_contains_due_services_of_selected_customers(): void
{
$customer = Customer::factory()->create();
$this->actingAs($this->admin(), 'admin')
->getJson('/api/v1/administrator/mail-campaigns/renewal-services?' . http_build_query(['uuids' => [$customer->uuid], 'days' => 30]))
->assertOk()
->assertExactJson(['error' => false, 'data' => []]);
}
public function test_renewal_services_are_rejected_for_a_template_that_is_not_a_renewal_reminder(): void
{
Queue::fake();
$customer = Customer::factory()->create();
$template = Template::create([
'type_id' => 0, 'name' => 'T ' . uniqid(), 'format' => 'html',
'subject' => 'Ưu đãi', 'message' => '<p>Hello</p>', 'status' => 1,
]);
$service = Service::query()->forceCreate([
'uuid' => (string) \Illuminate\Support\Str::uuid(), 'customer_id' => $customer->id,
'product_id' => Product::factory()->create()->id, 'type' => 'vps', 'status' => 'active',
]);
$this->actingAs($this->admin(), 'admin')
->postJson('/api/v1/administrator/mail-campaigns', [
'template_id' => $template->id,
'recipient_type' => 'selected',
'uuids' => [$customer->uuid],
'renewal_services' => [['service_id' => $service->id, 'months' => 1]],
])
->assertStatus(422);
}
}