|
5 | 5 | use Pterodactyl\Models\Node; |
6 | 6 | use Illuminate\Http\Response; |
7 | 7 | use Pterodactyl\Models\Location; |
| 8 | +use Pterodactyl\Transformers\Api\Application\LocationTransformer; |
8 | 9 | use Pterodactyl\Transformers\Api\Application\NodeTransformer; |
9 | 10 | use Pterodactyl\Transformers\Api\Application\ServerTransformer; |
10 | 11 | use Pterodactyl\Tests\Integration\Api\Application\ApplicationApiIntegrationTestCase; |
@@ -88,6 +89,77 @@ public function testGetSingleLocation() |
88 | 89 | ], true); |
89 | 90 | } |
90 | 91 |
|
| 92 | + /** |
| 93 | + * Test that a location can be created. |
| 94 | + */ |
| 95 | + public function testCreateLocation() |
| 96 | + { |
| 97 | + $response = $this->postJson('/api/application/locations', [ |
| 98 | + 'short' => 'inhouse', |
| 99 | + 'long' => 'This is my inhouse location', |
| 100 | + ]); |
| 101 | + |
| 102 | + $response->assertStatus(Response::HTTP_CREATED); |
| 103 | + $response->assertJsonCount(3); |
| 104 | + $response->assertJsonStructure([ |
| 105 | + 'object', |
| 106 | + 'attributes' => ['id', 'short', 'long', 'created_at', 'updated_at'], |
| 107 | + 'meta' => ['resource'], |
| 108 | + ]); |
| 109 | + |
| 110 | + $this->assertDatabaseHas('locations', ['short' => 'inhouse', 'long' => 'This is my inhouse location']); |
| 111 | + |
| 112 | + $location = Location::where('short', 'inhouse')->first(); |
| 113 | + $response->assertJson([ |
| 114 | + 'object' => 'location', |
| 115 | + 'attributes' => $this->getTransformer(LocationTransformer::class)->transform($location), |
| 116 | + 'meta' => [ |
| 117 | + 'resource' => route('api.application.locations.view', $location->id), |
| 118 | + ], |
| 119 | + ], true); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * Test that a location can be updated. |
| 124 | + */ |
| 125 | + public function testUpdateLocation() |
| 126 | + { |
| 127 | + $location = Location::factory()->create(); |
| 128 | + |
| 129 | + $response = $this->patchJson('/api/application/locations/' . $location->id, [ |
| 130 | + 'short' => 'new inhouse', |
| 131 | + 'long' => 'This is my new inhouse location' |
| 132 | + ]); |
| 133 | + $response->assertStatus(Response::HTTP_OK); |
| 134 | + $response->assertJsonCount(2); |
| 135 | + $response->assertJsonStructure([ |
| 136 | + 'object', |
| 137 | + 'attributes' => ['id', 'short', 'long', 'created_at', 'updated_at'] |
| 138 | + ]); |
| 139 | + |
| 140 | + $this->assertDatabaseHas('locations', ['short' => 'new inhouse', 'long' => 'This is my new inhouse location']); |
| 141 | + $location = $location->fresh(); |
| 142 | + |
| 143 | + $response->assertJson([ |
| 144 | + 'object' => 'location', |
| 145 | + 'attributes' => $this->getTransformer(LocationTransformer::class)->transform($location), |
| 146 | + ]); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Test that a location can be deleted from the database. |
| 151 | + */ |
| 152 | + public function testDeleteLocation() |
| 153 | + { |
| 154 | + $location = Location::factory()->create(); |
| 155 | + $this->assertDatabaseHas('locations', ['id' => $location->id]); |
| 156 | + |
| 157 | + $response = $this->delete('/api/application/locations/' . $location->id); |
| 158 | + $response->assertStatus(Response::HTTP_NO_CONTENT); |
| 159 | + |
| 160 | + $this->assertDatabaseMissing('locations', ['id' => $location->id]); |
| 161 | + } |
| 162 | + |
91 | 163 | /** |
92 | 164 | * Test that all of the defined relationships for a location can be loaded successfully. |
93 | 165 | */ |
|
0 commit comments