diff --git a/tests/Feature/Components/Api/DeleteComponentsTest.php b/tests/Feature/Components/Api/DeleteComponentsTest.php new file mode 100644 index 0000000000..98f418449c --- /dev/null +++ b/tests/Feature/Components/Api/DeleteComponentsTest.php @@ -0,0 +1,64 @@ +create(); + + $this->actingAsForApi(User::factory()->create()) + ->deleteJson(route('api.components.destroy', $component)) + ->assertForbidden(); + } + + public function testCanDeleteComponents() + { + $component = Component::factory()->create(); + + $this->actingAsForApi(User::factory()->deleteComponents()->create()) + ->deleteJson(route('api.components.destroy', $component)) + ->assertStatusMessageIs('success'); + + $this->assertTrue($component->fresh()->trashed()); + } + + public function testAdheresToMultipleFullCompanySupportScoping() + { + [$companyA, $companyB] = Company::factory()->count(2)->create(); + + $componentA = Component::factory()->for($companyA)->create(); + $componentB = Component::factory()->for($companyB)->create(); + $componentC = Component::factory()->for($companyB)->create(); + + $superUser = $companyA->users()->save(User::factory()->superuser()->make()); + $userInCompanyA = $companyA->users()->save(User::factory()->deleteComponents()->make()); + $userInCompanyB = $companyB->users()->save(User::factory()->deleteComponents()->make()); + + $this->settings->enableMultipleFullCompanySupport(); + + $this->actingAsForApi($userInCompanyA) + ->deleteJson(route('api.components.destroy', $componentB)) + ->assertStatusMessageIs('error'); + + $this->actingAsForApi($userInCompanyB) + ->deleteJson(route('api.components.destroy', $componentA)) + ->assertStatusMessageIs('error'); + + $this->actingAsForApi($superUser) + ->deleteJson(route('api.components.destroy', $componentC)) + ->assertStatusMessageIs('success'); + + $this->assertNull($componentA->fresh()->deleted_at, 'Component unexpectedly deleted'); + $this->assertNull($componentB->fresh()->deleted_at, 'Component unexpectedly deleted'); + $this->assertNotNull($componentC->fresh()->deleted_at, 'Component was not deleted'); + } +}