- ProvisionDnsDomainJob/SuspendDnsDomainJob: tạo domain admin lên Plesk, huỷ = suspend (is_created=3) - Khách xem zone DNS được gán ở /dich-vu/domain, quản lý bản ghi A/AAAA/CNAME/TXT/MX/SRV - send-mail hoá đơn đẩy SendInvoiceMailJob, preview + sửa nội dung, ghi mail.order_id - invoice_attachments.type (payment_proof/deployment) - CacheService xoá theo SCAN pattern, Redis không persistent mặc định - Backfill transactions.public_code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
3.0 KiB
PHP
94 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Api\Admin\Invoice;
|
|
|
|
use App\Enums\Invoice\InvoiceStatus;
|
|
use App\Enums\Order\OrderStatus;
|
|
use App\Jobs\Mail\SendInvoiceMailJob;
|
|
use App\Mail\InvoiceNotificationMail;
|
|
use App\Models\Customer;
|
|
use App\Models\Invoice;
|
|
use App\Models\Order;
|
|
use App\Models\Setting;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Spatie\Permission\Models\Role;
|
|
use Tests\TestCase;
|
|
|
|
class InvoiceSendMailTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private User $admin;
|
|
private Invoice $invoice;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Role::firstOrCreate(['name' => 'Full Administrator', 'guard_name' => 'admin']);
|
|
$this->admin = User::factory()->create();
|
|
$this->admin->assignRole('Full Administrator');
|
|
|
|
$customer = Customer::factory()->create();
|
|
$order = Order::create([
|
|
'order_num' => 'ORD-' . uniqid(),
|
|
'customer_id' => $customer->id,
|
|
'sub_total' => 100_000,
|
|
'total' => 100_000,
|
|
'status' => OrderStatus::PENDING->value,
|
|
]);
|
|
$this->invoice = Invoice::create([
|
|
'invoice_number' => 'INV-' . uniqid(),
|
|
'customer_id' => $customer->id,
|
|
'order_id' => $order->id,
|
|
'invoice_type' => 1,
|
|
'sub_total' => 100_000,
|
|
'tax' => 0,
|
|
'total' => 100_000,
|
|
'status' => InvoiceStatus::UNPAID->value,
|
|
'due_date' => now()->addDays(5)->toDateString(),
|
|
]);
|
|
}
|
|
|
|
private function sendMail(bool $mailEnabled)
|
|
{
|
|
Queue::fake();
|
|
Setting::updateOrCreate(['key' => 'email_settings'], ['value' => json_encode(['mail_enabled' => $mailEnabled])]);
|
|
|
|
return $this->actingAs($this->admin, 'admin')
|
|
->postJson("/api/v1/administrator/invoices/{$this->invoice->id}/send-mail", ['type' => 'invoice', 'message' => 'Hi']);
|
|
}
|
|
|
|
public function test_send_mail_is_queued(): void
|
|
{
|
|
$this->sendMail(true)->assertOk();
|
|
|
|
Queue::assertPushed(SendInvoiceMailJob::class, fn ($job) => $job->invoiceId === $this->invoice->id
|
|
&& $job->sentBy === $this->admin->id
|
|
&& $job->html === null);
|
|
}
|
|
|
|
public function test_send_mail_is_rejected_when_mail_is_disabled(): void
|
|
{
|
|
$this->sendMail(false)->assertStatus(422);
|
|
|
|
Queue::assertNothingPushed();
|
|
}
|
|
|
|
public function test_job_sends_invoice_mail_and_logs_it(): void
|
|
{
|
|
$this->seed(\Database\Seeders\TemplateSeeder::class);
|
|
Mail::fake();
|
|
|
|
dispatch_sync(new SendInvoiceMailJob($this->invoice->id, 'invoice', 'Hi', null, null, $this->admin->id));
|
|
|
|
Mail::assertSent(InvoiceNotificationMail::class);
|
|
$this->assertDatabaseHas('mail', ['order_id' => $this->invoice->order_id, 'sent_by' => $this->admin->id]);
|
|
}
|
|
}
|