mivita/tests/Feature/PointsAboHighlightTest.php
Kevin 773d523bf7 Punkte-Legende entfernt, Prognose-Titel auf Monatsende
- Aktuelle Punkte / Meine Statistik / Team-Punkte: Farblegende unter der
  Bestellliste entfaellt (Kundenwunsch 24.09.)
- Home: "Level & Provision laut Prognose" nennt jetzt "Stand Monatsende";
  die Prognose rechnet schon bis zum letzten Liefertag, nur der Titel
  sagte noch "Stand 25."

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 11:37:32 +00:00

125 lines
4.2 KiB
PHP

<?php
use App\Models\ShoppingOrder;
use App\Models\UserSalesVolume;
use App\Services\Backoffice\PersonalStatisticsService;
use App\User;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\URL;
use Tests\TestCase;
uses(TestCase::class, RefreshDatabase::class);
beforeEach(function () {
Carbon::setTestNow(Carbon::parse('2026-09-08'));
URL::resolveMissingNamedRoutesUsing(fn (string $name, $parameters = []) => '/'.$name);
});
afterEach(function () {
Carbon::setTestNow();
});
function pahUser(string $email): User
{
return User::forceCreate([
'email' => $email,
'password' => bcrypt('secret'),
'lang' => 'de',
'm_level' => 1,
'admin' => 1,
'active_date' => '2026-01-10',
'payment_account' => now()->addYear(),
]);
}
function pahVolume(User $user, bool $isAbo, int $status = 1): UserSalesVolume
{
$order = ShoppingOrder::create([
'shopping_user_id' => 0,
'auth_user_id' => $user->id,
'member_id' => $user->id,
'country_id' => 1,
'language' => 'de',
'user_shop_id' => 1,
'payment_for' => 6,
'total' => 50.00,
'subtotal' => 50.00,
'points' => 45,
'paid' => true,
'shipped' => 0,
'is_abo' => $isAbo,
'mode' => 'live',
]);
return UserSalesVolume::forceCreate([
'user_id' => $user->id,
'shopping_order_id' => $order->id,
'month' => 9,
'year' => 2026,
'date' => '08.09.2026',
'status' => $status,
'points' => 45,
'total_net' => 100,
]);
}
it('hebt Abo-Bestellungen in der Dashboard-Karte "Aktuelle Punkte" ab', function (): void {
// Kundenrueckmeldung 08.09.2026: In "Aktuelle Punkte" waren die Abos nicht
// hervorgehoben — die Kennzeichnung gab es bisher nur unter Mein Team > Punkte.
$user = pahUser('pah-dashboard@example.com');
pahVolume($user, isAbo: true);
pahVolume($user, isAbo: false);
$html = view('dashboard._points', ['user' => $user->fresh()])->render();
expect($html)
->toContain('btn-xs btn-info')
->toContain('btn-xs btn-primary')
->toContain(e(__('abo.abo_order_short')))
// Kundenwunsch 24.09.2026: die Farblegende unter der Tabelle entfaellt
->not->toContain('blau = eigene Bestellung')
// Kundenwunsch 09.09.2026: auch in der Spalte "Art" haengt der Abo-Zusatz dahinter
->toContain(e(__('payment.advisor_order').' '.__('abo.abo_order_short')));
});
it('liefert das Abo-Kennzeichen fuer die persoenliche Statistik mit', function (): void {
$user = pahUser('pah-personal@example.com');
pahVolume($user, isAbo: true);
pahVolume($user, isAbo: false);
$groups = app(PersonalStatisticsService::class)->monthly($user, 9, 2026)['groups'];
$rows = collect($groups)->flatMap(fn (array $group) => $group['rows']);
expect($rows->pluck('is_abo')->all())->toContain(true)->toContain(false);
expect($rows->firstWhere('is_abo', true)['status_label'])
->toContain(__('abo.abo_order_short'));
expect($rows->firstWhere('is_abo', false)['status_label'])
->not->toContain(__('abo.abo_order_short'));
});
it('haengt den Abo-Zusatz nur bei Abo-Lieferungen an die Art', function (): void {
$user = pahUser('pah-model@example.com');
$abo = pahVolume($user, isAbo: true)->fresh(['shopping_order']);
$shop = pahVolume($user, isAbo: false)->fresh(['shopping_order']);
expect($abo->isAboOrder())->toBeTrue();
expect($shop->isAboOrder())->toBeFalse();
expect($abo->getStatusTypeWithAbo())->toBe($abo->getStatusType().' '.__('abo.abo_order_short'));
expect($shop->getStatusTypeWithAbo())->toBe($shop->getStatusType());
});
it('faerbt Abo-Bestellungen auch in "Meine Statistik" ein', function (): void {
// Die Seite haengt an layouts.layout-2 und laesst sich nicht isoliert rendern —
// geprueft wird deshalb die Verdrahtung von is_abo in der Blade-Quelle.
$view = file_get_contents(resource_path('views/user/backoffice/statistics/my.blade.php'));
expect($view)
->toContain("\$row['is_abo']")
->toContain("'info' : 'primary'")
->toContain("'info' : 'secondary'")
->not->toContain('points_order_legend');
});