2024-09-09 14:35:38 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Accessories\Api;
|
|
|
|
|
|
|
|
use App\Models\Accessory;
|
2024-09-12 12:58:47 -07:00
|
|
|
use App\Models\Company;
|
2024-09-09 14:35:38 -07:00
|
|
|
use App\Models\User;
|
2024-09-12 12:58:47 -07:00
|
|
|
use Tests\Concerns\TestsMultipleFullCompanySupport;
|
2024-09-12 13:02:32 -07:00
|
|
|
use Tests\Concerns\TestsPermissionsRequirement;
|
2024-09-09 14:35:38 -07:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-09-12 13:32:42 -07:00
|
|
|
class DeleteAccessoriesTest extends TestCase implements TestsMultipleFullCompanySupport, TestsPermissionsRequirement
|
2024-09-09 14:35:38 -07:00
|
|
|
{
|
2024-09-12 13:02:32 -07:00
|
|
|
public function testRequiresPermission()
|
2024-09-09 14:35:38 -07:00
|
|
|
{
|
|
|
|
$accessory = Accessory::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->deleteJson(route('api.accessories.destroy', $accessory))
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
2024-09-12 12:58:47 -07:00
|
|
|
|
|
|
|
public function testAdheresToMultipleFullCompanySupportScoping()
|
|
|
|
{
|
|
|
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
|
|
|
|
|
|
|
$accessoryA = Accessory::factory()->for($companyA)->create();
|
|
|
|
$accessoryB = Accessory::factory()->for($companyB)->create();
|
|
|
|
$accessoryC = Accessory::factory()->for($companyB)->create();
|
|
|
|
|
|
|
|
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
|
|
|
$userInCompanyA = $companyA->users()->save(User::factory()->deleteAccessories()->make());
|
|
|
|
$userInCompanyB = $companyB->users()->save(User::factory()->deleteAccessories()->make());
|
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
$this->actingAsForApi($userInCompanyA)
|
|
|
|
->deleteJson(route('api.accessories.destroy', $accessoryB))
|
|
|
|
->assertStatusMessageIs('error');
|
|
|
|
|
|
|
|
$this->actingAsForApi($userInCompanyB)
|
|
|
|
->deleteJson(route('api.accessories.destroy', $accessoryA))
|
|
|
|
->assertStatusMessageIs('error');
|
|
|
|
|
|
|
|
$this->actingAsForApi($superUser)
|
|
|
|
->deleteJson(route('api.accessories.destroy', $accessoryC))
|
|
|
|
->assertStatusMessageIs('success');
|
|
|
|
|
2024-09-16 14:20:24 -07:00
|
|
|
$this->assertNotSoftDeleted($accessoryA);
|
|
|
|
$this->assertNotSoftDeleted($accessoryB);
|
|
|
|
$this->assertSoftDeleted($accessoryC);
|
2024-09-12 12:58:47 -07:00
|
|
|
}
|
2024-09-16 14:25:11 -07:00
|
|
|
|
|
|
|
public function testCannotDeleteAccessoryThatHasCheckouts()
|
|
|
|
{
|
|
|
|
$accessory = Accessory::factory()->checkedOutToUser()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->deleteAccessories()->create())
|
|
|
|
->deleteJson(route('api.accessories.destroy', $accessory))
|
|
|
|
->assertStatusMessageIs('error');
|
|
|
|
|
|
|
|
$this->assertNotSoftDeleted($accessory);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCanDeleteAccessory()
|
|
|
|
{
|
|
|
|
$accessory = Accessory::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->deleteAccessories()->create())
|
|
|
|
->deleteJson(route('api.accessories.destroy', $accessory))
|
|
|
|
->assertStatusMessageIs('success');
|
|
|
|
|
|
|
|
$this->assertSoftDeleted($accessory);
|
|
|
|
}
|
2024-09-09 14:35:38 -07:00
|
|
|
}
|