Ergebnis des Senior-Reviews über dev/2026-07-22 (Konzept 22.07., Feedback 24.07.,
Plan 19.08.). Rechnerisch war nichts zu korrigieren: Payline-Punkte und Provision
des Prognose-Blocks (N4) stimmen exakt mit der Provisions-Engine überein
(54.718,5 P. bzw. 3.772,88 EUR gegengerechnet an User 454). Behoben sind
Darstellungs- und Konsistenzfehler, die der Beraterin als falsche Zahlen
aufgefallen wären:
- "+N neu" schrumpfte rückwirkend, der Bestand daneben nicht: newAboCount() nutzte
weiter activeAbo(), während aboStockCount() auf das Monatsende zurückrechnet.
Beide teilen sich jetzt aboStockQuery(); die Jahres-Wachstumstabelle ebenso.
- Level-Kachel widersprach sich ("Zum nächsten Level Diamant fehlen X" über
"Karriere-Level: Diamant"): Text auf die Monats-Qualifikation umformuliert
(de/en/es/fr), Überschrift "Qualifikation in diesem Monat", Karriere-Level nur
noch bei Abweichung.
- Firstlines-Kachel zählte alle direkten Partner, "Teampartner gesamt" daneben nur
aktive (F1): Kachel nutzt jetzt isActiveConsultant(), die Detailseite listet
weiter alle und weist beide Zahlen aus.
- Neupartnerzahlen vergangener Monate sanken auf dem Home-Dashboard, sobald
Jahresgebühren ausliefen: neue User::newPartnerReferenceDate() (laufender Monat =
heute, abgeschlossener Monat = Monatsende). Dabei die drei Inline-Kopien der
Neupartner-Regel auf scopeNewPartnerIn()/isNewPartnerIn() zusammengeführt.
- Top-3-Karte ließ den Betrachter aus, obwohl "ich gehört in die Liste" in der
Juli-Runde für alle anderen Ranglisten umgesetzt wurde: zählt jetzt mit, inkl.
is_self und "ich"-Badge.
- Neues Profilfoto zeigte bis zu 6 h ein totes Bild: die URL steckt nicht mehr im
Cache, sondern entsteht beim Lesen (withProfileImages()).
- Test-Regression seit der Juli-Runde: Unit/Services/BackofficeDashboardServiceTest
fiel über die fehlende Spalte status_points (kam mit nonPaylinePoints() dazu).
- Kleinigkeiten: ProfileImageController gab die komplette Exception als
Flash-Message aus (jetzt Log + Sprachkey), BackofficeDrilldownService formatierte
Datumsangaben hart auf d.m.Y statt über Util::formatDateDB().
Tests: neuer HomeMonthlyStatsTest (buildMonthlyStats war ungetestet) plus Tests für
Stichtags-Zählung und Foto-Cache. Fünf Tests kodierten das alte Verhalten
(Betrachter zählt nicht mit, abgelaufener Account zählt nie) und wurden auf die
neue Semantik umgestellt, jeweils mit Gegenprobe. Suite: 861 grün (vorher 855),
89 rot — ausschließlich die in docs/2026-06-11-test-suite-vorbestehende-fehler.md
dokumentierten Altlasten.
Offen und bewusst nicht enthalten:
- Deploy-Schritt: backoffice:store-statistics-snapshots --force (vorher dumpen).
Kein vorhandener Snapshot enthält recruiter_ranking, Mai/Juni zusätzlich weder
non_payline_points noch die Führungskräfte-"gesamt"-Spalten; der Cron überspringt
vorhandene Snapshots ohne --force. Achtung: die Neuberechnung ist nicht
verlustfrei.
- TreeHtmlRendererTest/TreeCalcBotIntegrationTest: die Abo-Badges machten den
Renderer datenbankabhängig; die Dateien waren schon vorher rot und gehören in die
separate Test-Aufräumaufgabe.
- deleteImage bleibt ein GET-Route (gleiches Muster wie das Shop-Bild).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
242 lines
9.2 KiB
PHP
242 lines
9.2 KiB
PHP
<?php
|
|
|
|
use App\Models\UserAbo;
|
|
use App\Models\UserAccount;
|
|
use App\Models\UserSalesVolume;
|
|
use App\Services\Team\TopResultsService;
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
Carbon::setTestNow(Carbon::parse('2026-08-15'));
|
|
Cache::flush();
|
|
});
|
|
|
|
afterEach(function () {
|
|
Carbon::setTestNow();
|
|
});
|
|
|
|
function trsMakeUser(
|
|
?int $sponsorId = null,
|
|
string $firstName = 'Team',
|
|
string $lastName = 'Partner',
|
|
?string $activeDate = null,
|
|
?string $paymentAccount = 'future',
|
|
): User {
|
|
$account = UserAccount::forceCreate([
|
|
'first_name' => $firstName,
|
|
'last_name' => $lastName,
|
|
]);
|
|
|
|
return User::forceCreate([
|
|
'email' => 'trs-'.uniqid('', true).'@example.com',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
'm_level' => 1,
|
|
'm_sponsor' => $sponsorId,
|
|
'payment_account' => $paymentAccount === 'future' ? now()->addYear() : $paymentAccount,
|
|
'active_date' => $activeDate,
|
|
'account_id' => $account->id,
|
|
]);
|
|
}
|
|
|
|
function trsAddVolume(int $userId, int $points, int $status, int $month = 8, int $year = 2026): void
|
|
{
|
|
UserSalesVolume::forceCreate([
|
|
'user_id' => $userId,
|
|
'month' => $month,
|
|
'year' => $year,
|
|
'points' => $points,
|
|
'status' => $status,
|
|
]);
|
|
}
|
|
|
|
function trsMakeAbo(int $ownerId, string $isFor, string $startDate, bool $active = true, int $status = 2): UserAbo
|
|
{
|
|
return UserAbo::create([
|
|
'user_id' => $ownerId,
|
|
'member_id' => $ownerId,
|
|
'shopping_user_id' => 0,
|
|
'email' => 'trs-abo-'.uniqid('', true).'@example.com',
|
|
'is_for' => $isFor,
|
|
'payone_userid' => 0,
|
|
'clearingtype' => 'cc',
|
|
'amount' => 5000,
|
|
'active' => $active,
|
|
'status' => $status,
|
|
'abo_interval' => 5,
|
|
'start_date' => $startDate,
|
|
'next_date' => '2026-09-05',
|
|
]);
|
|
}
|
|
|
|
function trsTop3(User $viewer): array
|
|
{
|
|
Cache::flush();
|
|
|
|
return app(TopResultsService::class)->monthlyTop3($viewer, 8, 2026);
|
|
}
|
|
|
|
it('rankt das persoenliche Volumen inkl. Status-1- und Status-2-Punkten, mit Betrachter, ohne Fremde', function (): void {
|
|
$root = trsMakeUser(null, 'Root', 'Viewer');
|
|
$anna = trsMakeUser($root->id, 'Anna', 'Alpha');
|
|
$ben = trsMakeUser($root->id, 'Ben', 'Beta');
|
|
$fremd = trsMakeUser(null, 'Frank', 'Fremd');
|
|
|
|
trsAddVolume($anna->id, 100, 1); // Eigenpunkte
|
|
trsAddVolume($anna->id, 50, 2); // Kundenpunkte
|
|
trsAddVolume($anna->id, 999, 3); // pending zaehlt nicht
|
|
trsAddVolume($ben->id, 40, 1);
|
|
trsAddVolume($ben->id, 70, 1, 7); // anderer Monat zaehlt nicht
|
|
trsAddVolume($root->id, 500, 1); // Betrachter zaehlt mit ("ich")
|
|
trsAddVolume($fremd->id, 800, 1); // nicht im Team
|
|
|
|
$result = trsTop3($root);
|
|
|
|
expect($result['top_volume'])->toHaveCount(3)
|
|
->and($result['top_volume'][0])->toMatchArray(['user_id' => $root->id, 'value' => 500.0, 'is_self' => true])
|
|
->and($result['top_volume'][1])->toMatchArray(['user_id' => $anna->id, 'first_name' => 'Anna', 'last_name' => 'Alpha', 'value' => 150.0, 'is_self' => false])
|
|
->and($result['top_volume'][1]['profile_image_url'])->toBeNull()
|
|
->and($result['top_volume'][2])->toMatchArray(['user_id' => $ben->id, 'value' => 40.0]);
|
|
});
|
|
|
|
it('begrenzt auf Top 3 und sortiert Gleichstaende nach Name', function (): void {
|
|
$root = trsMakeUser(null, 'Root', 'Viewer');
|
|
$carla = trsMakeUser($root->id, 'Carla', 'Chef');
|
|
$zoe = trsMakeUser($root->id, 'Zoe', 'Zett');
|
|
$anna = trsMakeUser($root->id, 'Anna', 'Alpha');
|
|
$doris = trsMakeUser($root->id, 'Doris', 'Klein');
|
|
|
|
trsAddVolume($carla->id, 200, 1);
|
|
trsAddVolume($zoe->id, 100, 1);
|
|
trsAddVolume($anna->id, 100, 1);
|
|
trsAddVolume($doris->id, 50, 1); // Platz 4, faellt raus
|
|
|
|
$result = trsTop3($root);
|
|
|
|
expect($result['top_volume'])->toHaveCount(3)
|
|
->and(array_column($result['top_volume'], 'user_id'))
|
|
->toBe([$carla->id, $anna->id, $zoe->id]);
|
|
});
|
|
|
|
it('zaehlt Neupartner je Sponsor nach der Dashboard-Definition', function (): void {
|
|
$root = trsMakeUser(null, 'Root', 'Viewer');
|
|
$sponsor = trsMakeUser($root->id, 'Sandra', 'Sponsor');
|
|
$other = trsMakeUser($root->id, 'Olaf', 'Other');
|
|
|
|
trsMakeUser($sponsor->id, 'Neu', 'Eins', '2026-08-10');
|
|
trsMakeUser($sponsor->id, 'Neu', 'Zwei', '2026-08-20');
|
|
trsMakeUser($sponsor->id, 'Alt', 'Juli', '2026-07-10'); // anderer Monat
|
|
trsMakeUser($sponsor->id, 'Neu', 'Inaktiv', '2026-08-12', null); // kein aktives Abrechnungskonto
|
|
trsMakeUser($other->id, 'Neu', 'Drei', '2026-08-05');
|
|
trsMakeUser($root->id, 'Neu', 'BeimViewer', '2026-08-08'); // Sponsor = Betrachter, zaehlt mit
|
|
|
|
$result = trsTop3($root);
|
|
|
|
// Gleichstand 1:1 zwischen Olaf und Root -> nach Vorname sortiert
|
|
expect($result['top_recruiters'])->toHaveCount(3)
|
|
->and($result['top_recruiters'][0])->toMatchArray(['user_id' => $sponsor->id, 'value' => 2, 'is_self' => false])
|
|
->and($result['top_recruiters'][1])->toMatchArray(['user_id' => $other->id, 'value' => 1])
|
|
->and($result['top_recruiters'][2])->toMatchArray(['user_id' => $root->id, 'value' => 1, 'is_self' => true]);
|
|
});
|
|
|
|
it('zaehlt neue Abos als Kundenabos plus Eigenabo je Berater', function (): void {
|
|
$root = trsMakeUser(null, 'Root', 'Viewer');
|
|
$anna = trsMakeUser($root->id, 'Anna', 'Alpha');
|
|
$ben = trsMakeUser($root->id, 'Ben', 'Beta');
|
|
$fremd = trsMakeUser(null, 'Frank', 'Fremd');
|
|
|
|
trsMakeAbo($anna->id, 'ot', '2026-08-05');
|
|
trsMakeAbo($anna->id, 'ot', '2026-08-20');
|
|
trsMakeAbo($anna->id, 'me', '2026-08-03');
|
|
trsMakeAbo($anna->id, 'ot', '2026-07-05'); // anderer Monat
|
|
trsMakeAbo($anna->id, 'me', '2026-08-10', true, 4); // gekuendigt
|
|
trsMakeAbo($anna->id, 'ot', '2026-08-11', false); // inaktiv
|
|
trsMakeAbo($ben->id, 'me', '2026-08-15');
|
|
trsMakeAbo($root->id, 'ot', '2026-08-09'); // Betrachter zaehlt mit
|
|
trsMakeAbo($fremd->id, 'ot', '2026-08-09'); // nicht im Team
|
|
|
|
$result = trsTop3($root);
|
|
|
|
// Gleichstand 1:1 zwischen Ben und Root -> nach Vorname sortiert
|
|
expect($result['top_new_abos'])->toHaveCount(3)
|
|
->and($result['top_new_abos'][0])->toMatchArray(['user_id' => $anna->id, 'value' => 3, 'is_self' => false])
|
|
->and($result['top_new_abos'][1])->toMatchArray(['user_id' => $ben->id, 'value' => 1])
|
|
->and($result['top_new_abos'][2])->toMatchArray(['user_id' => $root->id, 'value' => 1, 'is_self' => true]);
|
|
});
|
|
|
|
it('cacht das Ergebnis fuer 6 Stunden', function (): void {
|
|
$root = trsMakeUser(null, 'Root', 'Viewer');
|
|
$anna = trsMakeUser($root->id, 'Anna', 'Alpha');
|
|
|
|
trsAddVolume($anna->id, 100, 1);
|
|
$first = app(TopResultsService::class)->monthlyTop3($root, 8, 2026);
|
|
|
|
trsAddVolume($anna->id, 900, 1);
|
|
$second = app(TopResultsService::class)->monthlyTop3($root, 8, 2026);
|
|
|
|
expect($first['top_volume'][0]['value'])->toBe(100.0)
|
|
->and($second)->toBe($first);
|
|
});
|
|
|
|
it('zeigt ein neues Profilfoto sofort, trotz gecachter Rangliste', function (): void {
|
|
Storage::fake('public');
|
|
|
|
$root = trsMakeUser(null, 'Root', 'Viewer');
|
|
$anna = trsMakeUser($root->id, 'Anna', 'Alpha');
|
|
trsAddVolume($anna->id, 100, 1);
|
|
|
|
$service = app(TopResultsService::class);
|
|
expect($service->monthlyTop3($root, 8, 2026)['top_volume'][0]['profile_image_url'])->toBeNull();
|
|
|
|
// Foto wird hochgeladen, nachdem die Rangliste bereits im Cache liegt
|
|
Storage::disk('public')->put('images/profile/anna.jpg', 'x');
|
|
$anna->account->forceFill(['profile_image' => 'anna.jpg'])->save();
|
|
|
|
expect($service->monthlyTop3($root, 8, 2026)['top_volume'][0]['profile_image_url'])
|
|
->toContain('images/profile/anna.jpg');
|
|
});
|
|
|
|
it('rendert die Top-Ergebnisse-Karte nur mit Eintraegen', function (): void {
|
|
URL::resolveMissingNamedRoutesUsing(fn (string $name, $parameters = []) => '/'.$name);
|
|
|
|
$row = fn (string $first, string $last, $value) => [
|
|
'user_id' => 1, 'first_name' => $first, 'last_name' => $last,
|
|
'profile_image_url' => null, 'value' => $value,
|
|
];
|
|
|
|
$html = view('dashboard._top_results', [
|
|
'monthlyStats' => [
|
|
'month' => 8,
|
|
'year' => 2026,
|
|
'top_results' => [
|
|
'top_volume' => [$row('Anna', 'Alpha', 150.0)],
|
|
'top_recruiters' => [],
|
|
'top_new_abos' => [$row('Ben', 'Beta', 3)],
|
|
],
|
|
],
|
|
])->render();
|
|
|
|
expect($html)
|
|
->toContain(e(__('home.top_results_title')))
|
|
->toContain(__('home.top_results_volume'))
|
|
->toContain('Anna Alpha')
|
|
->toContain('Ben Beta')
|
|
->toContain(__('home.top_results_empty')); // leere Recruiter-Spalte
|
|
|
|
$emptyHtml = view('dashboard._top_results', [
|
|
'monthlyStats' => [
|
|
'month' => 8,
|
|
'year' => 2026,
|
|
'top_results' => ['top_volume' => [], 'top_recruiters' => [], 'top_new_abos' => []],
|
|
],
|
|
])->render();
|
|
|
|
expect($emptyHtml)->not->toContain(e(__('home.top_results_title')));
|
|
});
|