10.April 2026
This commit is contained in:
parent
a00c42e770
commit
f58c709945
208 changed files with 19280 additions and 2914 deletions
181
tests/Feature/Incentive/IncentiveParticipantRankOrderingTest.php
Normal file
181
tests/Feature/Incentive/IncentiveParticipantRankOrderingTest.php
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\User\IncentiveController;
|
||||
use App\Models\Incentive;
|
||||
use App\Models\IncentiveParticipant;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('sortiert Teilnehmer mit Rang 1,2,… und ohne Rang zuletzt', function () {
|
||||
$incentive = Incentive::factory()->create();
|
||||
|
||||
$makeUser = fn () => User::forceCreate([
|
||||
'email' => 't-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
]);
|
||||
|
||||
$userNoRank = $makeUser();
|
||||
$userRank2 = $makeUser();
|
||||
$userRank1 = $makeUser();
|
||||
|
||||
IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $userNoRank->id,
|
||||
'rank' => null,
|
||||
]);
|
||||
IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $userRank2->id,
|
||||
'rank' => 2,
|
||||
]);
|
||||
IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $userRank1->id,
|
||||
'rank' => 1,
|
||||
]);
|
||||
|
||||
$orderedUserIds = IncentiveParticipant::query()
|
||||
->where('incentive_id', $incentive->id)
|
||||
->orderByIncentiveLeaderboard()
|
||||
->pluck('user_id')
|
||||
->all();
|
||||
|
||||
expect($orderedUserIds)->toBe([$userRank1->id, $userRank2->id, $userNoRank->id]);
|
||||
});
|
||||
|
||||
it('sortiert qualifizierte Teilnehmer vor nicht qualifizierten, unabhängig von Punkten und Rang', function () {
|
||||
$incentive = Incentive::factory()->create();
|
||||
|
||||
$makeUser = fn () => User::forceCreate([
|
||||
'email' => 't-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
]);
|
||||
|
||||
$userNotQualified = $makeUser();
|
||||
$userQualified = $makeUser();
|
||||
|
||||
IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $userNotQualified->id,
|
||||
'is_qualified' => false,
|
||||
'total_points' => 10_000,
|
||||
'rank' => 1,
|
||||
]);
|
||||
IncentiveParticipant::factory()->qualified()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $userQualified->id,
|
||||
'total_points' => 500,
|
||||
'rank' => 2,
|
||||
]);
|
||||
|
||||
$orderedUserIds = IncentiveParticipant::query()
|
||||
->where('incentive_id', $incentive->id)
|
||||
->orderByIncentiveLeaderboard()
|
||||
->pluck('user_id')
|
||||
->all();
|
||||
|
||||
expect($orderedUserIds)->toBe([$userQualified->id, $userNotQualified->id]);
|
||||
});
|
||||
|
||||
it('sortiert bei Punktgleichstand Teilnehmer mit Klarnamen (bestaetigte Teilnahme) vor anonymen', function () {
|
||||
$incentive = Incentive::factory()->create();
|
||||
|
||||
$makeUser = fn () => User::forceCreate([
|
||||
'email' => 't-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
]);
|
||||
|
||||
$anonymous = IncentiveParticipant::factory()->unconfirmed()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $makeUser()->id,
|
||||
'total_points' => 500,
|
||||
'rank' => 5,
|
||||
]);
|
||||
$confirmed = IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $makeUser()->id,
|
||||
'accepted_terms_at' => now(),
|
||||
'total_points' => 500,
|
||||
'rank' => 5,
|
||||
]);
|
||||
|
||||
$orderedUserIds = IncentiveParticipant::query()
|
||||
->where('incentive_id', $incentive->id)
|
||||
->orderByIncentiveLeaderboard()
|
||||
->pluck('user_id')
|
||||
->all();
|
||||
|
||||
expect($orderedUserIds)->toBe([$confirmed->user_id, $anonymous->user_id]);
|
||||
});
|
||||
|
||||
it('begrenzt die User-Rangliste auf 30 Plaetze (Gewinner-Zone bleibt max_winners)', function () {
|
||||
$incentive = Incentive::factory()->create(['max_winners' => 20]);
|
||||
|
||||
$makeUser = fn () => User::forceCreate([
|
||||
'email' => 't-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
]);
|
||||
|
||||
foreach (range(1, 35) as $i) {
|
||||
IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $makeUser()->id,
|
||||
'total_points' => 1000 - $i,
|
||||
]);
|
||||
}
|
||||
|
||||
$ranking = IncentiveParticipant::where('incentive_id', $incentive->id)
|
||||
->withRankingActivity()
|
||||
->orderByIncentiveLeaderboard()
|
||||
->limit(IncentiveController::USER_RANKING_DISPLAY_LIMIT)
|
||||
->get();
|
||||
|
||||
expect($ranking)->toHaveCount(30);
|
||||
});
|
||||
|
||||
it('blendet in der User-Ranglogik Teilnehmer ohne Partner, Abo und Punkte aus', function () {
|
||||
$incentive = Incentive::factory()->create();
|
||||
|
||||
$makeUser = fn () => User::forceCreate([
|
||||
'email' => 't-'.uniqid('', true).'@example.com',
|
||||
'password' => bcrypt('secret'),
|
||||
'lang' => 'de',
|
||||
]);
|
||||
|
||||
IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $makeUser()->id,
|
||||
'qualified_partners' => 0,
|
||||
'qualified_abos' => 0,
|
||||
'total_points' => 0,
|
||||
]);
|
||||
IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $makeUser()->id,
|
||||
'qualified_partners' => 0,
|
||||
'qualified_abos' => 0,
|
||||
'total_points' => 100,
|
||||
]);
|
||||
IncentiveParticipant::factory()->create([
|
||||
'incentive_id' => $incentive->id,
|
||||
'user_id' => $makeUser()->id,
|
||||
'qualified_partners' => 1,
|
||||
'qualified_abos' => 0,
|
||||
'total_points' => 0,
|
||||
]);
|
||||
|
||||
$ids = IncentiveParticipant::query()
|
||||
->where('incentive_id', $incentive->id)
|
||||
->withRankingActivity()
|
||||
->orderBy('id')
|
||||
->pluck('id')
|
||||
->all();
|
||||
|
||||
expect($ids)->toHaveCount(2);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue