output:
Chunk ID: a6a690
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 3286
Output:
|-------|-------|
| customer | customer@acme.test (John Doe) |
| payment_method | credit_card |
| status / financial / fulfillment | paid / paid / unfulfilled |
| placed_at | 2 days ago |

Lines:

| Product | Variant (option values) | Qty | Unit Price | Line Total |
|---------|------------------------|-----|-----------|-----------|
| Classic Cotton T-Shirt | S / White | 2 | 2499 | 4998 |

Totals: subtotal 4998, discount 0, shipping 499, tax 798, total **5497**

Payment: mock, method "credit_card", provider_payment_id "mock_test_order1001", status "captured", amount 5497

Fulfillments: None.

---

**Order #1002 - Fully delivered (Credit Card)**

| Field | Value |
|-------|-------|
| customer | customer@acme.test (John Doe) |
| payment_method | credit_card |
| status / financial / fulfillment | fulfilled / paid / fulfilled |
| placed_at | 10 days ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Organic Hoodie | M | 1 | 5999 | 5999 |
| Classic Cotton T-Shirt | L / Black | 1 | 2499 | 2499 |

Totals: subtotal 8498, discount 0, shipping 499, tax 1357, total **8997**

Payment: mock, method "credit_card", "mock_test_order1002", captured, 8997

Fulfillment: status "delivered", tracking company "DHL", tracking number "DHL1234567890", shipped 8 days ago. Fulfillment lines cover all order lines at full quantity.

---

**Order #1003 - Partially fulfilled (Credit Card)**

| Field | Value |
|-------|-------|
| customer | jane@example.com (Jane Smith) |
| payment_method | credit_card |
| status / financial / fulfillment | paid / paid / partial |
| placed_at | 5 days ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Premium Slim Fit Jeans | 32 / Blue | 1 | 7999 | 7999 |
| Leather Belt | L/XL / Brown | 1 | 3499 | 3499 |

Totals: subtotal 11498, discount 0, shipping 499, tax 1836, total **11997**

Payment: mock, method "credit_card", "mock_test_order1003", captured, 11997

Fulfillment: status "shipped", DHL, "DHL9876543210", shipped 3 days ago. Fulfillment lines: **only the Jeans line (qty 1)**. The Belt is not yet shipped.

---

**Order #1004 - Cancelled with full refund (Credit Card)**

| Field | Value |
|-------|-------|
| customer | customer@acme.test (John Doe) |
| payment_method | credit_card |
| status / financial / fulfillment | cancelled / refunded / unfulfilled |
| placed_at | 15 days ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Classic Cotton T-Shirt | M / Navy | 1 | 2499 | 2499 |

Totals: subtotal 2499, discount 0, shipping 499, tax 399, total **2998**

Payment: mock, method "credit_card", "mock_test_order1004", status "refunded", amount 2998

Refund: amount 2998, reason "Customer requested cancellation", status "processed", provider_refund_id "mock_re_test_order1004"

---

**Order #1005 - Bank transfer awaiting payment**

| Field | Value |
|-------|-------|
| customer | jane@example.com (Jane Smith) |
| payment_method | bank_transfer |
| status / financial / fulfillment | pending / pending / unfulfilled |
| placed_at | 2 hours ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Leather Belt | S/M / Black | 1 | 3499 | 3499 |

Totals: subtotal 3499, discount 0, shipping 499, tax 559, total **3998**

Payment: mock, method "bank_transfer", "mock_test_order1005", status "pending", amount 3998

**Test purpose:** Tests the bank transfer flow - admin "Confirm Payment" button, fulfillment guard (cannot fulfill until payment confirmed), and auto-cancel job scenario.

---

**Order #1006 - Standard paid order (Credit Card)**

| Field | Value |
|-------|-------|
| customer | michael@example.com (Michael Brown) |
| payment_method | credit_card |
| status / financial / fulfillment | paid / paid / unfulfilled |
| placed_at | 1 day ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Running Sneakers | EU 42 / Black | 1 | 11999 | 11999 |

Totals: subtotal 11999, discount 0, shipping 499, tax 1916, total **12498**

Payment: mock, method "credit_card", "mock_test_order1006", captured, 12498

---

**Order #1007 - Multi-item delivered (PayPal)**

| Field | Value |
|-------|-------|
| customer | sarah@example.com (Sarah Wilson) |
| payment_method | paypal |
| status / financial / fulfillment | fulfilled / paid / fulfilled |
| placed_at | 20 days ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| V-Neck Linen Tee | M / Beige | 2 | 3499 | 6998 |
| Wool Scarf | Grey | 1 | 2999 | 2999 |

Totals: subtotal 9997, discount 0, shipping 499, tax 1596, total **10496**

Payment: mock, method "paypal", "mock_test_order1007", captured, 10496

Fulfillment: delivered, DHL, "DHL1112223334", shipped 18 days ago. All lines fulfilled.

---

**Order #1008 - Partial refund (Credit Card)**

| Field | Value |
|-------|-------|
| customer | david@example.com (David Lee) |
| payment_method | credit_card |
| status / financial / fulfillment | paid / partially_refunded / fulfilled |
| placed_at | 12 days ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Cargo Pants | 32 / Khaki | 1 | 5499 | 5499 |
| Graphic Print Tee | L | 1 | 2999 | 2999 |

Totals: subtotal 8498, discount 0, shipping 499, tax 1357, total **8997**

Payment: mock, method "credit_card", "mock_test_order1008", captured, 8997

Fulfillment: delivered, UPS, "UPS5556667778", shipped 10 days ago

Refund (partial - for Graphic Print Tee only): amount 2999, reason "Item returned", status "processed", provider_refund_id "mock_re_test_order1008"

---

**Order #1009 - Accessories order (Credit Card)**

| Field | Value |
|-------|-------|
| customer | emma@example.com (Emma Garcia) |
| payment_method | credit_card |
| status / financial / fulfillment | paid / paid / unfulfilled |
| placed_at | 3 days ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Canvas Tote Bag | Natural | 1 | 1999 | 1999 |
| Bucket Hat | S/M / Black | 1 | 2499 | 2499 |

Totals: subtotal 4498, discount 0, shipping 499, tax 718, total **4997**

Payment: mock, method "credit_card", "mock_test_order1009", captured, 4997

---

**Order #1010 - High-value order (PayPal)**

| Field | Value |
|-------|-------|
| customer | customer@acme.test (John Doe) |
| payment_method | paypal |
| status / financial / fulfillment | paid / paid / unfulfilled |
| placed_at | 1 day ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Cashmere Overcoat | M / Camel | 1 | 49999 | 49999 |

Totals: subtotal 49999, discount 0, shipping 499, tax 7983, total **50498**

Payment: mock, method "paypal", "mock_test_order1010", captured, 50498

---

**Order #1011 - Single item delivered (Credit Card)**

| Field | Value |
|-------|-------|
| customer | james@example.com (James Taylor) |
| payment_method | credit_card |
| status / financial / fulfillment | paid / paid / fulfilled |
| placed_at | 25 days ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Striped Polo Shirt | XL | 1 | 2799 | 2799 |

Totals: subtotal 2799, discount 0, shipping 499, tax 447, total **3298**

Payment: mock, method "credit_card", "mock_test_order1011", captured, 3298

Fulfillment: delivered, FedEx, "FX9998887776", shipped 23 days ago

---

**Order #1012 - Multi-quantity order (Credit Card)**

| Field | Value |
|-------|-------|
| customer | lisa@example.com (Lisa Anderson) |
| payment_method | credit_card |
| status / financial / fulfillment | paid / paid / unfulfilled |
| placed_at | 4 days ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Chino Shorts | 34 / Navy | 2 | 3999 | 7998 |

Totals: subtotal 7998, discount 0, shipping 499, tax 1277, total **8497**

Payment: mock, method "credit_card", "mock_test_order1012", captured, 8497

---

**Order #1013 - Multi-item order (Credit Card)**

| Field | Value |
|-------|-------|
| customer | robert@example.com (Robert Martinez) |
| payment_method | credit_card |
| status / financial / fulfillment | paid / paid / unfulfilled |
| placed_at | 1 day ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Wide Leg Trousers | M | 1 | 4999 | 4999 |
| Wool Scarf | Burgundy | 1 | 2999 | 2999 |

Totals: subtotal 7998, discount 0, shipping 499, tax 1277, total **8497**

Payment: mock, method "credit_card", "mock_test_order1013", captured, 8497

---

**Order #1014 - Digital product order (Credit Card)**

| Field | Value |
|-------|-------|
| customer | anna@example.com (Anna Thomas) |
| payment_method | credit_card |
| status / financial / fulfillment | paid / paid / fulfilled |
| placed_at | 14 days ago |

Lines:

| Product | Variant | Qty | Unit Price | Line Total |
|---------|---------|-----|-----------|-----------|
| Gift Card | 50 EUR | 1 | 5000 | 5000 |

Totals: subtotal 5000, discount 0, shipping **0** (digital product), tax 798, total **5000**

Payment: mock, method "credit_card", "mock_test_order1014", captured, 5000

Fulfillment: delivered (auto-fulfilled digital product), no tracking company, no tracking number, shipped_at = placed_at, delivered_at = placed_at

---

**Order #1015 - Order with discount (Bank Transfer, confirmed)**

| Field | Value |
|-------|-------|
| customer | customer@acme.test (John Doe) |
| payment_method | bank_transfer |
| status / financial / fulfillment | paid / paid / unfulfilled |
| placed_at | now (today) |

Lines:

| Product | Variant | Qty | Unit Price | Line Total | Discount Allocation |
|---------|---------|-----|-----------|-----------|-------------------|
| Classic Cotton T-Shirt | M / White | 1 | 2499 | 2499 | WELCOME10 discount, amount: 250 |
| Graphic Print Tee | M | 1 | 2999 | 2999 | WELCOME10 discount, amount: 300 |

Totals: subtotal 5498, discount **550**, shipping 499, tax 790, total **5447**

Payment: mock, method "bank_transfer", "mock_test_order1015", captured, 5447

The discount_allocations_json on each order line references the WELCOME10 discount's database ID and the allocated discount amount for that specific line.

**Test purpose:** Tests a bank transfer order that has been confirmed by the admin (payment status = captured). Contrasts with #1005 which is still pending.

---

#### Order Summary Table (Acme Fashion)

| Order | Customer | Payment Method | Status | Financial | Fulfillment | Total | Key Test Scenario |
|-------|----------|---------------|--------|-----------|-------------|-------|-------------------|
| #1001 | John Doe | credit_card | paid | paid | unfulfilled | 5497 | Awaiting fulfillment |
| #1002 | John Doe | credit_card | fulfilled | paid | fulfilled | 8997 | Delivered order |
| #1003 | Jane Smith | credit_card | paid | paid | partial | 11997 | Partial fulfillment |
| #1004 | John Doe | credit_card | cancelled | refunded | unfulfilled | 2998 | Full cancellation + refund |
| #1005 | Jane Smith | bank_transfer | pending | pending | unfulfilled | 3998 | Bank transfer awaiting payment |
| #1006 | Michael Brown | credit_card | paid | paid | unfulfilled | 12498 | Standard paid order |
| #1007 | Sarah Wilson | paypal | fulfilled | paid | fulfilled | 10496 | Multi-item delivered (PayPal) |
| #1008 | David Lee | credit_card | paid | partially_refunded | fulfilled | 8997 | Partial refund |
| #1009 | Emma Garcia | credit_card | paid | paid | unfulfilled | 4997 | Accessories order |
| #1010 | John Doe | paypal | paid | paid | unfulfilled | 50498 | High-value order (PayPal) |
| #1011 | James Taylor | credit_card | paid | paid | fulfilled | 3298 | Single item delivered |
| #1012 | Lisa Anderson | credit_card | paid | paid | unfulfilled | 8497 | Multi-quantity order |
| #1013 | Robert Martinez | credit_card | paid | paid | unfulfilled | 8497 | Multi-item order |
| #1014 | Anna Thomas | credit_card | paid | paid | fulfilled | 5000 | Digital product (auto-fulfilled) |
| #1015 | John Doe | bank_transfer | paid | paid | unfulfilled | 5447 | Order with discount (bank transfer, confirmed) |

---

**Acme Electronics - 3 orders (minimal, for tenant isolation):**

| Order | Customer | Status | Financial | Fulfillment | Total | Details |
|-------|----------|--------|-----------|-------------|-------|---------|
| #5001 | techfan@example.com | credit_card | paid | paid | fulfilled | 121298 | Pro Laptop 512GB (119999) + USB-C Cable (1299), shipping 0 |
| #5002 | gadgetlover@example.com | credit_card | paid | paid | unfulfilled | 14999 | Wireless Headphones Black (14999), shipping 0 |
| #5003 | techfan@example.com | bank_transfer | pending | pending | unfulfilled | 4999 | Monitor Stand (4999), shipping 0, bank transfer pending |

---

### 3.14 ThemeSeeder


output:
Chunk ID: 9b958e
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1358
Output:
<?php

use App\Livewire\Storefront\Account\Addresses\Index as AccountAddressesIndex;
use App\Models\Customer;
use App\Models\CustomerAddress;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Store;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    $this->withoutVite();
    $this->seed(DatabaseSeeder::class);
});

function customerAccountStore(): Store
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();

    app()->instance('current_store', $store);

    return $store;
}

function customerAccountCustomer(): Customer
{
    $store = customerAccountStore();

    return Customer::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('email', 'customer@acme.test')
        ->firstOrFail();
}

test('customer dashboard renders the account overview', function (): void {
    $customer = customerAccountCustomer();

    $this->actingAs($customer, 'customer')
        ->get('http://shop.test/account')
        ->assertOk()
        ->assertSee('My Account')
        ->assertSee('John Doe')
        ->assertSee('Recent Orders');
});

test('unauthenticated customers are redirected to login', function (): void {
    $this->get('http://shop.test/account')
        ->assertRedirect('http://shop.test/account/login');
});

test('customer order history and detail are available through account routes', function (): void {
    $store = customerAccountStore();
    $customer = customerAccountCustomer();
    $orders = collect(['#1001', '#1002', '#1004'])->map(fn (string $orderNumber): Order => Order::factory()
        ->forCustomer($customer)
        ->paid()
        ->create([
            'store_id' => $store->getKey(),
            'customer_id' => $customer->getKey(),
            'order_number' => $orderNumber,
            'email' => $customer->email,
        ]));

    OrderLine::factory()->create([
        'order_id' => $orders->first()->getKey(),
        'title_snapshot' => 'Classic Cotton T-Shirt',
    ]);

    $this->actingAs($customer, 'customer')
        ->get('http://shop.test/account/orders')
        ->assertOk()
        ->assertSee('#1001')
        ->assertSee('#1002')
        ->assertSee('#1004');

    $this->actingAs($customer, 'customer')
        ->get('http://shop.test/account/orders/'.$orders->first()->getKey())
        ->assertOk()
        ->assertSee('#1001')
        ->assertSee('Classic Cotton T-Shirt')
        ->assertSee('Subtotal')
        ->assertSee('Total');
});

test('customer can add and update addresses', function (): void {
    $customer = customerAccountCustomer();

    $this->actingAs($customer, 'customer');

    Livewire::test(AccountAddressesIndex::class)
        ->assertSee('Main Street 1')
        ->call('openAddressForm')
        ->set('addressLabel', 'Office')
        ->set('address.first_name', 'John')
        ->set('address.last_name', 'Doe')
        ->set('address.address1', 'New Street 42')
        ->set('address.city', 'Hamburg')
        ->set('address.postal_code', '20095')
        ->set('address.country', 'DE')
        ->call('saveAddress')
        ->assertSee('Address saved')
        ->assertSee('New Street 42')
        ->assertSee('Hamburg');

    $address = CustomerAddress::query()
        ->where('customer_id', $customer->getKey())
        ->where('label', 'Office')
        ->firstOrFail();

    expect(data_get($address->address_json, 'city'))->toBe('Hamburg');

    Livewire::test(AccountAddressesIndex::class)
        ->call('openAddressForm', $address->getKey())
        ->set('address.city', 'Frankfurt')
        ->call('saveAddress')
        ->assertSee('Address saved')
        ->assertSee('Frankfurt');

    expect(data_get($address->refresh()->address_json, 'city'))->toBe('Frankfurt');
});

test('customer can set a default address and delete an address', function (): void {
    $customer = customerAccountCustomer();
    $homeAddress = CustomerAddress::query()
        ->where('customer_id', $customer->getKey())
        ->where('label', 'Home')
        ->firstOrFail();
    $officeAddress = CustomerAddress::factory()->create([
        'customer_id' => $customer->getKey(),
        'label' => 'Office',
        'address_json' => [
            'first_name' => 'John',
            'last_name' => 'Doe',
            'address1' => 'Office Street 10',
            'address2' => null,
            'city' => 'Munich',
            'province_code' => null,
            'country' => 'DE',
            'postal_code' => '80331',
        ],
        'is_default' => false,
    ]);

    $this->actingAs($customer, 'customer');

    Livewire::test(AccountAddressesIndex::class)
        ->call('setDefaultAddress', $officeAddress->getKey())
        ->assertSee('Default address updated')
        ->call('deleteAddress', $officeAddress->getKey())
        ->assertSee('Address deleted');

    expect(CustomerAddress::query()->whereKey($officeAddress->getKey())->exists())->toBeFalse()
        ->and($homeAddress->refresh()->is_default)->toBeTrue();
});

test('customer logout clears the customer guard', function (): void {
    $customer = customerAccountCustomer();

    $this->actingAs($customer, 'customer')
        ->post('http://shop.test/account/logout')
        ->assertRedirect('http://shop.test/account/login');

    $this->assertGuest('customer');
});


command: sed -n '1,260p' tests/Feature/Storefront/OrderViewsTest.php

OrderViewsTest.php

type: read

aggregated_output:
<?php

use App\Enums\CartStatus;
use App\Enums\CheckoutStatus;
use App\Livewire\Storefront\Account\Orders\Index as AccountOrdersIndex;
use App\Livewire\Storefront\Account\Orders\Show as AccountOrderShow;
use App\Livewire\Storefront\Checkout\Confirmation;
use App\Livewire\Storefront\Checkout\Show as CheckoutShow;
use App\Models\Checkout;
use App\Models\Customer;
use App\Models\InventoryItem;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\ShippingRate;
use App\Models\Store;
use App\Services\CartService;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

beforeEach(function () {
    $this->withoutVite();
    $this->seed(DatabaseSeeder::class);
});

function orderViewsStore(): Store
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
    app()->instance('current_store', $store);

    return $store;
}

function orderViewsVariant(Store $store): ProductVariant
{
    $product = Product::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('handle', 'classic-cotton-t-shirt')
        ->firstOrFail();

    return ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->oldest('position')
        ->firstOrFail();
}

function orderViewsShippingRate(Store $store): ShippingRate
{
    return ShippingRate::withoutGlobalScopes()
        ->whereHas('zone', fn ($query) => $query->withoutGlobalScopes()->where('store_id', $store->getKey()))
        ->where('name', 'Standard Shipping')
        ->firstOrFail();
}

test('checkout page places an order and redirects to confirmation', function () {
    $store = orderViewsStore();
    $variant = orderViewsVariant($store);
    $cart = app(CartService::class)->create($store);
    session(['cart_id' => $cart->getKey()]);
    app(CartService::class)->addLine($cart, $variant->getKey(), 2);

    $component = Livewire::test(CheckoutShow::class)
        ->set('email', 'buyer@example.test')
        ->set('shippingAddress.first_name', 'Test')
        ->set('shippingAddress.last_name', 'Buyer')
        ->set('shippingAddress.address1', 'Main Street 1')
        ->set('shippingAddress.city', 'Berlin')
        ->set('shippingAddress.country', 'DE')
        ->set('shippingAddress.postal_code', '10115')
        ->call('saveAddress')
        ->set('selectedShippingRateId', orderViewsShippingRate($store)->getKey())
        ->call('selectShippingMethod')
        ->set('paymentMethod', 'credit_card')
        ->call('selectPaymentMethod')
        ->set('cardNumber', '4242 4242 4242 4242')
        ->call('placeOrder');

    $order = Order::withoutGlobalScopes()->firstOrFail();

    $component->assertRedirect(route('checkout.confirmation', $order));

    expect($order->email)->toBe('buyer@example.test')
        ->and($order->lines)->toHaveCount(1)
        ->and($cart->refresh()->status)->toBe(CartStatus::Converted)
        ->and(session('last_order_id'))->toBe($order->getKey())
        ->and(session('cart_id'))->toBeNull();
});

test('checkout page surfaces payment failures and releases reservations', function () {
    $store = orderViewsStore();
    $variant = orderViewsVariant($store);
    $cart = app(CartService::class)->create($store);
    session(['cart_id' => $cart->getKey()]);
    app(CartService::class)->addLine($cart, $variant->getKey(), 2);

    Livewire::test(CheckoutShow::class)
        ->set('email', 'buyer@example.test')
        ->set('shippingAddress.first_name', 'Test')
        ->set('shippingAddress.last_name', 'Buyer')
        ->set('shippingAddress.address1', 'Main Street 1')
        ->set('shippingAddress.city', 'Berlin')
        ->set('shippingAddress.country', 'DE')
        ->set('shippingAddress.postal_code', '10115')
        ->call('saveAddress')
        ->set('selectedShippingRateId', orderViewsShippingRate($store)->getKey())
        ->call('selectShippingMethod')
        ->set('paymentMethod', 'credit_card')
        ->call('selectPaymentMethod')
        ->set('cardNumber', '4000 0000 0000 0002')
        ->call('placeOrder')
        ->assertHasErrors('cardNumber')
        ->assertSet('step', 'payment');

    $checkout = Checkout::withoutGlobalScopes()->where('cart_id', $cart->getKey())->firstOrFail();
    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect(Order::withoutGlobalScopes()->count())->toBe(0)
        ->and($checkout->status)->toBe(CheckoutStatus::ShippingSelected)
        ->and($inventory->quantity_reserved)->toBe(0);
});

test('order confirmation is visible only for the session order or customer order', function () {
    $store = orderViewsStore();
    $customer = Customer::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
    $otherCustomer = Customer::factory()->create(['store_id' => $store->getKey()]);
    $order = Order::factory()->forCustomer($customer)->paid()->create([
        'store_id' => $store->getKey(),
        'customer_id' => $customer->getKey(),
        'email' => $customer->email,
    ]);

    session(['last_order_id' => $order->getKey()]);

    Livewire::test(Confirmation::class, ['order' => $order])
        ->assertSee($order->order_number);

    session()->forget('last_order_id');

    Livewire::test(Confirmation::class, ['order' => $order])
        ->assertStatus(404);

    $this->actingAs($otherCustomer, 'customer');

    Livewire::test(Confirmation::class, ['order' => $order])
        ->assertStatus(404);

    $this->actingAs($customer, 'customer');

    Livewire::test(Confirmation::class, ['order' => $order])
        ->assertSee($order->order_number);
});

test('customer account lists and shows customer orders', function () {
    $store = orderViewsStore();
    $customer = Customer::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
    $otherCustomer = Customer::factory()->create(['store_id' => $store->getKey()]);
    $order = Order::factory()->forCustomer($customer)->paid()->create([
        'store_id' => $store->getKey(),
        'customer_id' => $customer->getKey(),
        'order_number' => '#7777',
    ]);
    $otherOrder = Order::factory()->forCustomer($otherCustomer)->paid()->create([
        'store_id' => $store->getKey(),
        'customer_id' => $otherCustomer->getKey(),
        'order_number' => '#8888',
    ]);
    OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'title_snapshot' => 'Classic Cotton T-Shirt',
    ]);

    $this->actingAs($customer, 'customer');

    Livewire::test(AccountOrdersIndex::class)
        ->assertSee('#7777')
        ->assertDontSee('#8888');

    Livewire::test(AccountOrderShow::class, ['order' => $order])
        ->assertSee('Classic Cotton T-Shirt')
        ->assertSee('#7777');

    Livewire::test(AccountOrderShow::class, ['order' => $otherOrder])
        ->assertStatus(404);
});

status: completed


output:
Chunk ID: d21b57
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1754
Output:
<?php

use App\Enums\CartStatus;
use App\Enums\CheckoutStatus;
use App\Livewire\Storefront\Account\Orders\Index as AccountOrdersIndex;
use App\Livewire\Storefront\Account\Orders\Show as AccountOrderShow;
use App\Livewire\Storefront\Checkout\Confirmation;
use App\Livewire\Storefront\Checkout\Show as CheckoutShow;
use App\Models\Checkout;
use App\Models\Customer;
use App\Models\InventoryItem;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\ShippingRate;
use App\Models\Store;
use App\Services\CartService;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

beforeEach(function () {
    $this->withoutVite();
    $this->seed(DatabaseSeeder::class);
});

function orderViewsStore(): Store
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
    app()->instance('current_store', $store);

    return $store;
}

function orderViewsVariant(Store $store): ProductVariant
{
    $product = Product::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('handle', 'classic-cotton-t-shirt')
        ->firstOrFail();

    return ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->oldest('position')
        ->firstOrFail();
}

function orderViewsShippingRate(Store $store): ShippingRate
{
    return ShippingRate::withoutGlobalScopes()
        ->whereHas('zone', fn ($query) => $query->withoutGlobalScopes()->where('store_id', $store->getKey()))
        ->where('name', 'Standard Shipping')
        ->firstOrFail();
}

test('checkout page places an order and redirects to confirmation', function () {
    $store = orderViewsStore();
    $variant = orderViewsVariant($store);
    $cart = app(CartService::class)->create($store);
    session(['cart_id' => $cart->getKey()]);
    app(CartService::class)->addLine($cart, $variant->getKey(), 2);

    $component = Livewire::test(CheckoutShow::class)
        ->set('email', 'buyer@example.test')
        ->set('shippingAddress.first_name', 'Test')
        ->set('shippingAddress.last_name', 'Buyer')
        ->set('shippingAddress.address1', 'Main Street 1')
        ->set('shippingAddress.city', 'Berlin')
        ->set('shippingAddress.country', 'DE')
        ->set('shippingAddress.postal_code', '10115')
        ->call('saveAddress')
        ->set('selectedShippingRateId', orderViewsShippingRate($store)->getKey())
        ->call('selectShippingMethod')
        ->set('paymentMethod', 'credit_card')
        ->call('selectPaymentMethod')
        ->set('cardNumber', '4242 4242 4242 4242')
        ->call('placeOrder');

    $order = Order::withoutGlobalScopes()->firstOrFail();

    $component->assertRedirect(route('checkout.confirmation', $order));

    expect($order->email)->toBe('buyer@example.test')
        ->and($order->lines)->toHaveCount(1)
        ->and($cart->refresh()->status)->toBe(CartStatus::Converted)
        ->and(session('last_order_id'))->toBe($order->getKey())
        ->and(session('cart_id'))->toBeNull();
});

test('checkout page surfaces payment failures and releases reservations', function () {
    $store = orderViewsStore();
    $variant = orderViewsVariant($store);
    $cart = app(CartService::class)->create($store);
    session(['cart_id' => $cart->getKey()]);
    app(CartService::class)->addLine($cart, $variant->getKey(), 2);

    Livewire::test(CheckoutShow::class)
        ->set('email', 'buyer@example.test')
        ->set('shippingAddress.first_name', 'Test')
        ->set('shippingAddress.last_name', 'Buyer')
        ->set('shippingAddress.address1', 'Main Street 1')
        ->set('shippingAddress.city', 'Berlin')
        ->set('shippingAddress.country', 'DE')
        ->set('shippingAddress.postal_code', '10115')
        ->call('saveAddress')
        ->set('selectedShippingRateId', orderViewsShippingRate($store)->getKey())
        ->call('selectShippingMethod')
        ->set('paymentMethod', 'credit_card')
        ->call('selectPaymentMethod')
        ->set('cardNumber', '4000 0000 0000 0002')
        ->call('placeOrder')
        ->assertHasErrors('cardNumber')
        ->assertSet('step', 'payment');

    $checkout = Checkout::withoutGlobalScopes()->where('cart_id', $cart->getKey())->firstOrFail();
    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect(Order::withoutGlobalScopes()->count())->toBe(0)
        ->and($checkout->status)->toBe(CheckoutStatus::ShippingSelected)
        ->and($inventory->quantity_reserved)->toBe(0);
});

test('order confirmation is visible only for the session order or customer order', function () {
    $store = orderViewsStore();
    $customer = Customer::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
    $otherCustomer = Customer::factory()->create(['store_id' => $store->getKey()]);
    $order = Order::factory()->forCustomer($customer)->paid()->create([
        'store_id' => $store->getKey(),
        'customer_id' => $customer->getKey(),
        'email' => $customer->email,
    ]);

    session(['last_order_id' => $order->getKey()]);

    Livewire::test(Confirmation::class, ['order' => $order])
        ->assertSee($order->order_number);

    session()->forget('last_order_id');

    Livewire::test(Confirmation::class, ['order' => $order])
        ->assertStatus(404);

    $this->actingAs($otherCustomer, 'customer');

    Livewire::test(Confirmation::class, ['order' => $order])
        ->assertStatus(404);

    $this->actingAs($customer, 'customer');

    Livewire::test(Confirmation::class, ['order' => $order])
        ->assertSee($order->order_number);
});

test('customer account lists and shows customer orders', function () {
    $store = orderViewsStore();
    $customer = Customer::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
    $otherCustomer = Customer::factory()->create(['store_id' => $store->getKey()]);
    $order = Order::factory()->forCustomer($customer)->paid()->create([
        'store_id' => $store->getKey(),
        'customer_id' => $customer->getKey(),
        'order_number' => '#7777',
    ]);
    $otherOrder = Order::factory()->forCustomer($otherCustomer)->paid()->create([
        'store_id' => $store->getKey(),
        'customer_id' => $otherCustomer->getKey(),
        'order_number' => '#8888',
    ]);
    OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'title_snapshot' => 'Classic Cotton T-Shirt',
    ]);

    $this->actingAs($customer, 'customer');

    Livewire::test(AccountOrdersIndex::class)
        ->assertSee('#7777')
        ->assertDontSee('#8888');

    Livewire::test(AccountOrderShow::class, ['order' => $order])
        ->assertSee('Classic Cotton T-Shirt')
        ->assertSee('#7777');

    Livewire::test(AccountOrderShow::class, ['order' => $otherOrder])
        ->assertStatus(404);
});


command: sed -n '1,260p' tests/Feature/Admin/DashboardTest.php

DashboardTest.php

aggregated_output:
<?php

use App\Livewire\Admin\Dashboard as AdminDashboard;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    $this->withoutVite();
    $this->seed(DatabaseSeeder::class);
});

function adminDashboardStore(): Store
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
    app()->instance('current_store', $store);

    return $store;
}

function adminDashboardUser(): User
{
    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
}

function adminDashboardOrder(Store $store, string $title, int $quantity, int $unitPrice, array $orderAttributes = []): Order
{
    $product = Product::factory()
        ->withDefaultVariant($unitPrice)
        ->create([
            'store_id' => $store->getKey(),
            'title' => $title,
        ]);
    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->firstOrFail();
    $total = $quantity * $unitPrice;
    $order = Order::factory()->paid()->create(array_merge([
        'store_id' => $store->getKey(),
        'subtotal_amount' => $total,
        'shipping_amount' => 0,
        'tax_amount' => 0,
        'total_amount' => $total,
        'placed_at' => now(),
    ], $orderAttributes));

    OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $product->getKey(),
        'variant_id' => $variant->getKey(),
        'title_snapshot' => $title,
        'sku_snapshot' => 'DASH-'.str($title)->slug()->upper(),
        'quantity' => $quantity,
        'unit_price_amount' => $unitPrice,
        'total_amount' => $total,
    ]);

    return $order;
}

test('admin dashboard route requires authentication and renders store scoped metrics', function (): void {
    $store = adminDashboardStore();
    adminDashboardOrder($store, 'Dashboard Jacket', 2, 2500);
    adminDashboardOrder($store, 'Dashboard Cap', 1, 2000);

    $otherStore = Store::factory()->create();
    adminDashboardOrder($otherStore, 'Other Store Product', 1, 9900);

    $this->get('/admin')->assertRedirect('/admin/login');

    $this->actingAs(adminDashboardUser())
        ->withSession(['current_store_id' => $store->getKey()])
        ->get('/admin')
        ->assertSuccessful()
        ->assertSee('Dashboard')
        ->assertSee('70.00 EUR')
        ->assertSee('Dashboard Jacket')
        ->assertDontSee('Other Store Product');
});

test('admin dashboard recalculates kpis when date range changes', function (): void {
    $store = adminDashboardStore();
    $user = adminDashboardUser();

    adminDashboardOrder($store, 'Today Product', 1, 6000);
    adminDashboardOrder($store, 'Older Product', 1, 4000, [
        'placed_at' => now()->subDays(15),
    ]);

    Livewire::actingAs($user)
        ->test(AdminDashboard::class)
        ->assertSet('ordersCount', 2)
        ->assertSet('totalSales', 10000)
        ->set('dateRange', 'today')
        ->assertSet('ordersCount', 1)
        ->assertSet('totalSales', 6000)
        ->set('dateRange', 'custom')
        ->set('customStartDate', now()->subDays(20)->toDateString())
        ->set('customEndDate', now()->subDays(10)->toDateString())
        ->assertSet('ordersCount', 1)
        ->assertSet('totalSales', 4000);
});


output:
Chunk ID: 76d3f1
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 881
Output:
<?php

use App\Livewire\Admin\Dashboard as AdminDashboard;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    $this->withoutVite();
    $this->seed(DatabaseSeeder::class);
});

function adminDashboardStore(): Store
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
    app()->instance('current_store', $store);

    return $store;
}

function adminDashboardUser(): User
{
    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
}

function adminDashboardOrder(Store $store, string $title, int $quantity, int $unitPrice, array $orderAttributes = []): Order
{
    $product = Product::factory()
        ->withDefaultVariant($unitPrice)
        ->create([
            'store_id' => $store->getKey(),
            'title' => $title,
        ]);
    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->firstOrFail();
    $total = $quantity * $unitPrice;
    $order = Order::factory()->paid()->create(array_merge([
        'store_id' => $store->getKey(),
        'subtotal_amount' => $total,
        'shipping_amount' => 0,
        'tax_amount' => 0,
        'total_amount' => $total,
        'placed_at' => now(),
    ], $orderAttributes));

    OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $product->getKey(),
        'variant_id' => $variant->getKey(),
        'title_snapshot' => $title,
        'sku_snapshot' => 'DASH-'.str($title)->slug()->upper(),
        'quantity' => $quantity,
        'unit_price_amount' => $unitPrice,
        'total_amount' => $total,
    ]);

    return $order;
}

test('admin dashboard route requires authentication and renders store scoped metrics', function (): void {
    $store = adminDashboardStore();
    adminDashboardOrder($store, 'Dashboard Jacket', 2, 2500);
    adminDashboardOrder($store, 'Dashboard Cap', 1, 2000);

    $otherStore = Store::factory()->create();
    adminDashboardOrder($otherStore, 'Other Store Product', 1, 9900);

    $this->get('/admin')->assertRedirect('/admin/login');

    $this->actingAs(adminDashboardUser())
        ->withSession(['current_store_id' => $store->getKey()])
        ->get('/admin')
        ->assertSuccessful()
        ->assertSee('Dashboard')
        ->assertSee('70.00 EUR')
        ->assertSee('Dashboard Jacket')
        ->assertDontSee('Other Store Product');
});

test('admin dashboard recalculates kpis when date range changes', function (): void {
    $store = adminDashboardStore();
    $user = adminDashboardUser();

    adminDashboardOrder($store, 'Today Product', 1, 6000);
    adminDashboardOrder($store, 'Older Product', 1, 4000, [
        'placed_at' => now()->subDays(15),
    ]);

    Livewire::actingAs($user)
        ->test(AdminDashboard::class)
        ->assertSet('ordersCount', 2)
        ->assertSet('totalSales', 10000)
        ->set('dateRange', 'today')
        ->assertSet('ordersCount', 1)
        ->assertSet('totalSales', 6000)
        ->set('dateRange', 'custom')
        ->set('customStartDate', now()->subDays(20)->toDateString())
        ->set('customEndDate', now()->subDays(10)->toDateString())
        ->assertSet('ordersCount', 1)
        ->assertSet('totalSales', 4000);
});


command: sed -n '1,280p' tests/Browser/Admin/OrderManagementTest.php

OrderManagementTest.php

aggregated_output:
<?php

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentShipmentStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentMethod;
use App\Enums\PaymentStatus;
use App\Models\Customer;
use App\Models\Fulfillment;
use App\Models\InventoryItem;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Payment;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Pest\Browser\Playwright\Playwright;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    Playwright::setHost('shop.test');

    $this->seed(DatabaseSeeder::class);
});

afterEach(function (): void {
    Playwright::setHost(null);
});

function adminOrderHost(): array
{
    return ['host' => 'shop.test'];
}

function adminOrderAuthenticate(mixed $testCase): void
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();

    $testCase->actingAs($user);
    $testCase->withSession(['current_store_id' => $store->getKey()]);
}

/**
 * @return array{store: Store, paid: Order, fulfilled: Order, bank: Order}
 */
function adminOrderFixtures(): array
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
    $customer = Customer::query()->where('email', 'customer@acme.test')->firstOrFail();
    $product = Product::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('handle', 'classic-cotton-t-shirt')
        ->firstOrFail();
    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->firstOrFail();

    $paid = adminOrderCreateOrder(
        store: $store,
        customer: $customer,
        product: $product,
        variant: $variant,
        orderNumber: '#1001',
        paymentMethod: PaymentMethod::CreditCard,
        status: OrderStatus::Paid,
        financialStatus: FinancialStatus::Paid,
        fulfillmentStatus: FulfillmentStatus::Unfulfilled,
        placedAt: now()->subDays(3),
    );

    $fulfilled = adminOrderCreateOrder(
        store: $store,
        customer: $customer,
        product: $product,
        variant: $variant,
        orderNumber: '#1002',
        paymentMethod: PaymentMethod::CreditCard,
        status: OrderStatus::Fulfilled,
        financialStatus: FinancialStatus::Paid,
        fulfillmentStatus: FulfillmentStatus::Fulfilled,
        placedAt: now()->subDays(2),
    );

    adminOrderCreateDeliveredFulfillment($fulfilled);

    $bank = adminOrderCreateOrder(
        store: $store,
        customer: $customer,
        product: $product,
        variant: $variant,
        orderNumber: '#1005',
        paymentMethod: PaymentMethod::BankTransfer,
        status: OrderStatus::Pending,
        financialStatus: FinancialStatus::Pending,
        fulfillmentStatus: FulfillmentStatus::Unfulfilled,
        placedAt: now()->subDay(),
    );

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update([
            'quantity_on_hand' => 20,
            'quantity_reserved' => 1,
        ]);

    return [
        'store' => $store,
        'paid' => $paid,
        'fulfilled' => $fulfilled,
        'bank' => $bank,
    ];
}

function adminOrderCreateOrder(
    Store $store,
    Customer $customer,
    Product $product,
    ProductVariant $variant,
    string $orderNumber,
    PaymentMethod $paymentMethod,
    OrderStatus $status,
    FinancialStatus $financialStatus,
    FulfillmentStatus $fulfillmentStatus,
    mixed $placedAt,
): Order {
    $subtotal = $variant->price_amount;
    $shipping = 499;
    $tax = 0;
    $total = $subtotal + $shipping + $tax;

    $order = Order::factory()->create([
        'store_id' => $store->getKey(),
        'customer_id' => $customer->getKey(),
        'order_number' => $orderNumber,
        'payment_method' => $paymentMethod,
        'status' => $status,
        'financial_status' => $financialStatus,
        'fulfillment_status' => $fulfillmentStatus,
        'currency' => $store->default_currency,
        'subtotal_amount' => $subtotal,
        'discount_amount' => 0,
        'shipping_amount' => $shipping,
        'tax_amount' => $tax,
        'total_amount' => $total,
        'email' => $customer->email,
        'placed_at' => $placedAt,
    ]);

    OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $product->getKey(),
        'variant_id' => $variant->getKey(),
        'title_snapshot' => 'Classic Cotton T-Shirt',
        'sku_snapshot' => $variant->sku,
        'quantity' => 1,
        'unit_price_amount' => $variant->price_amount,
        'total_amount' => $variant->price_amount,
    ]);

    Payment::factory()->create([
        'order_id' => $order->getKey(),
        'method' => $paymentMethod,
        'status' => $financialStatus === FinancialStatus::Pending ? PaymentStatus::Pending : PaymentStatus::Captured,
        'amount' => $total,
        'currency' => $store->default_currency,
    ]);

    return $order->refresh();
}

function adminOrderCreateDeliveredFulfillment(Order $order): void
{
    $line = $order->lines()->firstOrFail();
    $fulfillment = Fulfillment::query()->create([
        'order_id' => $order->getKey(),
        'status' => FulfillmentShipmentStatus::Delivered,
        'tracking_company' => 'DHL',
        'tracking_number' => 'DHL1234567890',
        'shipped_at' => now()->subDay(),
        'delivered_at' => now(),
    ]);

    $fulfillment->lines()->create([
        'order_line_id' => $line->getKey(),
        'quantity' => $line->quantity,
    ]);
}

function adminOrderOpenOrders(mixed $testCase): mixed
{
    adminOrderFixtures();
    adminOrderAuthenticate($testCase);

    return visit('/admin/orders', adminOrderHost())
        ->wait(1)
        ->assertPathIs('/admin/orders')
        ->assertSee('Orders')
        ->assertNoJavaScriptErrors();
}

function adminOrderOpenOrder(mixed $testCase, string $orderNumber): mixed
{
    return adminOrderOpenOrders($testCase)
        ->assertSee($orderNumber)
        ->click("a:has-text(\"{$orderNumber}\")")
        ->wait(1)
        ->assertSee($orderNumber)
        ->assertNoJavaScriptErrors();
}

function adminOrderCreateFulfillmentInBrowser(mixed $page): mixed
{
    return $page
        ->click('button[data-test="fulfillment-modal-button"]')
        ->wait(1)
        ->fill('input[wire\\:model="trackingCompany"]', 'DHL')
        ->fill('input[wire\\:model="trackingNumber"]', 'DHL123456789')
        ->click('button[data-test="fulfillment-submit-button"]')
        ->wait(1)
        ->assertSee('Fulfillment created')
        ->assertSee('DHL')
        ->assertSee('DHL123456789')
        ->assertNoJavaScriptErrors();
}

test('shows the order list with seeded orders', function (): void {
    adminOrderOpenOrders($this)
        ->assertSee('#1001')
        ->assertNoJavaScriptErrors();
});

test('can filter orders by status', function (): void {
    adminOrderOpenOrders($this)
        ->select('select[wire\\:model\\.live="financialStatusFilter"]', 'paid')
        ->wait(1)
        ->assertSee('#1001')
        ->assertDontSee('#1005')
        ->assertNoJavaScriptErrors()
        ->select('select[wire\\:model\\.live="fulfillmentStatusFilter"]', 'fulfilled')
        ->wait(1)
        ->assertSee('#1002')
        ->assertNoJavaScriptErrors()
        ->select('select[wire\\:model\\.live="financialStatusFilter"]', 'all')
        ->select('select[wire\\:model\\.live="fulfillmentStatusFilter"]', 'all')
        ->wait(1)
        ->assertSee('#1001')
        ->assertSee('#1005')
        ->assertNoJavaScriptErrors();
});

test('shows order detail with line items and totals', function (): void {
    adminOrderOpenOrder($this, '#1001')
        ->assertSee('Paid')
        ->assertSee('Unfulfilled')
        ->assertSee('Classic Cotton T-Shirt')
        ->assertSee('Subtotal')
        ->assertSee('Shipping')
        ->assertSee('Tax')
        ->assertSee('Total')
        ->assertNoJavaScriptErrors();
});

test('shows order timeline events', function (): void {
    adminOrderOpenOrder($this, '#1001')
        ->assertSee('Timeline')
        ->assertSee('Order placed')
        ->assertNoJavaScriptErrors();
});

test('can create a fulfillment', function (): void {
    adminOrderCreateFulfillmentInBrowser(adminOrderOpenOrder($this, '#1001'));
});

test('can process a refund', function (): void {


output:
Chunk ID: c88e20
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 2148
Output:
<?php

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentShipmentStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentMethod;
use App\Enums\PaymentStatus;
use App\Models\Customer;
use App\Models\Fulfillment;
use App\Models\InventoryItem;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Payment;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Pest\Browser\Playwright\Playwright;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    Playwright::setHost('shop.test');

    $this->seed(DatabaseSeeder::class);
});

afterEach(function (): void {
    Playwright::setHost(null);
});

function adminOrderHost(): array
{
    return ['host' => 'shop.test'];
}

function adminOrderAuthenticate(mixed $testCase): void
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();

    $testCase->actingAs($user);
    $testCase->withSession(['current_store_id' => $store->getKey()]);
}

/**
 * @return array{store: Store, paid: Order, fulfilled: Order, bank: Order}
 */
function adminOrderFixtures(): array
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
    $customer = Customer::query()->where('email', 'customer@acme.test')->firstOrFail();
    $product = Product::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('handle', 'classic-cotton-t-shirt')
        ->firstOrFail();
    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->firstOrFail();

    $paid = adminOrderCreateOrder(
        store: $store,
        customer: $customer,
        product: $product,
        variant: $variant,
        orderNumber: '#1001',
        paymentMethod: PaymentMethod::CreditCard,
        status: OrderStatus::Paid,
        financialStatus: FinancialStatus::Paid,
        fulfillmentStatus: FulfillmentStatus::Unfulfilled,
        placedAt: now()->subDays(3),
    );

    $fulfilled = adminOrderCreateOrder(
        store: $store,
        customer: $customer,
        product: $product,
        variant: $variant,
        orderNumber: '#1002',
        paymentMethod: PaymentMethod::CreditCard,
        status: OrderStatus::Fulfilled,
        financialStatus: FinancialStatus::Paid,
        fulfillmentStatus: FulfillmentStatus::Fulfilled,
        placedAt: now()->subDays(2),
    );

    adminOrderCreateDeliveredFulfillment($fulfilled);

    $bank = adminOrderCreateOrder(
        store: $store,
        customer: $customer,
        product: $product,
        variant: $variant,
        orderNumber: '#1005',
        paymentMethod: PaymentMethod::BankTransfer,
        status: OrderStatus::Pending,
        financialStatus: FinancialStatus::Pending,
        fulfillmentStatus: FulfillmentStatus::Unfulfilled,
        placedAt: now()->subDay(),
    );

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update([
            'quantity_on_hand' => 20,
            'quantity_reserved' => 1,
        ]);

    return [
        'store' => $store,
        'paid' => $paid,
        'fulfilled' => $fulfilled,
        'bank' => $bank,
    ];
}

function adminOrderCreateOrder(
    Store $store,
    Customer $customer,
    Product $product,
    ProductVariant $variant,
    string $orderNumber,
    PaymentMethod $paymentMethod,
    OrderStatus $status,
    FinancialStatus $financialStatus,
    FulfillmentStatus $fulfillmentStatus,
    mixed $placedAt,
): Order {
    $subtotal = $variant->price_amount;
    $shipping = 499;
    $tax = 0;
    $total = $subtotal + $shipping + $tax;

    $order = Order::factory()->create([
        'store_id' => $store->getKey(),
        'customer_id' => $customer->getKey(),
        'order_number' => $orderNumber,
        'payment_method' => $paymentMethod,
        'status' => $status,
        'financial_status' => $financialStatus,
        'fulfillment_status' => $fulfillmentStatus,
        'currency' => $store->default_currency,
        'subtotal_amount' => $subtotal,
        'discount_amount' => 0,
        'shipping_amount' => $shipping,
        'tax_amount' => $tax,
        'total_amount' => $total,
        'email' => $customer->email,
        'placed_at' => $placedAt,
    ]);

    OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $product->getKey(),
        'variant_id' => $variant->getKey(),
        'title_snapshot' => 'Classic Cotton T-Shirt',
        'sku_snapshot' => $variant->sku,
        'quantity' => 1,
        'unit_price_amount' => $variant->price_amount,
        'total_amount' => $variant->price_amount,
    ]);

    Payment::factory()->create([
        'order_id' => $order->getKey(),
        'method' => $paymentMethod,
        'status' => $financialStatus === FinancialStatus::Pending ? PaymentStatus::Pending : PaymentStatus::Captured,
        'amount' => $total,
        'currency' => $store->default_currency,
    ]);

    return $order->refresh();
}

function adminOrderCreateDeliveredFulfillment(Order $order): void
{
    $line = $order->lines()->firstOrFail();
    $fulfillment = Fulfillment::query()->create([
        'order_id' => $order->getKey(),
        'status' => FulfillmentShipmentStatus::Delivered,
        'tracking_company' => 'DHL',
        'tracking_number' => 'DHL1234567890',
        'shipped_at' => now()->subDay(),
        'delivered_at' => now(),
    ]);

    $fulfillment->lines()->create([
        'order_line_id' => $line->getKey(),
        'quantity' => $line->quantity,
    ]);
}

function adminOrderOpenOrders(mixed $testCase): mixed
{
    adminOrderFixtures();
    adminOrderAuthenticate($testCase);

    return visit('/admin/orders', adminOrderHost())
        ->wait(1)
        ->assertPathIs('/admin/orders')
        ->assertSee('Orders')
        ->assertNoJavaScriptErrors();
}

function adminOrderOpenOrder(mixed $testCase, string $orderNumber): mixed
{
    return adminOrderOpenOrders($testCase)
        ->assertSee($orderNumber)
        ->click("a:has-text(\"{$orderNumber}\")")
        ->wait(1)
        ->assertSee($orderNumber)
        ->assertNoJavaScriptErrors();
}

function adminOrderCreateFulfillmentInBrowser(mixed $page): mixed
{
    return $page
        ->click('button[data-test="fulfillment-modal-button"]')
        ->wait(1)
        ->fill('input[wire\\:model="trackingCompany"]', 'DHL')
        ->fill('input[wire\\:model="trackingNumber"]', 'DHL123456789')
        ->click('button[data-test="fulfillment-submit-button"]')
        ->wait(1)
        ->assertSee('Fulfillment created')
        ->assertSee('DHL')
        ->assertSee('DHL123456789')
        ->assertNoJavaScriptErrors();
}

test('shows the order list with seeded orders', function (): void {
    adminOrderOpenOrders($this)
        ->assertSee('#1001')
        ->assertNoJavaScriptErrors();
});

test('can filter orders by status', function (): void {
    adminOrderOpenOrders($this)
        ->select('select[wire\\:model\\.live="financialStatusFilter"]', 'paid')
        ->wait(1)
        ->assertSee('#1001')
        ->assertDontSee('#1005')
        ->assertNoJavaScriptErrors()
        ->select('select[wire\\:model\\.live="fulfillmentStatusFilter"]', 'fulfilled')
        ->wait(1)
        ->assertSee('#1002')
        ->assertNoJavaScriptErrors()
        ->select('select[wire\\:model\\.live="financialStatusFilter"]', 'all')
        ->select('select[wire\\:model\\.live="fulfillmentStatusFilter"]', 'all')
        ->wait(1)
        ->assertSee('#1001')
        ->assertSee('#1005')
        ->assertNoJavaScriptErrors();
});

test('shows order detail with line items and totals', function (): void {
    adminOrderOpenOrder($this, '#1001')
        ->assertSee('Paid')
        ->assertSee('Unfulfilled')
        ->assertSee('Classic Cotton T-Shirt')
        ->assertSee('Subtotal')
        ->assertSee('Shipping')
        ->assertSee('Tax')
        ->assertSee('Total')
        ->assertNoJavaScriptErrors();
});

test('shows order timeline events', function (): void {
    adminOrderOpenOrder($this, '#1001')
        ->assertSee('Timeline')
        ->assertSee('Order placed')
        ->assertNoJavaScriptErrors();
});

test('can create a fulfillment', function (): void {
    adminOrderCreateFulfillmentInBrowser(adminOrderOpenOrder($this, '#1001'));
});

test('can process a refund', function (): void {


command: sed -n '1,280p' tests/Browser/Storefront/CustomerAccountTest.php

CustomerAccountTest.php

aggregated_output:
<?php

use App\Models\Customer;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Store;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Collection;
use Pest\Browser\Playwright\Playwright;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    Playwright::setHost('shop.test');

    $this->seed(DatabaseSeeder::class);
});

afterEach(function (): void {
    Playwright::setHost(null);
});

function storefrontAccountHost(): array
{
    return ['host' => 'shop.test'];
}

function storefrontAccountLogin(): mixed
{
    return visit('/account/login', storefrontAccountHost())
        ->fill('input[type=email]', 'customer@acme.test')
        ->fill('input[type=password]', 'password')
        ->click('@customer-login-button')
        ->wait(1)
        ->assertPathIs('/account')
        ->assertSee('My Account')
        ->assertSee('John Doe')
        ->assertNoJavaScriptErrors();
}

function storefrontAccountStore(): Store
{
    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
}

function storefrontAccountCustomer(): Customer
{
    $store = storefrontAccountStore();

    return Customer::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('email', 'customer@acme.test')
        ->firstOrFail();
}

/**
 * @return Collection<int, Order>
 */
function storefrontAccountCreateOrders(): Collection
{
    $store = storefrontAccountStore();
    $customer = storefrontAccountCustomer();

    return collect(['#1001', '#1002', '#1004'])
        ->map(function (string $orderNumber, int $index) use ($store, $customer): Order {
            $order = Order::factory()
                ->forCustomer($customer)
                ->paid()
                ->create([
                    'store_id' => $store->getKey(),
                    'customer_id' => $customer->getKey(),
                    'order_number' => $orderNumber,
                    'email' => $customer->email,
                    'subtotal_amount' => 2499,
                    'shipping_amount' => 499,
                    'tax_amount' => 0,
                    'total_amount' => 2998,
                    'placed_at' => now()->subDays($index),
                ]);

            OrderLine::factory()->create([
                'order_id' => $order->getKey(),
                'product_id' => null,
                'variant_id' => null,
                'title_snapshot' => 'Classic Cotton T-Shirt',
                'quantity' => 1,
                'unit_price_amount' => 2499,
                'total_amount' => 2499,
            ]);

            return $order;
        });
}

test('can register a new customer', function (): void {
    visit('/account/register', storefrontAccountHost())
        ->fill('input[wire\\:model="name"]', 'New Customer')
        ->fill('input[wire\\:model="email"]', 'new-customer-e2e@example.com')
        ->fill('input[wire\\:model="password"]', 'password123')
        ->fill('input[wire\\:model="password_confirmation"]', 'password123')
        ->click('@customer-register-button')
        ->wait(1)
        ->assertPathIs('/account')
        ->assertSee('My Account')
        ->assertNoJavaScriptErrors();
});

test('shows validation errors for duplicate email registration', function (): void {
    visit('/account/register', storefrontAccountHost())
        ->fill('input[wire\\:model="name"]', 'Duplicate Customer')
        ->fill('input[wire\\:model="email"]', 'customer@acme.test')
        ->fill('input[wire\\:model="password"]', 'password123')
        ->fill('input[wire\\:model="password_confirmation"]', 'password123')
        ->click('@customer-register-button')
        ->wait(1)
        ->assertPathIs('/account/register')
        ->assertSee('already been taken')
        ->assertNoJavaScriptErrors();
});

test('shows validation errors for mismatched passwords', function (): void {
    visit('/account/register', storefrontAccountHost())
        ->fill('input[wire\\:model="name"]', 'Test Customer')
        ->fill('input[wire\\:model="email"]', 'mismatch@example.com')
        ->fill('input[wire\\:model="password"]', 'password123')
        ->fill('input[wire\\:model="password_confirmation"]', 'different456')
        ->click('@customer-register-button')
        ->wait(1)
        ->assertPathIs('/account/register')
        ->assertSee('password')
        ->assertNoJavaScriptErrors();
});

test('can log in as existing customer', function (): void {
    storefrontAccountLogin();
});

test('shows error for invalid customer credentials', function (): void {
    visit('/account/login', storefrontAccountHost())
        ->fill('input[type=email]', 'customer@acme.test')
        ->fill('input[type=password]', 'wrongpassword')
        ->click('@customer-login-button')
        ->wait(1)
        ->assertPathIs('/account/login')
        ->assertSee('Invalid credentials')
        ->assertNoJavaScriptErrors();
});

test('redirects unauthenticated customers to login', function (): void {
    visit('/account', storefrontAccountHost())
        ->wait(1)
        ->assertPathIs('/account/login')
        ->assertSee('Log in')
        ->assertNoJavaScriptErrors();
});

test('shows order history for logged in customer', function (): void {
    storefrontAccountCreateOrders();

    storefrontAccountLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/orders"]')
        ->wait(1)
        ->assertPathIs('/account/orders')
        ->assertSee('#1001')
        ->assertSee('#1002')
        ->assertSee('#1004')
        ->assertNoJavaScriptErrors();
});

test('shows order detail for customer order', function (): void {
    $orders = storefrontAccountCreateOrders();
    $order = $orders->first();

    storefrontAccountLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/orders"]')
        ->wait(1)
        ->click('a[href$="/account/orders/'.$order->getKey().'"]')
        ->wait(1)
        ->assertPathIs('/account/orders/'.$order->getKey())
        ->assertSee('#1001')
        ->assertSee('Subtotal')
        ->assertSee('Total')
        ->assertNoJavaScriptErrors();
});

test('can view addresses', function (): void {
    storefrontAccountLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/addresses"]')
        ->wait(1)
        ->assertPathIs('/account/addresses')
        ->assertSee('Main Street 1')
        ->assertSee('Berlin')
        ->assertNoJavaScriptErrors();
});

test('can add a new address', function (): void {
    storefrontAccountLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/addresses"]')
        ->wait(1)
        ->click('button:has-text("Add address")')
        ->wait(1)
        ->fill('input[wire\\:model="address.first_name"]', 'John')
        ->fill('input[wire\\:model="address.last_name"]', 'Doe')
        ->fill('input[wire\\:model="address.address1"]', 'New Street 42')
        ->fill('input[wire\\:model="address.city"]', 'Hamburg')
        ->fill('input[wire\\:model="address.postal_code"]', '20095')
        ->select('select[wire\\:model="address.country"]', 'DE')
        ->click('form[wire\\:submit="saveAddress"] button[type="submit"]')
        ->wait(1)
        ->assertSee('Address saved')
        ->assertSee('New Street 42')
        ->assertSee('Hamburg')
        ->assertNoJavaScriptErrors();
});

test('can edit an existing address', function (): void {
    storefrontAccountLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/addresses"]')
        ->wait(1)
        ->click('article:has-text("Main Street 1") button:has-text("Edit")')
        ->wait(1)
        ->fill('input[wire\\:model="address.city"]', 'Frankfurt')
        ->click('form[wire\\:submit="saveAddress"] button[type="submit"]')
        ->wait(1)
        ->assertSee('Address saved')
        ->assertSee('Frankfurt')
        ->assertNoJavaScriptErrors();
});

test('can log out', function (): void {
    storefrontAccountLogin()
        ->click('@customer-logout-button')
        ->wait(1)
        ->assertPathIs('/account/login')
        ->assertSee('Log in')
        ->assertNoJavaScriptErrors();
});


output:
Chunk ID: aac378
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 2052
Output:
<?php

use App\Models\Customer;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Store;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Collection;
use Pest\Browser\Playwright\Playwright;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    Playwright::setHost('shop.test');

    $this->seed(DatabaseSeeder::class);
});

afterEach(function (): void {
    Playwright::setHost(null);
});

function storefrontAccountHost(): array
{
    return ['host' => 'shop.test'];
}

function storefrontAccountLogin(): mixed
{
    return visit('/account/login', storefrontAccountHost())
        ->fill('input[type=email]', 'customer@acme.test')
        ->fill('input[type=password]', 'password')
        ->click('@customer-login-button')
        ->wait(1)
        ->assertPathIs('/account')
        ->assertSee('My Account')
        ->assertSee('John Doe')
        ->assertNoJavaScriptErrors();
}

function storefrontAccountStore(): Store
{
    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
}

function storefrontAccountCustomer(): Customer
{
    $store = storefrontAccountStore();

    return Customer::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('email', 'customer@acme.test')
        ->firstOrFail();
}

/**
 * @return Collection<int, Order>
 */
function storefrontAccountCreateOrders(): Collection
{
    $store = storefrontAccountStore();
    $customer = storefrontAccountCustomer();

    return collect(['#1001', '#1002', '#1004'])
        ->map(function (string $orderNumber, int $index) use ($store, $customer): Order {
            $order = Order::factory()
                ->forCustomer($customer)
                ->paid()
                ->create([
                    'store_id' => $store->getKey(),
                    'customer_id' => $customer->getKey(),
                    'order_number' => $orderNumber,
                    'email' => $customer->email,
                    'subtotal_amount' => 2499,
                    'shipping_amount' => 499,
                    'tax_amount' => 0,
                    'total_amount' => 2998,
                    'placed_at' => now()->subDays($index),
                ]);

            OrderLine::factory()->create([
                'order_id' => $order->getKey(),
                'product_id' => null,
                'variant_id' => null,
                'title_snapshot' => 'Classic Cotton T-Shirt',
                'quantity' => 1,
                'unit_price_amount' => 2499,
                'total_amount' => 2499,
            ]);

            return $order;
        });
}

test('can register a new customer', function (): void {
    visit('/account/register', storefrontAccountHost())
        ->fill('input[wire\\:model="name"]', 'New Customer')
        ->fill('input[wire\\:model="email"]', 'new-customer-e2e@example.com')
        ->fill('input[wire\\:model="password"]', 'password123')
        ->fill('input[wire\\:model="password_confirmation"]', 'password123')
        ->click('@customer-register-button')
        ->wait(1)
        ->assertPathIs('/account')
        ->assertSee('My Account')
        ->assertNoJavaScriptErrors();
});

test('shows validation errors for duplicate email registration', function (): void {
    visit('/account/register', storefrontAccountHost())
        ->fill('input[wire\\:model="name"]', 'Duplicate Customer')
        ->fill('input[wire\\:model="email"]', 'customer@acme.test')
        ->fill('input[wire\\:model="password"]', 'password123')
        ->fill('input[wire\\:model="password_confirmation"]', 'password123')
        ->click('@customer-register-button')
        ->wait(1)
        ->assertPathIs('/account/register')
        ->assertSee('already been taken')
        ->assertNoJavaScriptErrors();
});

test('shows validation errors for mismatched passwords', function (): void {
    visit('/account/register', storefrontAccountHost())
        ->fill('input[wire\\:model="name"]', 'Test Customer')
        ->fill('input[wire\\:model="email"]', 'mismatch@example.com')
        ->fill('input[wire\\:model="password"]', 'password123')
        ->fill('input[wire\\:model="password_confirmation"]', 'different456')
        ->click('@customer-register-button')
        ->wait(1)
        ->assertPathIs('/account/register')
        ->assertSee('password')
        ->assertNoJavaScriptErrors();
});

test('can log in as existing customer', function (): void {
    storefrontAccountLogin();
});

test('shows error for invalid customer credentials', function (): void {
    visit('/account/login', storefrontAccountHost())
        ->fill('input[type=email]', 'customer@acme.test')
        ->fill('input[type=password]', 'wrongpassword')
        ->click('@customer-login-button')
        ->wait(1)
        ->assertPathIs('/account/login')
        ->assertSee('Invalid credentials')
        ->assertNoJavaScriptErrors();
});

test('redirects unauthenticated customers to login', function (): void {
    visit('/account', storefrontAccountHost())
        ->wait(1)
        ->assertPathIs('/account/login')
        ->assertSee('Log in')
        ->assertNoJavaScriptErrors();
});

test('shows order history for logged in customer', function (): void {
    storefrontAccountCreateOrders();

    storefrontAccountLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/orders"]')
        ->wait(1)
        ->assertPathIs('/account/orders')
        ->assertSee('#1001')
        ->assertSee('#1002')
        ->assertSee('#1004')
        ->assertNoJavaScriptErrors();
});

test('shows order detail for customer order', function (): void {
    $orders = storefrontAccountCreateOrders();
    $order = $orders->first();

    storefrontAccountLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/orders"]')
        ->wait(1)
        ->click('a[href$="/account/orders/'.$order->getKey().'"]')
        ->wait(1)
        ->assertPathIs('/account/orders/'.$order->getKey())
        ->assertSee('#1001')
        ->assertSee('Subtotal')
        ->assertSee('Total')
        ->assertNoJavaScriptErrors();
});

test('can view addresses', function (): void {
    storefrontAccountLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/addresses"]')
        ->wait(1)
        ->assertPathIs('/account/addresses')
        ->assertSee('Main Street 1')
        ->assertSee('Berlin')
        ->assertNoJavaScriptErrors();
});

test('can add a new address', function (): void {
    storefrontAccountLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/addresses"]')
        ->wait(1)
        ->click('button:has-text("Add address")')
        ->wait(1)
        ->fill('input[wire\\:model="address.first_name"]', 'John')
        ->fill('input[wire\\:model="address.last_name"]', 'Doe')
        ->fill('input[wire\\:model="address.address1"]', 'New Street 42')
        ->fill('input[wire\\:model="address.city"]', 'Hamburg')
        ->fill('input[wire\\:model="address.postal_code"]', '20095')
        ->select('select[wire\\:model="address.country"]', 'DE')
        ->click('form[wire\\:submit="saveAddress"] button[type="submit"]')
        ->wait(1)
        ->assertSee('Address saved')
        ->assertSee('New Street 42')
        ->assertSee('Hamburg')
        ->assertNoJavaScriptErrors();
});

test('can edit an existing address', function (): void {
    storefrontAccountLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/addresses"]')
        ->wait(1)
        ->click('article:has-text("Main Street 1") button:has-text("Edit")')
        ->wait(1)
        ->fill('input[wire\\:model="address.city"]', 'Frankfurt')
        ->click('form[wire\\:submit="saveAddress"] button[type="submit"]')
        ->wait(1)
        ->assertSee('Address saved')
        ->assertSee('Frankfurt')
        ->assertNoJavaScriptErrors();
});

test('can log out', function (): void {
    storefrontAccountLogin()
        ->click('@customer-logout-button')
        ->wait(1)
        ->assertPathIs('/account/login')
        ->assertSee('Log in')
        ->assertNoJavaScriptErrors();
});


cmd: sed -n '280,560p' tests/Browser/Admin/OrderManagementTest.php


cmd: sed -n '1,260p' tests/Browser/Admin/CustomerManagementTest.php


cmd: sed -n '1,320p' tests/Browser/Storefront/TenantIsolationTest.php


cmd: sed -n '1,280p' tests/Feature/Admin/OrderManagementTest.php


cmd: sed -n '1,260p' tests/Feature/Admin/CustomerManagementTest.php


command: sed -n '280,560p' tests/Browser/Admin/OrderManagementTest.php

aggregated_output:
test('can process a refund', function (): void {
    adminOrderOpenOrder($this, '#1001')
        ->click('button[data-test="refund-modal-button"]')
        ->wait(1)
        ->fill('input[wire\\:model="refundAmount"]', '10.00')
        ->fill('textarea[wire\\:model="refundReason"]', 'Customer requested partial refund')
        ->click('button[data-test="refund-submit-button"]')
        ->wait(1)
        ->assertSee('Refund processed')
        ->assertSee('Partially Refunded')
        ->assertNoJavaScriptErrors();
});

test('shows customer information in order detail', function (): void {
    adminOrderOpenOrder($this, '#1001')
        ->assertSee('customer@acme.test')
        ->assertNoJavaScriptErrors();
});

test('can confirm bank transfer payment', function (): void {
    adminOrderOpenOrder($this, '#1005')
        ->assertSee('Pending')
        ->assertPresent('button[data-test="confirm-payment-button"]')
        ->click('button[data-test="confirm-payment-button"]')
        ->wait(1)
        ->assertSee('Payment confirmed')
        ->assertSee('Paid')
        ->assertDontSee('Confirm payment')
        ->assertNoJavaScriptErrors();
});

test('shows fulfillment guard for unpaid order', function (): void {
    adminOrderOpenOrder($this, '#1005')
        ->assertSee('Cannot create fulfillment')
        ->assertSee('Payment must be confirmed before items can be fulfilled')
        ->assertScript('document.querySelector("button[data-test=\"fulfillment-modal-button\"]") === null')
        ->assertNoJavaScriptErrors();
});

test('can mark fulfillment as shipped', function (): void {
    $page = adminOrderCreateFulfillmentInBrowser(adminOrderOpenOrder($this, '#1001'));

    $page->click('button[data-test="mark-fulfillment-shipped-button"]')
        ->wait(1)
        ->assertSee('Shipped')
        ->assertNoJavaScriptErrors();
});

test('can mark fulfillment as delivered', function (): void {
    $page = adminOrderCreateFulfillmentInBrowser(adminOrderOpenOrder($this, '#1001'));

    $page->click('button[data-test="mark-fulfillment-shipped-button"]')
        ->wait(1)
        ->click('button[data-test="mark-fulfillment-delivered-button"]')
        ->wait(1)
        ->assertSee('Delivered')
        ->assertSee('Fulfilled')
        ->assertNoJavaScriptErrors();
});


command: sed -n '1,260p' tests/Browser/Admin/CustomerManagementTest.php

aggregated_output:
<?php

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentMethod;
use App\Enums\PaymentStatus;
use App\Models\Customer;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Payment;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Pest\Browser\Playwright\Playwright;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    Playwright::setHost('shop.test');

    $this->seed(DatabaseSeeder::class);
});

afterEach(function (): void {
    Playwright::setHost(null);
});

function adminCustomerBrowserHost(): array
{
    return ['host' => 'shop.test'];
}

function adminCustomerBrowserAuthenticate(mixed $testCase): Store
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();

    $testCase->actingAs($user);
    $testCase->withSession(['current_store_id' => $store->getKey()]);

    return $store;
}

function adminCustomerBrowserCustomer(Store $store): Customer
{
    return Customer::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('email', 'customer@acme.test')
        ->firstOrFail();
}

function adminCustomerBrowserCreateOrder(Store $store, Customer $customer): Order
{
    $product = Product::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('handle', 'classic-cotton-t-shirt')
        ->firstOrFail();
    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->firstOrFail();
    $shipping = 499;
    $total = $variant->price_amount + $shipping;

    $order = Order::factory()->create([
        'store_id' => $store->getKey(),
        'customer_id' => $customer->getKey(),
        'order_number' => '#1001',
        'payment_method' => PaymentMethod::CreditCard,
        'status' => OrderStatus::Paid,
        'financial_status' => FinancialStatus::Paid,
        'fulfillment_status' => FulfillmentStatus::Unfulfilled,
        'currency' => $store->default_currency,
        'subtotal_amount' => $variant->price_amount,
        'discount_amount' => 0,
        'shipping_amount' => $shipping,
        'tax_amount' => 0,
        'total_amount' => $total,
        'email' => $customer->email,
        'placed_at' => now()->subDay(),
    ]);

    OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $product->getKey(),
        'variant_id' => $variant->getKey(),
        'title_snapshot' => 'Classic Cotton T-Shirt',
        'sku_snapshot' => $variant->sku,
        'quantity' => 1,
        'unit_price_amount' => $variant->price_amount,
        'total_amount' => $variant->price_amount,
    ]);

    Payment::factory()->create([
        'order_id' => $order->getKey(),
        'method' => PaymentMethod::CreditCard,
        'status' => PaymentStatus::Captured,
        'amount' => $total,
        'currency' => $store->default_currency,
    ]);

    return $order->refresh();
}

function adminCustomerBrowserOpenCustomers(mixed $testCase): mixed
{
    adminCustomerBrowserAuthenticate($testCase);

    return visit('/admin/customers', adminCustomerBrowserHost())
        ->wait(1)
        ->assertPathIs('/admin/customers')
        ->assertSee('Customers')
        ->assertNoJavaScriptErrors();
}

function adminCustomerBrowserOpenCustomer(mixed $testCase): mixed
{
    return adminCustomerBrowserOpenCustomers($testCase)
        ->assertSee('John Doe')
        ->click('a:has-text("John Doe")')
        ->wait(1)
        ->assertPathContains('/admin/customers/')
        ->assertNoJavaScriptErrors();
}

test('shows the customer list', function (): void {
    adminCustomerBrowserOpenCustomers($this)
        ->assertSee('customer@acme.test')
        ->assertSee('John Doe')
        ->assertNoJavaScriptErrors();
});

test('shows customer detail with order history', function (): void {
    $store = adminCustomerBrowserAuthenticate($this);
    $customer = adminCustomerBrowserCustomer($store);
    adminCustomerBrowserCreateOrder($store, $customer);

    visit('/admin/customers', adminCustomerBrowserHost())
        ->wait(1)
        ->assertPathIs('/admin/customers')
        ->click('a:has-text("John Doe")')
        ->wait(1)
        ->assertPathContains('/admin/customers/')
        ->assertSee('John Doe')
        ->assertSee('customer@acme.test')
        ->assertSee('Order history')
        ->assertSee('#1001')
        ->assertNoJavaScriptErrors();
});

test('shows customer addresses', function (): void {
    adminCustomerBrowserOpenCustomer($this)
        ->assertSee('John Doe')
        ->assertSee('Addresses')
        ->assertSee('Home')
        ->assertNoJavaScriptErrors();
});


command: sed -n '1,320p' tests/Browser/Storefront/TenantIsolationTest.php

aggregated_output:
<?php

use App\Models\Customer;
use App\Models\Order;
use App\Models\Store;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Pest\Browser\Playwright\Playwright;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    Playwright::setHost('acme-fashion.test');

    $this->seed(DatabaseSeeder::class);
});

afterEach(function (): void {
    Playwright::setHost(null);
});

function tenantIsolationHost(): array
{
    return ['host' => 'acme-fashion.test'];
}

function tenantIsolationStore(string $handle): Store
{
    return Store::query()->where('handle', $handle)->firstOrFail();
}

function tenantIsolationFashionCustomer(): Customer
{
    $store = tenantIsolationStore('acme-fashion');

    return Customer::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('email', 'customer@acme.test')
        ->firstOrFail();
}

function tenantIsolationCreateOrders(): void
{
    $fashionStore = tenantIsolationStore('acme-fashion');
    $electronicsStore = tenantIsolationStore('acme-electronics');
    $fashionCustomer = tenantIsolationFashionCustomer();
    $electronicsCustomer = Customer::factory()->create([
        'store_id' => $electronicsStore->getKey(),
        'email' => 'customer@acme.test',
        'password' => 'password',
        'name' => 'Electronics Customer',
    ]);

    foreach (['#1001', '#1002', '#1004'] as $orderNumber) {
        Order::factory()
            ->forCustomer($fashionCustomer)
            ->paid()
            ->create([
                'store_id' => $fashionStore->getKey(),
                'customer_id' => $fashionCustomer->getKey(),
                'order_number' => $orderNumber,
                'email' => $fashionCustomer->email,
            ]);
    }

    Order::factory()
        ->forCustomer($electronicsCustomer)
        ->paid()
        ->create([
            'store_id' => $electronicsStore->getKey(),
            'customer_id' => $electronicsCustomer->getKey(),
            'order_number' => '#2001',
            'email' => $electronicsCustomer->email,
        ]);
}

function tenantIsolationAdminLogin(): mixed
{
    return visit('/admin/login', tenantIsolationHost())
        ->fill('input[type=email]', 'admin@acme.test')
        ->fill('input[type=password]', 'password')
        ->click('@admin-login-button')
        ->wait(1)
        ->assertPathIs('/admin')
        ->assertSee('Dashboard')
        ->assertNoJavaScriptErrors();
}

function tenantIsolationCustomerLogin(): mixed
{
    return visit('/account/login', tenantIsolationHost())
        ->fill('input[type=email]', 'customer@acme.test')
        ->fill('input[type=password]', 'password')
        ->click('@customer-login-button')
        ->wait(1)
        ->assertPathIs('/account')
        ->assertSee('My Account')
        ->assertSee('John Doe')
        ->assertNoJavaScriptErrors();
}

test('storefront only shows current store products', function (): void {
    visit('/', tenantIsolationHost())
        ->assertSee('Acme Fashion')
        ->assertSee('Classic Cotton T-Shirt')
        ->assertDontSee('Pro Laptop 15')
        ->assertDontSee('Wireless Headphones')
        ->assertNoJavaScriptErrors();
});

test('storefront collections only contain current store products', function (): void {
    visit('/collections/t-shirts', tenantIsolationHost())
        ->assertSee('T-Shirts')
        ->assertSee('Classic Cotton T-Shirt')
        ->assertDontSee('Pro Laptop 15')
        ->assertDontSee('Wireless Headphones')
        ->assertNoJavaScriptErrors();
});

test('admin cannot see other store products or orders', function (): void {
    tenantIsolationCreateOrders();

    tenantIsolationAdminLogin()
        ->click('a[href$="/admin/products"]')
        ->wait(1)
        ->assertPathIs('/admin/products')
        ->assertSee('Products')
        ->assertDontSee('Pro Laptop 15')
        ->assertDontSee('Wireless Headphones')
        ->click('a[href$="/admin/orders"]')
        ->wait(1)
        ->assertPathIs('/admin/orders')
        ->assertSee('#1001')
        ->assertDontSee('#2001')
        ->assertNoJavaScriptErrors();
});

test('search only returns current store products', function (): void {
    visit('/search?q=cotton', tenantIsolationHost())
        ->assertSee('Classic Cotton T-Shirt')
        ->assertDontSee('Pro Laptop 15')
        ->assertNoJavaScriptErrors();

    visit('/search?q=laptop', tenantIsolationHost())
        ->assertDontSee('Pro Laptop 15')
        ->assertSee('No products found')
        ->assertNoJavaScriptErrors();
});

test('customer accounts are scoped to their store', function (): void {
    tenantIsolationCreateOrders();

    tenantIsolationCustomerLogin()
        ->click('nav[aria-label="Account navigation"] a[href$="/account/orders"]')
        ->wait(1)
        ->assertPathIs('/account/orders')
        ->assertSee('#1001')
        ->assertSee('#1002')
        ->assertSee('#1004')
        ->assertDontSee('#2001')
        ->assertNoJavaScriptErrors();
});


command: sed -n '1,280p' tests/Feature/Admin/OrderManagementTest.php

aggregated_output:
<?php

use App\Enums\FinancialStatus;
use App\Enums\FulfillmentShipmentStatus;
use App\Enums\FulfillmentStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentMethod;
use App\Enums\PaymentStatus;
use App\Livewire\Admin\Orders\Index as AdminOrdersIndex;
use App\Livewire\Admin\Orders\Show as AdminOrderShow;
use App\Models\Fulfillment;
use App\Models\InventoryItem;
use App\Models\Order;
use App\Models\OrderLine;
use App\Models\Payment;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

beforeEach(function () {
    $this->withoutVite();
    $this->seed(DatabaseSeeder::class);
});

function adminOrderManagementStore(): Store
{
    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
    app()->instance('current_store', $store);

    return $store;
}

function adminOrderManagementUser(): User
{
    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
}

/**
 * @return array{0: Order, 1: OrderLine, 2: ProductVariant}
 */
function adminOrderManagementOrder(Store $store, array $orderAttributes = [], int $quantity = 2, int $unitPrice = 2500): array
{
    $product = Product::factory()
        ->withDefaultVariant($unitPrice)
        ->create(['store_id' => $store->getKey()]);
    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->firstOrFail();

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update([
            'quantity_on_hand' => 10,
            'quantity_reserved' => 0,
        ]);

    $total = $quantity * $unitPrice;
    $order = Order::factory()->paid()->create(array_merge([
        'store_id' => $store->getKey(),
        'subtotal_amount' => $total,
        'shipping_amount' => 0,
        'tax_amount' => 0,
        'total_amount' => $total,
        'email' => 'buyer@example.test',
    ], $orderAttributes));
    $line = OrderLine::factory()->create([
        'order_id' => $order->getKey(),
        'product_id' => $product->getKey(),
        'variant_id' => $variant->getKey(),
        'title_snapshot' => 'Admin Test Product',
        'sku_snapshot' => 'ADMIN-TEST-001',
        'quantity' => $quantity,
        'unit_price_amount' => $unitPrice,
        'total_amount' => $total,
    ]);

    Payment::factory()->create([
        'order_id' => $order->getKey(),
        'method' => $order->payment_method,
        'status' => $order->financial_status === FinancialStatus::Pending ? PaymentStatus::Pending : PaymentStatus::Captured,
        'amount' => $total,
        'currency' => $order->currency,
    ]);

    return [$order, $line, $variant];
}

test('admin order routes require authentication and render scoped orders', function () {
    $store = adminOrderManagementStore();
    [$order] = adminOrderManagementOrder($store, [
        'order_number' => '#7001',
        'email' => 'alpha@example.test',
    ]);

    $otherStore = Store::factory()->create();
    adminOrderManagementOrder($otherStore, [
        'order_number' => '#9001',
        'email' => 'other@example.test',
    ]);

    $this->get('/admin/orders')->assertRedirect('/admin/login');

    $user = adminOrderManagementUser();

    $this->actingAs($user)
        ->get('/admin/orders')
        ->assertSuccessful()
        ->assertSee('#7001')
        ->assertDontSee('#9001');

    $this->actingAs($user)
        ->get('/admin/orders/'.$order->getKey())
        ->assertSuccessful()
        ->assertSee('#7001')
        ->assertSee('Admin Test Product');
});

test('admin order index filters by search and status dimensions', function () {
    $store = adminOrderManagementStore();
    $user = adminOrderManagementUser();
    adminOrderManagementOrder($store, [
        'order_number' => '#7001',
        'email' => 'alpha@example.test',
    ]);
    adminOrderManagementOrder($store, [
        'order_number' => '#7002',
        'email' => 'bravo@example.test',
        'status' => OrderStatus::Pending,
        'financial_status' => FinancialStatus::Pending,
        'payment_method' => PaymentMethod::BankTransfer,
    ]);

    Livewire::actingAs($user)
        ->test(AdminOrdersIndex::class)
        ->assertSee('#7001')
        ->assertSee('#7002')
        ->set('search', 'alpha')
        ->assertSee('#7001')
        ->assertDontSee('#7002')
        ->set('search', '')
        ->set('financialStatusFilter', 'pending')
        ->assertSee('#7002')
        ->assertDontSee('#7001');
});

test('admin order detail confirms bank transfer payments', function () {
    $store = adminOrderManagementStore();
    $user = adminOrderManagementUser();
    [$order, $line, $variant] = adminOrderManagementOrder($store, [
        'payment_method' => PaymentMethod::BankTransfer,
        'status' => OrderStatus::Pending,
        'financial_status' => FinancialStatus::Pending,
    ]);

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update(['quantity_reserved' => $line->quantity]);

    Livewire::actingAs($user)
        ->test(AdminOrderShow::class, ['order' => $order])
        ->call('confirmBankTransferPayment')
        ->assertHasNoErrors();

    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect($order->refresh()->status)->toBe(OrderStatus::Paid)
        ->and($order->financial_status)->toBe(FinancialStatus::Paid)
        ->and($order->payments()->first()?->status)->toBe(PaymentStatus::Captured)
        ->and($inventory->quantity_on_hand)->toBe(8)
        ->and($inventory->quantity_reserved)->toBe(0);
});

test('admin order detail processes refunds and fulfillment transitions', function () {
    $store = adminOrderManagementStore();
    $user = adminOrderManagementUser();
    [$order, $line] = adminOrderManagementOrder($store, quantity: 2, unitPrice: 2500);

    Livewire::actingAs($user)
        ->test(AdminOrderShow::class, ['order' => $order])
        ->set('refundAmount', '10.00')
        ->set('refundReason', 'Customer return')
        ->call('processRefund')
        ->assertHasNoErrors();

    expect($order->refresh()->financial_status)->toBe(FinancialStatus::PartiallyRefunded)
        ->and($order->refunds()->first()?->amount)->toBe(1000);

    Livewire::actingAs($user)
        ->test(AdminOrderShow::class, ['order' => $order->refresh()])
        ->set("fulfillmentLineQuantities.{$line->getKey()}", 1)
        ->set('trackingCompany', 'DHL')
        ->set('trackingNumber', 'DHL123')
        ->call('createFulfillment')
        ->assertHasNoErrors();

    $fulfillment = Fulfillment::query()->where('order_id', $order->getKey())->firstOrFail();

    expect($order->refresh()->fulfillment_status)->toBe(FulfillmentStatus::Partial)
        ->and($fulfillment->lines()->first()?->quantity)->toBe(1);

    Livewire::actingAs($user)
        ->test(AdminOrderShow::class, ['order' => $order->refresh()])
        ->call('markFulfillmentShipped', $fulfillment->getKey())
        ->call('markFulfillmentDelivered', $fulfillment->getKey())
        ->assertHasNoErrors();

    expect($fulfillment->refresh()->status)->toBe(FulfillmentShipmentStatus::Delivered)
        ->and($fulfillment->delivered_at)->not->toBeNull();
});

test('admin order detail rejects orders from another store', function () {
    $store = adminOrderManagementStore();
    $otherStore = Store::factory()->create();
    $user = adminOrderManagementUser();
    [$otherOrder] = adminOrderManagementOrder($otherStore, [
        'order_number' => '#9001',
    ]);

    app()->instance('current_store', $store);

    Livewire::actingAs($user)
        ->test(AdminOrderShow::class, ['order' => $otherOrder])
        ->assertStatus(404);
});