Skip to content

Commit 275cf46

Browse files
committed
Add tests for delete asset endpoint
1 parent 5c2660b commit 275cf46

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Tests\Feature\Assets\Api;
4+
5+
use App\Models\Asset;
6+
use App\Models\Company;
7+
use App\Models\User;
8+
use Tests\Concerns\TestsMultipleFullCompanySupport;
9+
use Tests\Concerns\TestsPermissionsRequirement;
10+
use Tests\TestCase;
11+
12+
class DeleteAssetTest extends TestCase implements TestsMultipleFullCompanySupport, TestsPermissionsRequirement
13+
{
14+
public function testRequiresPermission()
15+
{
16+
$asset = Asset::factory()->create();
17+
18+
$this->actingAsForApi(User::factory()->create())
19+
->deleteJson(route('api.assets.destroy', $asset))
20+
->assertForbidden();
21+
}
22+
23+
public function testCanDeleteAsset()
24+
{
25+
$asset = Asset::factory()->create();
26+
27+
$this->actingAsForApi(User::factory()->deleteAssets()->create())
28+
->deleteJson(route('api.assets.destroy', $asset))
29+
->assertStatusMessageIs('success');
30+
31+
$this->assertTrue($asset->fresh()->trashed());
32+
}
33+
34+
public function testCannotDeleteAssetThatIsCheckedOut()
35+
{
36+
$this->markTestSkipped('This behavior is not functioning yet.');
37+
}
38+
39+
public function testAdheresToMultipleFullCompanySupportScoping()
40+
{
41+
[$companyA, $companyB] = Company::factory()->count(2)->create();
42+
43+
$assetA = Asset::factory()->for($companyA)->create();
44+
$assetB = Asset::factory()->for($companyB)->create();
45+
$assetC = Asset::factory()->for($companyB)->create();
46+
47+
$superUser = $companyA->users()->save(User::factory()->superuser()->make());
48+
$userInCompanyA = $companyA->users()->save(User::factory()->deleteAssets()->make());
49+
$userInCompanyB = $companyB->users()->save(User::factory()->deleteAssets()->make());
50+
51+
$this->settings->enableMultipleFullCompanySupport();
52+
53+
$this->actingAsForApi($userInCompanyA)
54+
->deleteJson(route('api.assets.destroy', $assetB))
55+
->assertStatusMessageIs('error');
56+
57+
$this->actingAsForApi($userInCompanyB)
58+
->deleteJson(route('api.assets.destroy', $assetA))
59+
->assertStatusMessageIs('error');
60+
61+
$this->actingAsForApi($superUser)
62+
->deleteJson(route('api.assets.destroy', $assetC))
63+
->assertStatusMessageIs('success');
64+
65+
$this->assertNull($assetA->fresh()->deleted_at, 'Asset unexpectedly deleted');
66+
$this->assertNull($assetB->fresh()->deleted_at, 'Asset unexpectedly deleted');
67+
$this->assertNotNull($assetC->fresh()->deleted_at, 'Asset was not deleted');
68+
}
69+
}

0 commit comments

Comments
 (0)