Add test case

This commit is contained in:
Marcus Moore 2024-04-10 15:47:26 -07:00
parent 6d572424ac
commit 4434de6241
No known key found for this signature in database
2 changed files with 23 additions and 1 deletions

View file

@ -92,7 +92,6 @@ class AssetCheckoutController extends Controller
$settings = \App\Models\Setting::getSettings();
// We have to check whether $target->company_id is null here since locations don't have a company yet
// @todo: test this
if (($settings->full_multiple_companies_support) && ((!is_null($target->company_id)) && (!is_null($asset->company_id)))) {
if ($target->company_id != $asset->company_id){
return redirect()->to("hardware/$assetId/checkout")->with('error', trans('general.error_user_company'));

View file

@ -4,6 +4,7 @@ namespace Tests\Feature\Checkouts;
use App\Events\CheckoutableCheckedOut;
use App\Models\Asset;
use App\Models\Company;
use App\Models\LicenseSeat;
use App\Models\Location;
use App\Models\Statuslabel;
@ -169,6 +170,28 @@ class AssetCheckoutTest extends TestCase
});
}
public function testCannotCheckoutAcrossCompaniesWhenFullCompanySupportEnabled()
{
Event::fake([CheckoutableCheckedOut::class]);
$this->settings->enableMultipleFullCompanySupport();
$assetCompany = Company::factory()->create();
$userCompany = Company::factory()->create();
$user = User::factory()->for($userCompany)->create();
$asset = Asset::factory()->for($assetCompany)->create();
$this->actingAs(User::factory()->superuser()->create())
->post(route('hardware.checkout.store', $asset), [
'checkout_to_type' => 'user',
'assigned_user' => $user->id,
])
->assertRedirect(route('hardware.checkout.store', $asset));
Event::assertNotDispatched(CheckoutableCheckedOut::class);
}
public function testLicenseSeatsAreAssignedToUserUponCheckout()
{
$asset = Asset::factory()->create();