<?php

use App\Filament\Admin\Resources\PaymentResource\Pages\CreatePayment;
use App\Models\Customer;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

it('can create a payment', function () {
    $user = User::factory(['is_admin' => true])->create();
    $this->actingAs($user);
    $customer = Customer::factory()->create();

    $formData = [
        'customer_id' => $customer->id,
        'amount'      => 500,
    ];

    $this->livewire(CreatePayment::class)
        ->fillForm($formData)
        ->call('create')
        ->assertHasNoErrors();

    $this->assertDatabaseHas('payments', [
        'customer_id' => $formData['customer_id'],
        'amount'      => $formData['amount'],
    ]);
});
