This commit is contained in:
baodev0
2026-10-08 11:25:28 +07:00
parent 1544629a1f
commit 8651dde6b1
45 changed files with 1543 additions and 357 deletions
@@ -9,8 +9,11 @@ use App\Enums\Order\OrderStatus;
use App\Models\Customer;
use App\Models\Invoice;
use App\Models\Order;
use App\Jobs\Mail\SendTemplateEmailJob;
use App\Services\InvoiceReminderService;
use App\Support\AutoEmailGate;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
@@ -25,6 +28,32 @@ class InvoiceReminderTest extends TestCase
// không phụ thuộc template có trong DB hay không.
Queue::fake();
config(['billing.reminder_offsets' => [-7, -3, 0, 3]]);
$this->setAutoDisabled([]);
}
private function setAutoDisabled(array $scenarios): void
{
DB::table('setting')->updateOrInsert(['key' => 'email_settings'], ['value' => json_encode(['auto_disabled' => $scenarios])]);
}
public function test_disabled_automatic_reminder_is_not_sent_and_step_stays(): void
{
$this->setAutoDisabled([InvoiceReminderService::SCENARIO]);
$invoice = $this->makeInvoice(now()->addDays(5));
$this->artisan('invoices:send-reminders')->assertExitCode(0);
$this->assertSame(0, (int) $invoice->fresh()->reminder_step);
Queue::assertNotPushed(SendTemplateEmailJob::class);
}
public function test_manual_reminder_is_sent_while_automatic_is_disabled(): void
{
$this->setAutoDisabled([InvoiceReminderService::SCENARIO]);
$invoice = $this->makeInvoice(now()->addDays(5));
AutoEmailGate::markManual();
$this->assertTrue(app(InvoiceReminderService::class)->remind($invoice, force: true));
}
public function test_no_reminder_is_sent_before_the_first_offset(): void