feat(billing): renewals, coupons, VAT numbering, billing cycles and invoice payment tracking
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
ea9a53f742
commit
25f23d541e
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\Client;
|
||||
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class OrderInvoicesTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Customer $customer;
|
||||
private Order $order;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->customer = Customer::factory()->create(['status' => 1]);
|
||||
$this->order = Order::create(['order_num' => 'ORD-TEST', 'customer_id' => $this->customer->id, 'total' => 100_000, 'status' => 1]);
|
||||
|
||||
foreach ([['INV-FIRST', 1, InvoiceStatus::PAID], ['INV-RENEW', 2, InvoiceStatus::UNPAID]] as [$number, $type, $status]) {
|
||||
Invoice::create([
|
||||
'invoice_number' => $number, 'customer_id' => $this->customer->id, 'order_id' => $this->order->id,
|
||||
'invoice_type' => $type, 'sub_total' => 100_000, 'tax' => 0, 'total' => 100_000, 'status' => $status->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function as(): static
|
||||
{
|
||||
return $this->actingAs($this->customer, 'client')->withHeaders(['x-access-token' => $this->buildClientAccessToken()]);
|
||||
}
|
||||
|
||||
public function test_order_detail_lists_every_invoice_with_payable_flag_and_pay_url(): void
|
||||
{
|
||||
$response = $this->as()->getJson('/v1/client/orders/num/ORD-TEST')->assertOk();
|
||||
|
||||
$response->assertJsonCount(2, 'data.invoices')
|
||||
->assertJsonPath('data.invoices.0.invoice_number', 'INV-RENEW')
|
||||
->assertJsonPath('data.invoices.0.payable', true)
|
||||
->assertJsonPath('data.invoices.0.type_text', 'Gia hạn')
|
||||
->assertJsonPath('data.invoices.0.payment_url', '/hoa-don/ORD-TEST?invoice=INV-RENEW')
|
||||
->assertJsonPath('data.invoices.1.payable', false)
|
||||
->assertJsonPath('data.invoices.1.payment_url', '/hoa-don/ORD-TEST');
|
||||
}
|
||||
|
||||
public function test_invoice_page_can_target_a_renewal_invoice_of_the_order(): void
|
||||
{
|
||||
$this->as()->getJson('/v1/client/invoices/order/ORD-TEST')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.invoice_number', 'INV-FIRST')
|
||||
->assertJsonPath('data.order.order_num', 'ORD-TEST')
|
||||
->assertJsonPath('data.order.status', 1)
|
||||
->assertJsonPath('data.order.status_text', 'Đã kích hoạt')
|
||||
->assertJsonPath('data.order.total', 100_000);
|
||||
|
||||
$this->as()->getJson('/v1/client/invoices/order/ORD-TEST?invoice=INV-RENEW')
|
||||
->assertOk()->assertJsonPath('data.invoice_number', 'INV-RENEW');
|
||||
|
||||
$this->as()->getJson('/v1/client/invoices/order/ORD-TEST?invoice=INV-OTHER')->assertNotFound();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user