Skip to content

A free open source IT asset/license management system

Implement test

Marcus Moore17aab4c4906b
diff --git a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
index 397215f2f3..56866d201c 100644
--- a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
+++ b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
@@ -5,6 +5,7 @@ namespace Tests\Feature\Checkouts\Ui;
use App\Mail\CheckoutAssetMail;
use App\Models\Asset;
use App\Models\Company;
+use App\Models\Location;
use App\Models\User;
use Illuminate\Support\Facades\Mail;
use PHPUnit\Framework\ExpectationFailedException;
@@ -171,7 +172,40 @@ class BulkAssetCheckoutTest extends TestCase
public function test_adheres_to_full_multiple_company_support_when_checking_out_to_location()
{
- $this->markTestIncomplete();
+ $this->settings->enableMultipleFullCompanySupport();
+
+ // create two companies
+ [$companyA, $companyB] = Company::factory()->count(2)->create();
+
+ // create an asset for each company
+ $assetForCompanyA = Asset::factory()->for($companyA)->create();
+ $assetForCompanyB = Asset::factory()->for($companyB)->create();
+
+ $this->assertNull($assetForCompanyA->assigned_to, 'Asset should not be assigned before attempting this test case.');
+ $this->assertNull($assetForCompanyB->assigned_to, 'Asset should not be assigned before attempting this test case.');
+
+ // create a location for one company
+ $locationForCompanyA = Location::factory()->for($companyA)->create();
+
+ // create a super admin and act as them
+ $admin = User::factory()->superuser()->create();
+ // attempt to bulk checkout both items to the user in the company
+ $response = $this->actingAs($admin)
+ ->post(route('hardware.bulkcheckout.store'), [
+ 'selected_assets' => [
+ $assetForCompanyA->id,
+ $assetForCompanyB->id,
+ ],
+ 'checkout_to_type' => 'location',
+ 'assigned_location' => $locationForCompanyA->id,
+ ]);
+
+ // ensure bulk checkout is blocked
+ $this->assertNull($assetForCompanyA->fresh()->assigned_to, 'Asset was checked out across companies.');
+ $this->assertNull($assetForCompanyB->fresh()->assigned_to, 'Asset was checked out across companies.');
+
+ // ensure redirected back
+ $response->assertRedirectToRoute('hardware.bulkcheckout.show');
}
}