mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-23 11:43:47 -08:00
Simplify permission tests
This commit is contained in:
parent
bde05d6ed9
commit
983a25aa5f
|
@ -5,6 +5,7 @@ namespace Tests\Feature\Importing\Api;
|
|||
use App\Models\Accessory;
|
||||
use App\Models\Actionlog;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Database\Factories\AccessoryFactory;
|
||||
use Database\Factories\CompanyFactory;
|
||||
use Illuminate\Support\Str;
|
||||
|
@ -15,9 +16,10 @@ use Illuminate\Foundation\Testing\WithFaker;
|
|||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\Support\Importing\AccessoriesImportFileBuilder as ImportFileBuilder;
|
||||
|
||||
class ImportAccessoriesTest extends ImportDataTestCase
|
||||
class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissionsRequirement
|
||||
{
|
||||
use WithFaker;
|
||||
|
||||
|
@ -31,14 +33,9 @@ class ImportAccessoriesTest extends ImportDataTestCase
|
|||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('permissionsTestData')]
|
||||
public function onlyUserWithPermissionCanImportAccessories(array|string $permissions): void
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$permissions = collect((array) $permissions)
|
||||
->map(fn (string $permission) => [$permission => '1'])
|
||||
->toJson();
|
||||
|
||||
$this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions]));
|
||||
$this->actingAsForApi(User::factory()->create());
|
||||
|
||||
$this->importFileResponse(['import' => 44])->assertForbidden();
|
||||
}
|
||||
|
|
|
@ -19,9 +19,10 @@ use Illuminate\Support\Arr;
|
|||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\Support\Importing\AssetsImportFileBuilder as ImportFileBuilder;
|
||||
|
||||
class ImportAssetsTest extends ImportDataTestCase
|
||||
class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsRequirement
|
||||
{
|
||||
use WithFaker;
|
||||
|
||||
|
@ -35,14 +36,9 @@ class ImportAssetsTest extends ImportDataTestCase
|
|||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('permissionsTestData')]
|
||||
public function onlyUserWithPermissionCanImportAssets(array|string $permissions): void
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$permissions = collect((array) $permissions)
|
||||
->map(fn (string $permission) => [$permission => '1'])
|
||||
->toJson();
|
||||
|
||||
$this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions]));
|
||||
$this->actingAsForApi(User::factory()->create());
|
||||
|
||||
$this->importFileResponse(['import' => 44])->assertForbidden();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Tests\Feature\Importing\Api;
|
|||
|
||||
use App\Models\Actionlog as ActionLog;
|
||||
use App\Models\Component;
|
||||
use App\Models\User;
|
||||
use Database\Factories\ComponentFactory;
|
||||
use Illuminate\Support\Str;
|
||||
use Database\Factories\UserFactory;
|
||||
|
@ -13,9 +14,10 @@ use Illuminate\Foundation\Testing\WithFaker;
|
|||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\Support\Importing\ComponentsImportFileBuilder as ImportFileBuilder;
|
||||
|
||||
class ImportComponentsTest extends ImportDataTestCase
|
||||
class ImportComponentsTest extends ImportDataTestCase implements TestsPermissionsRequirement
|
||||
{
|
||||
use WithFaker;
|
||||
|
||||
|
@ -29,14 +31,9 @@ class ImportComponentsTest extends ImportDataTestCase
|
|||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('permissionsTestData')]
|
||||
public function onlyUserWithPermissionCanImportComponents(array|string $permissions): void
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$permissions = collect((array) $permissions)
|
||||
->map(fn (string $permission) => [$permission => '1'])
|
||||
->toJson();
|
||||
|
||||
$this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions]));
|
||||
$this->actingAsForApi(User::factory()->create());
|
||||
|
||||
$this->importFileResponse(['import' => 44])->assertForbidden();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Tests\Feature\Importing\Api;
|
|||
|
||||
use App\Models\Actionlog as ActivityLog;
|
||||
use App\Models\Consumable;
|
||||
use App\Models\User;
|
||||
use Database\Factories\ConsumableFactory;
|
||||
use Illuminate\Support\Str;
|
||||
use Database\Factories\UserFactory;
|
||||
|
@ -13,9 +14,10 @@ use Illuminate\Foundation\Testing\WithFaker;
|
|||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\Support\Importing\ConsumablesImportFileBuilder as ImportFileBuilder;
|
||||
|
||||
class ImportConsumablesTest extends ImportDataTestCase
|
||||
class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissionsRequirement
|
||||
{
|
||||
use WithFaker;
|
||||
|
||||
|
@ -29,14 +31,9 @@ class ImportConsumablesTest extends ImportDataTestCase
|
|||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('permissionsTestData')]
|
||||
public function onlyUserWithPermissionCanImportConsumables(array|string $permissions): void
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$permissions = collect((array) $permissions)
|
||||
->map(fn (string $permission) => [$permission => '1'])
|
||||
->toJson();
|
||||
|
||||
$this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions]));
|
||||
$this->actingAsForApi(User::factory()->create());
|
||||
|
||||
$this->importFileResponse(['import' => 44])->assertForbidden();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Tests\Feature\Importing\Api;
|
|||
|
||||
use App\Models\Actionlog as ActivityLog;
|
||||
use App\Models\License;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Database\Factories\UserFactory;
|
||||
use Database\Factories\ImportFactory;
|
||||
|
@ -12,9 +13,10 @@ use PHPUnit\Framework\Attributes\Test;
|
|||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\Support\Importing\LicensesImportFileBuilder as ImportFileBuilder;
|
||||
|
||||
class ImportLicenseTest extends ImportDataTestCase
|
||||
class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRequirement
|
||||
{
|
||||
use WithFaker;
|
||||
|
||||
|
@ -28,14 +30,9 @@ class ImportLicenseTest extends ImportDataTestCase
|
|||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('permissionsTestData')]
|
||||
public function onlyUserWithPermissionCanImportLicenses(array|string $permissions): void
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$permissions = collect((array) $permissions)
|
||||
->map(fn (string $permission) => [$permission => '1'])
|
||||
->toJson();
|
||||
|
||||
$this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions]));
|
||||
$this->actingAsForApi(User::factory()->create());
|
||||
|
||||
$this->importFileResponse(['import' => 44])->assertForbidden();
|
||||
}
|
||||
|
|
|
@ -15,9 +15,10 @@ use Illuminate\Support\Facades\Hash;
|
|||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\Support\Importing\UsersImportFileBuilder as ImportFileBuilder;
|
||||
|
||||
class ImportUsersTest extends ImportDataTestCase
|
||||
class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequirement
|
||||
{
|
||||
use WithFaker;
|
||||
|
||||
|
@ -31,14 +32,9 @@ class ImportUsersTest extends ImportDataTestCase
|
|||
}
|
||||
|
||||
#[Test]
|
||||
#[DataProvider('permissionsTestData')]
|
||||
public function onlyUserWithPermissionCanImportUsers(array|string $permissions): void
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
$permissions = collect((array) $permissions)
|
||||
->map(fn (string $permission) => [$permission => '1'])
|
||||
->toJson();
|
||||
|
||||
$this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions]));
|
||||
$this->actingAsForApi(User::factory()->create());
|
||||
|
||||
$this->importFileResponse(['import' => 44])->assertForbidden();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue