Skip to content

Commit e8ea218

Browse files
committed
Add integration test for remaining application api user endpoints
1 parent bbbab4b commit e8ea218

File tree

6 files changed

+355
-20
lines changed

6 files changed

+355
-20
lines changed

app/Transformers/Api/Application/UserTransformer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function transform(User $user): array
5353
*
5454
* @param \Pterodactyl\Models\User $user
5555
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
56+
*
57+
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
5658
*/
5759
public function includeServers(User $user)
5860
{

database/factories/ModelFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Cake\Chronos\Chronos;
34
use Faker\Generator as Faker;
45
use Pterodactyl\Models\ApiKey;
56

@@ -57,6 +58,8 @@
5758
'language' => 'en',
5859
'root_admin' => false,
5960
'use_totp' => false,
61+
'created_at' => Chronos::now(),
62+
'updated_at' => Chronos::now(),
6063
];
6164
});
6265

@@ -69,7 +72,7 @@
6972
$factory->define(Pterodactyl\Models\Location::class, function (Faker $faker) {
7073
return [
7174
'id' => $faker->unique()->randomNumber(),
72-
'short' => $faker->domainWord,
75+
'short' => $faker->unique()->domainWord,
7376
'long' => $faker->catchPhrase,
7477
];
7578
});

tests/Integration/Api/Application/Location/LocationControllerTest.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Pterodactyl\Tests\Integration\Api\Application\Location;
44

55
use Pterodactyl\Models\Node;
6+
use Illuminate\Http\Response;
67
use Pterodactyl\Models\Location;
78
use Pterodactyl\Transformers\Api\Application\NodeTransformer;
89
use Pterodactyl\Transformers\Api\Application\ServerTransformer;
@@ -17,8 +18,8 @@ public function testGetLocations()
1718
{
1819
$locations = factory(Location::class)->times(2)->create();
1920

20-
$response = $this->json('GET', '/api/application/locations');
21-
$response->assertStatus(200);
21+
$response = $this->getJson('/api/application/locations');
22+
$response->assertStatus(Response::HTTP_OK);
2223
$response->assertJsonCount(2, 'data');
2324
$response->assertJsonStructure([
2425
'object',
@@ -71,8 +72,8 @@ public function testGetSingleLocation()
7172
{
7273
$location = factory(Location::class)->create();
7374

74-
$response = $this->json('GET', '/api/application/locations/' . $location->id);
75-
$response->assertStatus(200);
75+
$response = $this->getJson('/api/application/locations/' . $location->id);
76+
$response->assertStatus(Response::HTTP_OK);
7677
$response->assertJsonCount(2);
7778
$response->assertJsonStructure(['object', 'attributes' => ['id', 'short', 'long', 'created_at', 'updated_at']]);
7879
$response->assertJson([
@@ -95,8 +96,8 @@ public function testRelationshipsCanBeLoaded()
9596
$location = factory(Location::class)->create();
9697
$server = $this->createServerModel(['user_id' => $this->getApiUser()->id, 'location_id' => $location->id]);
9798

98-
$response = $this->json('GET', '/api/application/locations/' . $location->id . '?include=servers,nodes');
99-
$response->assertStatus(200);
99+
$response = $this->getJson('/api/application/locations/' . $location->id . '?include=servers,nodes');
100+
$response->assertStatus(Response::HTTP_OK);
100101
$response->assertJsonCount(2)->assertJsonCount(2, 'attributes.relationships');
101102
$response->assertJsonStructure([
102103
'attributes' => [
@@ -145,8 +146,8 @@ public function testKeyWithoutPermissionCannotLoadRelationship()
145146
$location = factory(Location::class)->create();
146147
factory(Node::class)->create(['location_id' => $location->id]);
147148

148-
$response = $this->json('GET', '/api/application/locations/' . $location->id . '?include=nodes');
149-
$response->assertStatus(200);
149+
$response = $this->getJson('/api/application/locations/' . $location->id . '?include=nodes');
150+
$response->assertStatus(Response::HTTP_OK);
150151
$response->assertJsonCount(2)->assertJsonCount(1, 'attributes.relationships');
151152
$response->assertJsonStructure([
152153
'attributes' => [
@@ -176,7 +177,7 @@ public function testKeyWithoutPermissionCannotLoadRelationship()
176177
*/
177178
public function testGetMissingLocation()
178179
{
179-
$response = $this->json('GET', '/api/application/locations/nil');
180+
$response = $this->getJson('/api/application/locations/nil');
180181
$this->assertNotFoundJson($response);
181182
}
182183

@@ -189,7 +190,7 @@ public function testErrorReturnedIfNoPermission()
189190
$location = factory(Location::class)->create();
190191
$this->createNewDefaultApiKey($this->getApiUser(), ['r_locations' => 0]);
191192

192-
$response = $this->json('GET', '/api/application/locations/' . $location->id);
193+
$response = $this->getJson('/api/application/locations/' . $location->id);
193194
$this->assertAccessDeniedJson($response);
194195
}
195196

@@ -201,7 +202,7 @@ public function testResourceIsNotExposedWithoutPermissions()
201202
{
202203
$this->createNewDefaultApiKey($this->getApiUser(), ['r_locations' => 0]);
203204

204-
$response = $this->json('GET', '/api/application/locations/nil');
205+
$response = $this->getJson('/api/application/locations/nil');
205206
$this->assertAccessDeniedJson($response);
206207
}
207208
}

tests/Integration/Api/Application/Users/ExternalUserControllerTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Pterodactyl\Tests\Integration\Api\Application\Users;
44

55
use Pterodactyl\Models\User;
6+
use Illuminate\Http\Response;
67
use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase;
78

89
class ExternalUserControllerTest extends ApplicationApiIntegrationTestCase
@@ -14,8 +15,8 @@ public function testGetRemoteUser()
1415
{
1516
$user = factory(User::class)->create();
1617

17-
$response = $this->json('GET', '/api/application/users/external/' . $user->external_id);
18-
$response->assertStatus(200);
18+
$response = $this->getJson('/api/application/users/external/' . $user->external_id);
19+
$response->assertStatus(Response::HTTP_OK);
1920
$response->assertJsonCount(2);
2021
$response->assertJsonStructure([
2122
'object',
@@ -47,9 +48,9 @@ public function testGetRemoteUser()
4748
/**
4849
* Test that an invalid external ID returns a 404 error.
4950
*/
50-
public function testGetMissingLocation()
51+
public function testGetMissingUser()
5152
{
52-
$response = $this->json('GET', '/api/application/users/external/nil');
53+
$response = $this->getJson('/api/application/users/external/nil');
5354
$this->assertNotFoundJson($response);
5455
}
5556

@@ -62,7 +63,7 @@ public function testErrorReturnedIfNoPermission()
6263
$user = factory(User::class)->create();
6364
$this->createNewDefaultApiKey($this->getApiUser(), ['r_users' => 0]);
6465

65-
$response = $this->json('GET', '/api/application/users/external/' . $user->external_id);
66+
$response = $this->getJson('/api/application/users/external/' . $user->external_id);
6667
$this->assertAccessDeniedJson($response);
6768
}
6869

@@ -74,7 +75,7 @@ public function testResourceIsNotExposedWithoutPermissions()
7475
{
7576
$this->createNewDefaultApiKey($this->getApiUser(), ['r_users' => 0]);
7677

77-
$response = $this->json('GET', '/api/application/users/external/nil');
78+
$response = $this->getJson('/api/application/users/external/nil');
7879
$this->assertAccessDeniedJson($response);
7980
}
8081
}

0 commit comments

Comments
 (0)