create([ 'email' => 'eligible@example.com', 'registration_type' => RegistrationType::ApiUser->value, 'is_active' => true, ]); $needsReview = User::factory()->create([ 'email' => 'review@example.com', 'registration_type' => RegistrationType::ApiUser->value, 'is_active' => true, ]); $blockedInactive = User::factory()->create([ 'email' => 'inactive@example.com', 'registration_type' => RegistrationType::ApiUser->value, 'is_active' => false, ]); $blockedUnpaid = User::factory()->create([ 'email' => 'unpaid@example.com', 'registration_type' => RegistrationType::ApiUser->value, 'is_active' => true, ]); createLegacyApiCustomerInvoice($eligible, 1001, 'paid', now()->subMonth()); createLegacyApiCustomerInvoice($blockedInactive, 1002, 'paid', now()->subMonth()); createLegacyApiCustomerInvoice($blockedUnpaid, 1003, 'paid', now()->subMonths(2)); createLegacyApiCustomerInvoice($blockedUnpaid, 1004, 'reminder', now()->subMonth()); $report = app(LegacyApiCustomerReporter::class)->report(); expect($report['summary'])->toMatchArray([ 'total_candidates' => 4, 'eligible' => 1, 'needs_review' => 1, 'blocked' => 2, ]); $customers = collect($report['customers'])->keyBy('email'); expect($customers['eligible@example.com']['classification'])->toBe('eligible') ->and($customers['review@example.com']['classification'])->toBe('needs_review') ->and($customers['inactive@example.com']['classification'])->toBe('blocked') ->and($customers['unpaid@example.com']['classification'])->toBe('blocked') ->and($customers['unpaid@example.com']['latest_legacy_invoice']['status'])->toBe('reminder'); }); test('legacy api customers report command renders summary', function () { /** @var TestCase $this */ $user = User::factory()->create([ 'email' => 'api-customer@example.com', 'registration_type' => RegistrationType::ApiUser->value, ]); createLegacyApiCustomerInvoice($user, 2001, 'paid', now()); $this->artisan('api:legacy-customers-report', ['--no-report' => true]) ->expectsOutput('Legacy-API-Kundenreport') ->expectsOutput('Kandidaten: 1') ->expectsOutput('Freigabefähig: 1') ->assertSuccessful(); }); function createLegacyApiCustomerInvoice(User $user, int $legacyId, string $status, DateTimeInterface $invoiceDate): LegacyInvoice { return LegacyInvoice::query()->create([ 'legacy_portal' => 'businessportal24', 'legacy_id' => $legacyId, 'user_id' => $user->id, 'legacy_user_id' => $user->legacy_id ?? $user->id, 'number' => "LEG-{$legacyId}", 'total_cents' => 4900, 'status' => $status, 'invoice_date' => $invoiceDate, 'paid_at' => $status === 'paid' ? $invoiceDate : null, 'imported_at' => now(), ]); }