<?php

use Modules\Payment\Filament\Widgets\RevenueChartWidget;
use Modules\Payment\Models\Payment;

test('it sums completed payment amounts per day over the last 30 days', function () {
    Payment::factory()->completed()->create(['amount' => 10000, 'completed_at' => today()]);
    Payment::factory()->completed()->create(['amount' => 5000, 'completed_at' => today()]);
    Payment::factory()->create(['amount' => 99999, 'completed_at' => null]); // pending, excluded
    Payment::factory()->completed()->create(['amount' => 77777, 'completed_at' => today()->subDays(40)]); // outside window

    $widget = new RevenueChartWidget;
    $getData = (new ReflectionMethod($widget, 'getData'));
    $getData->setAccessible(true);
    $data = $getData->invoke($widget);

    expect($data['labels'])->toHaveCount(30)
        ->and(array_sum($data['datasets'][0]['data']))->toBe(15000.0);
});
