the browser-facing portion of osu!
at master 2.2 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace Tests\Controllers; 7 8use App\Models\Beatmap; 9use App\Models\Count; 10use App\Models\User; 11use App\Models\UserStatistics\Model as UserStatisticsModel; 12use Tests\TestCase; 13 14class RankingControllerTest extends TestCase 15{ 16 public function testIndex() 17 { 18 $this 19 ->get(route('rankings', ['mode' => 'osu', 'type' => 'performance'])) 20 ->assertSuccessful(); 21 } 22 23 public function testIndexRedirect() 24 { 25 $this 26 ->get(route('rankings', ['mode' => 'osu'])) 27 ->assertRedirect(route('rankings', ['mode' => 'osu', 'type' => 'performance'])); 28 } 29 30 public function testIndexInvalidMode() 31 { 32 $this 33 ->get(route('rankings', ['mode' => 'nope', 'type' => 'performance'])) 34 ->assertStatus(404); 35 } 36 37 public function testIndexInvalidType() 38 { 39 $this 40 ->get(route('rankings', ['mode' => 'osu', 'type' => 'notatype'])) 41 ->assertStatus(404); 42 } 43 44 public function testRankChange(): void 45 { 46 $ruleset = 'osu'; 47 $user = User::factory() 48 ->has( 49 UserStatisticsModel::getClass($ruleset)::factory()->state(['rank_score_index' => 1]), 50 User::statisticsRelationName($ruleset), 51 ) 52 ->create(); 53 $user->rankHistories()->create([ 54 'mode' => Beatmap::modeInt($ruleset), 55 'r0' => 10001, 56 ]); 57 58 // Set the start of the rank history table such that the recent rank 59 // change is taking the difference between current rank and r0 60 Count::updateOrCreate( 61 ['name' => Count::currentRankStartName($ruleset)], 62 ['count' => 30], 63 ); 64 65 $this->actAsScopedUser(null, ['public']); 66 67 $this 68 ->getJson(route('api.rankings', ['mode' => $ruleset, 'type' => 'performance'])) 69 ->assertOk() 70 ->assertJsonPath('ranking.0.rank_change_since_30_days', -10000); 71 } 72}