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(); } }