'lcs-'.uniqid('', true).'@example.com', 'password' => bcrypt('secret'), 'lang' => 'de', 'm_level' => 1, 'payment_account' => now()->addYear(), ]); } it('liefert die gespeicherte Provision, wenn der Monats-Batch bereits gelaufen ist', function (): void { $user = lcsMakeUser(); UserBusiness::forceCreate([ 'user_id' => $user->id, 'month' => 6, 'year' => 2026, 'version' => 2, 'commission_pp_total' => 120.50, 'commission_shop_sales' => 30.25, 'commission_growth_total' => 10.00, ]); $commission = app(LiveCommissionService::class)->commission($user, 6, 2026); expect($commission['total'])->toBe(160.75) ->and($commission['pp'])->toBe(120.5) ->and($commission['shop'])->toBe(30.25) ->and($commission['growth'])->toBe(10.0) ->and($commission['is_live'])->toBeFalse(); }); it('berechnet den Live-Snapshot ueber den gemeinsamen Lauf und cached ihn', function (): void { $user = lcsMakeUser(); $snapshot = app(LiveCommissionService::class)->snapshot($user, 7, 2026); expect($snapshot['is_live'])->toBeTrue() ->and($snapshot['failed'])->toBeFalse() ->and($snapshot['payline_points'])->toBe(0.0) ->and($snapshot['paylines'])->toBe(0) ->and(Cache::has("live_business_v3_{$user->id}_7_2026"))->toBeTrue(); }); it('faellt bei fehlschlagender Live-Berechnung auf Null-Werte zurueck und cached den Fehler nicht', function (): void { $user = lcsMakeUser(); // Deterministischer Fehler: ohne user_levels bricht der Baum-Lauf ab Schema::drop('user_levels'); $commission = app(LiveCommissionService::class)->commission($user, 7, 2026); expect($commission['total'])->toBe(0.0) ->and($commission['is_live'])->toBeTrue() ->and(Cache::has("live_business_v3_{$user->id}_7_2026"))->toBeFalse(); }); it('cached die Live-Provision fuer Folgeaufrufe', function (): void { $user = lcsMakeUser(); Cache::put( "live_business_v3_{$user->id}_7_2026", ['payline_points' => 12.5, 'paylines' => 2, 'pp' => 99.0, 'shop' => 0.0, 'growth' => 0.0, 'is_live' => true, 'failed' => false], now()->addHour() ); $commission = app(LiveCommissionService::class)->commission($user, 7, 2026); $snapshot = app(LiveCommissionService::class)->snapshot($user, 7, 2026); expect($commission['total'])->toBe(99.0) ->and($commission['is_live'])->toBeTrue() ->and($snapshot['payline_points'])->toBe(12.5) ->and($snapshot['paylines'])->toBe(2); }); it('liefert Payline-Punkte und Payline-Tiefe aus dem UserBusiness-Snapshot', function (): void { $user = lcsMakeUser(); UserBusiness::forceCreate([ 'user_id' => $user->id, 'month' => 6, 'year' => 2026, 'version' => 2, 'payline_points' => 350.5, 'qual_user_level' => ['paylines' => 3], 'commission_pp_total' => 10.0, 'commission_shop_sales' => 0.0, 'commission_growth_total' => 0.0, ]); $snapshot = app(LiveCommissionService::class)->snapshot($user, 6, 2026); expect($snapshot['payline_points'])->toBe(350.5) ->and($snapshot['paylines'])->toBe(3) ->and($snapshot['is_live'])->toBeFalse(); }); it('rendert die Provisions-Kachel auf der Monatsstatistik-Card', function (): void { URL::resolveMissingNamedRoutesUsing(fn (string $name, $parameters = []) => '/'.$name); $html = view('dashboard._statistics', [ 'monthlyStats' => [ 'month' => 7, 'year' => 2026, 'customer_points' => 100.0, 'team_payline_points' => 400.0, 'payline_is_live' => true, 'payline_forecast' => null, 'commission' => ['total' => 160.75, 'pp' => 120.5, 'shop' => 30.25, 'growth' => 10.0, 'is_live' => true], 'direct_new_partners' => 0, 'team_total_abos' => 0, 'team_partner_abos' => 0, 'team_partner_abos_new' => 0, 'team_customer_abos' => 0, 'team_customer_abos_new' => 0, 'shop_1000' => 0, 'new_partners' => 0, 'own_abos' => 0, 'own_abos_new' => 0, 'own_customer_abos' => 0, 'own_customer_abos_new' => 0, ], ])->render(); expect($html) ->toContain(__('home.commission_today')) ->toContain('160,75 €'); }); it('reicht Level- und Quali-Daten im Snapshot durch (N1/N4)', function (): void { foreach (['sales_volume_points_KP_sum' => 'float', 'payline_points_qual_kp' => 'float', 'qual_user_level_next' => 'text'] as $column => $type) { if (! Schema::connection('sqlite')->hasColumn('user_businesses', $column)) { Schema::connection('sqlite')->table('user_businesses', function ($table) use ($column, $type) { $type === 'float' ? $table->float($column)->nullable() : $table->text($column)->nullable(); }); } } $user = lcsMakeUser(); UserBusiness::forceCreate([ 'user_id' => $user->id, 'month' => 6, 'year' => 2026, 'version' => 2, 'payline_points' => 900.0, 'payline_points_qual_kp' => 950.0, 'sales_volume_points_KP_sum' => 300.0, 'qual_user_level' => ['name' => 'Gold', 'paylines' => 3], 'qual_user_level_next' => ['name' => 'Diamant', 'qual_pp' => 2000, 'qual_kp' => 600], ]); $snapshot = app(LiveCommissionService::class)->snapshot($user, 6, 2026); expect($snapshot['qual_level']['name'])->toBe('Gold') ->and($snapshot['next_level']['name'])->toBe('Diamant') ->and($snapshot['payline_points_qual_kp'])->toBe(950.0) ->and($snapshot['personal_points'])->toBe(300.0) ->and($snapshot['paylines'])->toBe(3); }); it('reicht das Fehlerkennzeichen der Provisionsberechnung durch', function (): void { // A19: Eine fehlgeschlagene Live-Berechnung liefert Ersatzwerte, aus denen sich // 0,00 EUR ergibt. Ohne das Kennzeichen ist das in der Oberflaeche nicht von // einem echten Nullmonat zu unterscheiden. $user = lcsMakeUser(); $service = Mockery::mock(LiveCommissionService::class)->makePartial(); $service->shouldReceive('snapshot')->once()->andReturn([ 'payline_points' => 0.0, 'paylines' => 0, 'pp' => 0.0, 'shop' => 0.0, 'growth' => 0.0, 'is_live' => true, 'failed' => true, 'qual_level' => null, 'next_level' => null, 'payline_points_qual_kp' => 0.0, 'personal_points' => 0.0, ]); $commission = $service->commission($user, 7, 2026); expect($commission['failed'])->toBeTrue() ->and($commission['total'])->toBe(0.0); }); it('meldet eine echte Nullprovision ohne Fehlerkennzeichen', function (): void { $user = lcsMakeUser(); UserBusiness::forceCreate([ 'user_id' => $user->id, 'month' => 6, 'year' => 2026, 'version' => 2, 'commission_pp_total' => 0, 'commission_shop_sales' => 0, 'commission_growth_total' => 0, ]); $commission = app(LiveCommissionService::class)->commission($user, 6, 2026); expect($commission['total'])->toBe(0.0) ->and($commission['failed'])->toBeFalse(); }); it('zeigt eine nicht verfuegbare Provisionsberechnung statt 0,00 Euro', function (): void { URL::resolveMissingNamedRoutesUsing(fn (string $name, $parameters = []) => '/'.$name); $html = view('dashboard._statistics', [ 'monthlyStats' => [ 'month' => 7, 'year' => 2026, 'customer_points' => 0.0, 'team_payline_points' => 0.0, 'payline_is_live' => true, 'payline_forecast' => null, 'commission' => ['total' => 0.0, 'pp' => 0.0, 'shop' => 0.0, 'growth' => 0.0, 'is_live' => true, 'failed' => true], 'direct_new_partners' => 0, 'team_total_abos' => 0, 'team_partner_abos' => 0, 'team_partner_abos_new' => 0, 'team_customer_abos' => 0, 'team_customer_abos_new' => 0, 'shop_1000' => 0, 'new_partners' => 0, 'own_abos' => 0, 'own_abos_new' => 0, 'own_customer_abos' => 0, 'own_customer_abos_new' => 0, ], ])->render(); expect($html) ->toContain(__('home.commission_unavailable')) ->not->toContain('0,00 €'); });