Skip to content

Commit

Permalink
update permissions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed May 26, 2024
1 parent 395425a commit 70c7883
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 12 deletions.
3 changes: 1 addition & 2 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
Route::name('user.servers_abilities')
->get('/user/servers_abilities', [ServersController::class, 'allServersAbilities']);

Route::name('game_mods.get_mods_list')->get('game_mods/get_list_for_game/{game}', [GameModsController::class, 'getListForGame']);

Route::middleware('isAdmin')->group(function () {
// Dedicated servers
Route::name('dedicated_servers')
Expand Down Expand Up @@ -113,6 +111,7 @@
Route::name('games.destroy')->delete('/games/{game}', [GamesController::class, 'destroy']);

Route::name('game_mods')->get('/game_mods', [GameModsController::class, 'index']);
Route::name('game_mods.get_mods_list')->get('game_mods/get_list_for_game/{game}', [GameModsController::class, 'getListForGame']);
Route::name('game_mods.store')->post('/game_mods', [GameModsController::class, 'store']);
Route::name('game_mods.show')->get('/game_mods/{game_mod}', [GameModsController::class, 'show']);
Route::name('game_mods.update')->put('/game_mods/{game_mod}', [GameModsController::class, 'update']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

namespace Tests\Feature\Permissions\Controllers\API;

use Gameap\Models\User;
use Gameap\Repositories\UserRepository;
use Illuminate\Http\Response;
use Silber\Bouncer\Bouncer;
use Tests\Feature\Permissions\PermissionsTestCase;
use Tests\TestCase;


class DedicatedServersControllerTest extends PermissionsTestCase
{
Expand All @@ -24,11 +19,11 @@ public function routesDataProvider()
['get', 'api.dedicated_servers.summary'],
['get', 'api.dedicated_servers.setup'],
['get', 'api.dedicated_servers.certificates'],
['get', 'api.dedicated_servers.logs'],
['get', 'api.dedicated_servers.get'],
['get', 'api.dedicated_servers.daemon'],
['get', 'api.dedicated_servers.ip_list'],
['get', 'api.dedicated_servers.busy_ports'],
['get', 'api.dedicated_servers.logs', 1],
['get', 'api.dedicated_servers.get', 1],
['get', 'api.dedicated_servers.daemon', 1],
['get', 'api.dedicated_servers.ip_list', 1],
['get', 'api.dedicated_servers.busy_ports', 1],
['post', 'api.dedicated_servers.store'],
['put', 'api.dedicated_servers.update', 1],
['delete', 'api.dedicated_servers.destroy', 1],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Tests\Feature\Permissions\Controllers\API;

use Illuminate\Http\Response;
use Tests\Feature\Permissions\PermissionsTestCase;

class GameModsControllerTest extends PermissionsTestCase
{
public function setUp(): void
{
parent::setUp();
}

public function routesDataProvider()
{
return [
['get', 'api.game_mods'],
['get', 'api.game_mods.get_mods_list'],
['post', 'api.game_mods.store'],
['get', 'api.game_mods.show', 1],
['put', 'api.game_mods.update', 1],
['delete', 'api.game_mods.destroy', 1],
];
}

/**
* @dataProvider routesDataProvider
*/
public function testForbidden($method, $route, $param = null, $data = [])
{
$this->setCurrentUserRoles(['user']);

$response = $this->{$method}(route($route, $param), $data);
$response->assertStatus(Response::HTTP_FORBIDDEN);
}
}
38 changes: 38 additions & 0 deletions tests/Feature/Permissions/Controllers/API/GamesControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Tests\Feature\Permissions\Controllers\API;

use Illuminate\Http\Response;
use Tests\Feature\Permissions\PermissionsTestCase;

class GamesControllerTest extends PermissionsTestCase
{
public function setUp(): void
{
parent::setUp();
}

public function routesDataProvider()
{
return [
['get', 'api.games'],
['post', 'api.games.store'],
['get', 'api.games.show', 1],
['put', 'api.games.update', 1],
['post', 'api.games.upgrade'],
['get', 'api.games.mods', 1],
['delete', 'api.games.destroy', 1],
];
}

/**
* @dataProvider routesDataProvider
*/
public function testForbidden($method, $route, $param = null, $data = [])
{
$this->setCurrentUserRoles(['user']);

$response = $this->{$method}(route($route, $param), $data);
$response->assertStatus(Response::HTTP_FORBIDDEN);
}
}

0 comments on commit 70c7883

Please sign in to comment.