F1: partner_paid_at wird beim Rechnungskauf (paymentStatusPaidAction mit paid=false) nicht mehr gesetzt, sondern erst bei der Rechnungszahlung; der Backfill nimmt das Aktivierungsdatum nur noch ohne jede Registrierungsbestellung (offene Rechnung bleibt leer). F2: Snapshots speichern je Linie new_partner_ids, die Neupartner-Liste zeigt genau diese; aeltere Snapshots ohne IDs rechnen mit der damaligen Regel (Registrierungsmonat, scopeNewPartnerInByActiveDate), damit Kachel und Liste uebereinstimmen. Keine Payload-Versionsaenderung, kein Neuaufbau noetig. F3: Liefertag-/Termin-Aenderung waehrend einer Pause zieht paused_until mit; eine Ausfuehrung loescht auch den paused_by_*-Grund. F4: expiredCount der Firstlines-Seite (Controller, View, Sprachen) zum bereits committeten Test nachgezogen. F5: Backfills schreiben ohne updated_at (toBase()->update, timestamps=false). Kuendigungsbestaetigung abo_cancel_confirm wird im Selfservice serverseitig verlangt. AboStatusExplainer laedt die Historie je Abo und Aktion nur einmal. Stellungnahme und Deploy-Folgen im Audit-Dokument, Regressionstests je Befund. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
212 lines
7.9 KiB
PHP
212 lines
7.9 KiB
PHP
<?php
|
|
|
|
use App\Models\UserAbo;
|
|
use App\Models\UserSalesVolume;
|
|
use App\Services\Backoffice\BackofficeDashboardService;
|
|
use App\Services\Backoffice\BackofficeDrilldownService;
|
|
use App\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
// September laeuft, August ist abgeschlossen.
|
|
Carbon::setTestNow('2026-09-15 10:00:00');
|
|
});
|
|
|
|
afterEach(fn () => Carbon::setTestNow());
|
|
|
|
function freezeUser(?int $sponsor = null): User
|
|
{
|
|
return User::forceCreate([
|
|
'email' => 'freeze-'.uniqid('', true).'@example.test',
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
'm_level' => 1,
|
|
'm_sponsor' => $sponsor,
|
|
'active_date' => '2026-01-01',
|
|
'partner_paid_at' => '2026-01-01',
|
|
'payment_account' => '2027-01-01',
|
|
]);
|
|
}
|
|
|
|
function freezeVolume(User $user, float $points, int $month = 8): UserSalesVolume
|
|
{
|
|
return UserSalesVolume::forceCreate([
|
|
'user_id' => $user->id,
|
|
'month' => $month,
|
|
'year' => 2026,
|
|
'date' => '2026-0'.$month.'-05',
|
|
'points' => $points,
|
|
'total_net' => $points,
|
|
'status' => 1,
|
|
'status_points' => 1,
|
|
'status_turnover' => 1,
|
|
]);
|
|
}
|
|
|
|
function freezeAbo(User $member, string $isFor = 'ot', string $startDate = '2026-08-05'): UserAbo
|
|
{
|
|
return UserAbo::create([
|
|
'user_id' => $member->id,
|
|
'member_id' => $member->id,
|
|
'shopping_user_id' => 0,
|
|
'email' => 'a-'.uniqid('', true).'@example.test',
|
|
'is_for' => $isFor,
|
|
'payone_userid' => 0,
|
|
'clearingtype' => 'cc',
|
|
'amount' => 5000,
|
|
'active' => true,
|
|
'status' => 2,
|
|
'abo_interval' => 5,
|
|
'start_date' => $startDate,
|
|
'next_date' => '2026-10-05',
|
|
]);
|
|
}
|
|
|
|
it('haelt Punkte eines abgeschlossenen Monats nach einer spaeteren Korrektur fest', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
$volume = freezeVolume($anna, 100);
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
$volume->update(['points' => 500]);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 8, 2026);
|
|
|
|
expect($overview['_meta']['source'])->toBe('snapshot')
|
|
->and((float) $overview['totals']['total_points'])->toBe(100.0);
|
|
});
|
|
|
|
it('haelt auch die Abo-Bestaende und Ranglisten fest', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
$abo = freezeAbo($anna);
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
// Kuendigung im September darf den August nicht mehr veraendern.
|
|
$abo->update(['active' => false, 'status' => 4, 'cancel_date' => '2026-09-10']);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 8, 2026);
|
|
|
|
expect((int) $overview['totals']['team_customer_abos'])->toBe(1);
|
|
});
|
|
|
|
it('laesst einen spaeter dazugekommenen Teampartner aus dem abgeschlossenen Monat heraus', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
freezeVolume($anna, 100);
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
// Neuer Teampartner im September, mit einer Buchung, die im August liegt
|
|
// (z. B. nachtraeglich zugeordnet) — der abgeschlossene Monat bleibt unberuehrt.
|
|
$spaeter = freezeUser($root->id);
|
|
freezeVolume($spaeter, 999);
|
|
app(BackofficeDashboardService::class)->flushLineBucketsMemo($root->id);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 8, 2026);
|
|
$details = app(BackofficeDrilldownService::class)->details($root, 0, 'total_points', 8, 2026);
|
|
|
|
expect((float) $overview['totals']['total_points'])->toBe(100.0)
|
|
->and($details['summary']['total_points'])->toBe(100.0)
|
|
->and($details['rows'])->toHaveCount(1)
|
|
->and($details['rows'][0]['user_id'])->toBe($anna->id);
|
|
});
|
|
|
|
it('zeigt in der Abo-Detailliste genau die eingefrorenen Abos', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
$abo = freezeAbo($anna);
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
$abo->update(['active' => false, 'status' => 4, 'cancel_date' => '2026-09-10']);
|
|
$abo->delete();
|
|
|
|
$details = app(BackofficeDrilldownService::class)->details($root, 0, 'team_customer_abos', 8, 2026);
|
|
|
|
expect($details['summary']['abo_count'])->toBe(1);
|
|
});
|
|
|
|
it('haelt Kachel und verlinkte Liste der neuen Abos zusammen', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
$abo = freezeAbo($anna, 'ot', '2026-08-20'); // neu im August
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
$abo->update(['active' => false, 'status' => 4, 'cancel_date' => '2026-09-08']);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 8, 2026);
|
|
$details = app(BackofficeDrilldownService::class)->details($root, 0, 'team_customer_abos', 8, 2026, true);
|
|
|
|
expect((int) $overview['totals']['team_customer_abos_new'])->toBe(1)
|
|
->and($details['summary']['abo_count'])->toBe(1);
|
|
});
|
|
|
|
it('haelt Neupartner-Kachel und verlinkte Liste zusammen, auch nach spaeter nachgetragenem Zahlungsdatum (Audit F2)', function () {
|
|
$root = freezeUser();
|
|
// Registriert und bezahlt im August: Neupartner August.
|
|
$anna = User::forceCreate([
|
|
'email' => 'freeze-anna-'.uniqid('', true).'@example.test', 'password' => bcrypt('secret'), 'lang' => 'de',
|
|
'm_level' => 1, 'm_sponsor' => $root->id, 'active_date' => '2026-08-28', 'partner_paid_at' => '2026-08-28', 'payment_account' => '2027-08-28',
|
|
]);
|
|
|
|
app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
// Nachtraeglich korrigiert: Zahlung war erst im September.
|
|
User::whereKey($anna->id)->toBase()->update(['partner_paid_at' => '2026-09-01 06:49:00']);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 8, 2026);
|
|
$details = app(BackofficeDrilldownService::class)->details($root, 0, 'new_partners', 8, 2026);
|
|
|
|
expect((int) $overview['totals']['new_partners'])->toBe(1)
|
|
->and($details['rows'])->toHaveCount(1)
|
|
->and($details['rows'][0]['user_id'])->toBe($anna->id);
|
|
});
|
|
|
|
it('rechnet fuer Snapshots ohne Neupartner-IDs mit der damaligen Regel (Registrierungsmonat)', function () {
|
|
$root = freezeUser();
|
|
// Vor dem 16.09. gezaehlt: registriert im August, bezahlt erst im September.
|
|
$anna = User::forceCreate([
|
|
'email' => 'freeze-anna-'.uniqid('', true).'@example.test', 'password' => bcrypt('secret'), 'lang' => 'de',
|
|
'm_level' => 1, 'm_sponsor' => $root->id, 'active_date' => '2026-08-28', 'partner_paid_at' => '2026-09-01 06:49:00', 'payment_account' => '2027-09-01',
|
|
]);
|
|
|
|
$snapshot = app(BackofficeDashboardService::class)->storeSnapshot($root, 8, 2026);
|
|
|
|
// Alten Snapshot nachstellen: Kachel nach alter Regel = 1, keine gespeicherten IDs.
|
|
$payload = $snapshot->payload;
|
|
foreach ($payload['lines'] as &$line) {
|
|
unset($line['new_partner_ids']);
|
|
$line['new_partners'] = 1;
|
|
}
|
|
unset($line);
|
|
$payload['totals']['new_partners'] = 1;
|
|
$snapshot->update(['payload' => $payload]);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 8, 2026);
|
|
$details = app(BackofficeDrilldownService::class)->details($root, 0, 'new_partners', 8, 2026);
|
|
|
|
expect((int) $overview['totals']['new_partners'])->toBe(1)
|
|
->and($details['rows'])->toHaveCount(1)
|
|
->and($details['rows'][0]['user_id'])->toBe($anna->id);
|
|
});
|
|
|
|
it('rechnet den laufenden Monat weiterhin live', function () {
|
|
$root = freezeUser();
|
|
$anna = freezeUser($root->id);
|
|
$volume = freezeVolume($anna, 100, 9);
|
|
|
|
$volume->update(['points' => 500]);
|
|
|
|
$overview = app(BackofficeDashboardService::class)->overview($root, 9, 2026);
|
|
|
|
expect($overview['_meta']['source'])->toBe('live')
|
|
->and((float) $overview['totals']['total_points'])->toBe(500.0);
|
|
});
|