Skip to content

A free open source IT asset/license management system

More tests

snipe52dde3c73dad
diff --git a/tests/Feature/Accessories/AccessoryArchiveValidationTest.php b/tests/Feature/Accessories/AccessoryArchiveValidationTest.php
index 35504a7eae..89dd76dc7b 100644
--- a/tests/Feature/Accessories/AccessoryArchiveValidationTest.php
+++ b/tests/Feature/Accessories/AccessoryArchiveValidationTest.php
@@ -82,6 +82,22 @@ class AccessoryArchiveValidationTest extends TestCase
$this->assertSame(CheckoutRequestState::Canceled, $pending->state);
}
+ public function test_deleting_accessory_auto_cancels_pending_requests(): void
+ {
+ $accessory = Accessory::factory()->create();
+ $pending = CheckoutRequest::factory()->create([
+ 'user_id' => User::factory()->create()->id,
+ 'requestable_id' => $accessory->id,
+ 'requestable_type' => Accessory::class,
+ ]);
+
+ $accessory->delete();
+
+ $pending->refresh();
+ $this->assertNotNull($pending->canceled_at);
+ $this->assertSame(CheckoutRequestState::Canceled, $pending->state);
+ }
+
public function test_archiving_does_not_touch_already_canceled_requests(): void
{
$accessory = Accessory::factory()->create();
diff --git a/tests/Feature/Components/ComponentArchiveValidationTest.php b/tests/Feature/Components/ComponentArchiveValidationTest.php
index 88ccf084ba..e7a3e82d59 100644
--- a/tests/Feature/Components/ComponentArchiveValidationTest.php
+++ b/tests/Feature/Components/ComponentArchiveValidationTest.php
@@ -99,6 +99,22 @@ class ComponentArchiveValidationTest extends TestCase
$this->assertSame(CheckoutRequestState::Canceled, $pending->state);
}
+ public function test_deleting_component_auto_cancels_pending_requests(): void
+ {
+ $component = Component::factory()->create();
+ $pending = CheckoutRequest::factory()->create([
+ 'user_id' => User::factory()->create()->id,
+ 'requestable_id' => $component->id,
+ 'requestable_type' => Component::class,
+ ]);
+
+ $component->delete();
+
+ $pending->refresh();
+ $this->assertNotNull($pending->canceled_at);
+ $this->assertSame(CheckoutRequestState::Canceled, $pending->state);
+ }
+
public function test_archiving_does_not_touch_already_canceled_requests(): void
{
$component = Component::factory()->create();
diff --git a/tests/Feature/Consumables/ConsumableArchiveValidationTest.php b/tests/Feature/Consumables/ConsumableArchiveValidationTest.php
index 7e2389dc93..4fd74d434f 100644
--- a/tests/Feature/Consumables/ConsumableArchiveValidationTest.php
+++ b/tests/Feature/Consumables/ConsumableArchiveValidationTest.php
@@ -100,6 +100,22 @@ class ConsumableArchiveValidationTest extends TestCase
$this->assertSame(CheckoutRequestState::Canceled, $pending->state);
}
+ public function test_deleting_consumable_auto_cancels_pending_requests(): void
+ {
+ $consumable = Consumable::factory()->create();
+ $pending = CheckoutRequest::factory()->create([
+ 'user_id' => User::factory()->create()->id,
+ 'requestable_id' => $consumable->id,
+ 'requestable_type' => Consumable::class,
+ ]);
+
+ $consumable->delete();
+
+ $pending->refresh();
+ $this->assertNotNull($pending->canceled_at);
+ $this->assertSame(CheckoutRequestState::Canceled, $pending->state);
+ }
+
public function test_archiving_does_not_touch_already_canceled_requests(): void
{
$consumable = Consumable::factory()->create();