Files
fotospiel-app/tests/Feature/Console/CouponExportCommandTest.php

49 lines
1.3 KiB
PHP

<?php
namespace Tests\Feature\Console;
use App\Models\Coupon;
use App\Models\CouponRedemption;
use App\Models\Package;
use App\Models\Tenant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class CouponExportCommandTest extends TestCase
{
use RefreshDatabase;
public function test_export_command_creates_csv(): void
{
Storage::fake('local');
$coupon = Coupon::factory()->create([
'code' => 'FLASH20',
]);
$package = Package::factory()->create();
$tenant = Tenant::factory()->create();
CouponRedemption::factory()->create([
'coupon_id' => $coupon->id,
'package_id' => $package->id,
'tenant_id' => $tenant->id,
'status' => CouponRedemption::STATUS_SUCCESS,
'amount_discounted' => 25,
'redeemed_at' => now(),
]);
$path = 'reports/test-coupons.csv';
$this->artisan('coupons:export', [
'--days' => 7,
'--path' => $path,
])->assertExitCode(0);
Storage::disk('local')->assertExists($path);
$contents = Storage::disk('local')->get($path);
$this->assertStringContainsString('FLASH20', $contents);
}
}