2024-09-12 13:29:10 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\AssetMaintenances\Api;
|
|
|
|
|
|
|
|
use App\Models\AssetMaintenance;
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\User;
|
2024-09-16 16:55:20 -07:00
|
|
|
use Tests\Concerns\TestsFullMultipleCompaniesSupport;
|
2024-09-12 13:29:10 -07:00
|
|
|
use Tests\Concerns\TestsPermissionsRequirement;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-09-16 16:55:20 -07:00
|
|
|
class DeleteAssetMaintenancesTest extends TestCase implements TestsFullMultipleCompaniesSupport, TestsPermissionsRequirement
|
2024-09-12 13:29:10 -07:00
|
|
|
{
|
|
|
|
public function testRequiresPermission()
|
|
|
|
{
|
|
|
|
$assetMaintenance = AssetMaintenance::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->deleteJson(route('api.maintenances.destroy', $assetMaintenance))
|
|
|
|
->assertForbidden();
|
2024-09-16 14:32:38 -07:00
|
|
|
|
|
|
|
$this->assertNotSoftDeleted($assetMaintenance);
|
2024-09-12 13:29:10 -07:00
|
|
|
}
|
|
|
|
|
2024-09-16 16:55:20 -07:00
|
|
|
public function testAdheresToFullMultipleCompaniesSupportScoping()
|
2024-09-12 13:29:10 -07:00
|
|
|
{
|
|
|
|
[$companyA, $companyB] = Company::factory()->count(2)->create();
|
|
|
|
|
|
|
|
$assetMaintenanceA = AssetMaintenance::factory()->create();
|
|
|
|
$assetMaintenanceB = AssetMaintenance::factory()->create();
|
|
|
|
$assetMaintenanceC = AssetMaintenance::factory()->create();
|
|
|
|
|
|
|
|
$assetMaintenanceA->asset->update(['company_id' => $companyA->id]);
|
|
|
|
$assetMaintenanceB->asset->update(['company_id' => $companyB->id]);
|
|
|
|
$assetMaintenanceC->asset->update(['company_id' => $companyB->id]);
|
|
|
|
|
|
|
|
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
|
|
|
|
$userInCompanyA = $companyA->users()->save(User::factory()->editAssets()->make());
|
|
|
|
$userInCompanyB = $companyB->users()->save(User::factory()->editAssets()->make());
|
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
$this->actingAsForApi($userInCompanyA)
|
|
|
|
->deleteJson(route('api.maintenances.destroy', $assetMaintenanceB))
|
|
|
|
->assertStatusMessageIs('error');
|
|
|
|
|
|
|
|
$this->actingAsForApi($userInCompanyB)
|
|
|
|
->deleteJson(route('api.maintenances.destroy', $assetMaintenanceA))
|
|
|
|
->assertStatusMessageIs('error');
|
|
|
|
|
|
|
|
$this->actingAsForApi($superUser)
|
|
|
|
->deleteJson(route('api.maintenances.destroy', $assetMaintenanceC))
|
|
|
|
->assertStatusMessageIs('success');
|
|
|
|
|
2024-09-16 14:20:24 -07:00
|
|
|
$this->assertNotSoftDeleted($assetMaintenanceA);
|
|
|
|
$this->assertNotSoftDeleted($assetMaintenanceB);
|
|
|
|
$this->assertSoftDeleted($assetMaintenanceC);
|
2024-09-12 13:29:10 -07:00
|
|
|
}
|
2024-09-16 14:25:11 -07:00
|
|
|
|
|
|
|
public function testCanDeleteAssetMaintenance()
|
|
|
|
{
|
|
|
|
$assetMaintenance = AssetMaintenance::factory()->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->editAssets()->create())
|
|
|
|
->deleteJson(route('api.maintenances.destroy', $assetMaintenance))
|
|
|
|
->assertStatusMessageIs('success');
|
|
|
|
|
|
|
|
$this->assertSoftDeleted($assetMaintenance);
|
|
|
|
}
|
2024-09-12 13:29:10 -07:00
|
|
|
}
|