parfum/tests/Feature/Member/OrderHistoryTest.php

56 lines
1.6 KiB
PHP

<?php
use App\Enums\OrderStatus;
use App\Livewire\Member\OrderHistory;
use App\Models\Customer;
use App\Models\Order;
use App\Models\OrderItem;
use Livewire\Livewire;
beforeEach(function () {
$this->setupUser();
// Ensure user has a customer profile as OrderHistory queries based on customer_id
$this->customer = Customer::factory()->for($this->user)->create();
});
it('renders the order history page', function () {
$this->actingAs($this->user);
Livewire::test(OrderHistory::class)
->assertStatus(200)
->assertSee('Riwayat Pesanan');
});
it('shows orders belonging to the authenticated user', function () {
$this->actingAs($this->user);
// Create an order for this user
$order = Order::factory()->create([
'customer_id' => $this->customer->id,
'status' => OrderStatus::PAID,
'total' => 150000, // 150,000
'created_at' => now()->subDays(2),
]);
// Create items for the order
// Ensure we provide a product for the orderable morph relation
OrderItem::factory()
->count(2)
->for($order)
->forProduct()
->create();
// Create an order for another user (noise)
$otherCustomer = Customer::factory()->create();
Order::factory()->create([
'customer_id' => $otherCustomer->id,
'total' => 999999,
]);
Livewire::test(OrderHistory::class)
->assertSee(formatCurrencyNumber(150000, 'Rp'))
->assertSee($order->status->label())
->assertSee(formatDateLocalized($order->created_at))
->assertDontSee(formatCurrencyNumber(999999, 'Rp'));
});