forked from RetroAchievements/RAWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserSetRequestsTest.php
More file actions
141 lines (127 loc) · 4.76 KB
/
Copy pathUserSetRequestsTest.php
File metadata and controls
141 lines (127 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
declare(strict_types=1);
namespace Tests\Feature\Api\V1;
use App\Models\Game;
use App\Models\System;
use App\Models\User;
use App\Models\UserGameListEntry;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class UserSetRequestsTest extends TestCase
{
use RefreshDatabase;
use BootstrapsApiV1;
/**
* Test that the API returns an empty response for a non-existent user.
*/
public function testGetUserSetRequestsUnknownUser(): void
{
$this->get($this->apiUrl('GetUserSetRequests', ['u' => 'nonExistant']))
->assertStatus(404)
->assertJson([]);
}
/**
* Test that the API returns all set requests for an existing user.
*/
public function testGetAllUserSetRequests(): void
{
$system = System::factory()->create();
$game = Game::factory()->create([
'ConsoleID' => $system->ID,
'ImageIcon' => '/Images/001234.png',
'achievements_published' => 0,
]);
$game2 = Game::factory()->create([
'Title' => '~Hack~ Test Case',
'ConsoleID' => $system->ID,
'ImageIcon' => '/Images/001235.png',
'achievements_published' => 12,
]);
$user = User::factory()->create([
'RAPoints' => 1501, // enough points to set request total to 1
]);
// Create the first user game list entry for the set request
UserGameListEntry::factory()->create([
'user_id' => $user->ID,
'type' => 'achievement_set_request',
'GameID' => $game->ID,
]);
// Create the second user game list entry for the set request
UserGameListEntry::factory()->create([
'user_id' => $user->ID,
'type' => 'achievement_set_request',
'GameID' => $game2->ID,
]);
$this->get($this->apiUrl('GetUserSetRequests', ['u' => $user->User, 't' => 1]))
->assertSuccessful()
->assertJson([
'RequestedSets' => [
[
'GameID' => $game->ID,
'Title' => $game->Title,
'ConsoleID' => $game->ConsoleID,
'ConsoleName' => $system->Name,
'ImageIcon' => $game->ImageIcon,
],
[
'GameID' => $game2->ID,
'Title' => $game2->Title,
'ConsoleID' => $game2->ConsoleID,
'ConsoleName' => $system->Name,
'ImageIcon' => $game2->ImageIcon,
],
],
'TotalRequests' => 1,
'PointsForNext' => 999,
]);
}
/**
* Test that the API returns only set requests with no published achievements for an existing user.
*/
public function testGetUserSetRequests(): void
{
$system = System::factory()->create();
$game = Game::factory()->create([
'ConsoleID' => $system->ID,
'ImageIcon' => '/Images/001234.png',
'achievements_published' => 4,
]);
$game2 = Game::factory()->create([
'Title' => '~Hack~ Test Case',
'ConsoleID' => $system->ID,
'ImageIcon' => '/Images/001235.png',
'achievements_published' => 0,
]);
$user = User::factory()->create([
'RAPoints' => 1501, // enough points to set request total to 1
]);
// Create the first user game list entry for the set request
UserGameListEntry::factory()->create([
'user_id' => $user->ID,
'type' => 'achievement_set_request',
'GameID' => $game->ID,
]);
// Create the second user game list entry for the set request
UserGameListEntry::factory()->create([
'user_id' => $user->ID,
'type' => 'achievement_set_request',
'GameID' => $game2->ID,
]);
// Note that only the second game is present in the assert. The code will find the first game as well but only return the game with no published achievements.
$this->get($this->apiUrl('GetUserSetRequests', ['u' => $user->User, 't' => 0]))
->assertSuccessful()
->assertJson([
'RequestedSets' => [
[
'GameID' => $game2->ID,
'Title' => $game2->Title,
'ConsoleID' => $game2->ConsoleID,
'ConsoleName' => $system->Name,
'ImageIcon' => $game2->ImageIcon,
],
],
'TotalRequests' => 1,
'PointsForNext' => 999,
]);
}
}