Skip to content

A free open source IT asset/license management system

Add failing test

Marcus Moore5c08f3a27eb3
diff --git a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
index f05c4389e6..0791b3b422 100644
--- a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
+++ b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
@@ -89,4 +89,32 @@ class BulkAssetCheckoutTest extends TestCase
$this->fail('Asset checkout email was sent when the entire checkout failed.');
}
}
+
+ public function test_prevents_checkouts_checked_out_items()
+ {
+ $asset = Asset::factory()->create();
+ $checkedOutAsset = Asset::factory()->assignedToUser()->create();
+ $existingUserId = $checkedOutAsset->assigned_to;
+
+ $target = User::factory()->create();
+
+ $response = $this->actingAs(User::factory()->superuser()->create())
+ ->post(route('hardware.bulkcheckout.store'), [
+ 'selected_assets' => [
+ $asset->id,
+ $checkedOutAsset->id,
+ ],
+ 'checkout_to_type' => 'user',
+ 'assigned_user' => $target->id,
+ ]);
+
+ $this->assertEquals(
+ $existingUserId,
+ $checkedOutAsset->fresh()->assigned_to,
+ 'Asset was checked out when it should have been prevented.'
+ );
+
+ // ensure redirected back
+ $response->assertRedirectToRoute('hardware.bulkcheckout.show');
+ }
}