mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Implement tests
This commit is contained in:
parent
8b50ef077d
commit
a071fff954
|
@ -3,11 +3,13 @@
|
|||
namespace Tests\Feature\Accessories\Api;
|
||||
|
||||
use App\Models\Accessory;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use Tests\Concerns\TestsFullMultipleCompaniesSupport;
|
||||
use Tests\Concerns\TestsPermissionsRequirement;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ShowAccessoryTest extends TestCase implements TestsPermissionsRequirement
|
||||
class ShowAccessoryTest extends TestCase implements TestsFullMultipleCompaniesSupport, TestsPermissionsRequirement
|
||||
{
|
||||
public function testRequiresPermission()
|
||||
{
|
||||
|
@ -17,4 +19,43 @@ class ShowAccessoryTest extends TestCase implements TestsPermissionsRequirement
|
|||
->getJson(route('api.accessories.show', $accessory))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
public function testAdheresToFullMultipleCompaniesSupportScoping()
|
||||
{
|
||||
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
||||
|
||||
$accessoryForCompanyA = Accessory::factory()->for($companyA)->create();
|
||||
|
||||
$superuser = User::factory()->superuser()->create();
|
||||
$userForCompanyB = User::factory()->for($companyB)->viewAccessories()->create();
|
||||
|
||||
$this->settings->enableMultipleFullCompanySupport();
|
||||
|
||||
$this->actingAsForApi($userForCompanyB)
|
||||
->getJson(route('api.accessories.show', $accessoryForCompanyA))
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('error');
|
||||
|
||||
$this->actingAsForApi($superuser)
|
||||
->getJson(route('api.accessories.show', $accessoryForCompanyA))
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'id' => $accessoryForCompanyA->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCanGetSingleAccessory()
|
||||
{
|
||||
$accessory = Accessory::factory()->checkedOutToUser()->create(['name' => 'My Accessory']);
|
||||
|
||||
$this->actingAsForApi(User::factory()->viewAccessories()->create())
|
||||
->getJson(route('api.accessories.show', $accessory))
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'id' => $accessory->id,
|
||||
'name' => 'My Accessory',
|
||||
'checkouts_count' => 1,
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue