2024-10-17 14:12:22 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Assets\Api;
|
|
|
|
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\AssetModel;
|
|
|
|
use App\Models\Statuslabel;
|
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
2024-10-17 14:31:05 -07:00
|
|
|
use Tests\Support\ProvidesDataForFullMultipleCompanySupportTesting;
|
2024-10-17 14:12:22 -07:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class StoreAssetWithFullMultipleCompanySupportTest extends TestCase
|
|
|
|
{
|
2024-10-17 14:31:05 -07:00
|
|
|
use ProvidesDataForFullMultipleCompanySupportTesting;
|
2024-10-17 14:12:22 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @link https://github.com/snipe/snipe-it/issues/15654
|
|
|
|
*/
|
2024-10-17 14:53:18 -07:00
|
|
|
#[DataProvider('dataForFullMultipleCompanySupportTesting')]
|
2024-10-17 14:12:22 -07:00
|
|
|
public function testAdheresToFullMultipleCompaniesSupportScoping($data)
|
|
|
|
{
|
|
|
|
['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data();
|
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
$response = $this->actingAsForApi($actor)
|
|
|
|
->postJson(route('api.assets.store'), [
|
|
|
|
'asset_tag' => 'random_string',
|
|
|
|
'company_id' => $company->id,
|
|
|
|
'model_id' => AssetModel::factory()->create()->id,
|
|
|
|
'status_id' => Statuslabel::factory()->readyToDeploy()->create()->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$asset = Asset::withoutGlobalScopes()->findOrFail($response['payload']['id']);
|
|
|
|
|
|
|
|
$assertions($asset);
|
|
|
|
}
|
2024-10-21 12:19:48 -07:00
|
|
|
|
|
|
|
#[DataProvider('dataForFullMultipleCompanySupportTesting')]
|
|
|
|
public function testHandlesCompanyIdBeingString($data)
|
|
|
|
{
|
|
|
|
['actor' => $actor, 'company_attempting_to_associate' => $company, 'assertions' => $assertions] = $data();
|
|
|
|
|
|
|
|
$this->settings->enableMultipleFullCompanySupport();
|
|
|
|
|
|
|
|
$response = $this->actingAsForApi($actor)
|
|
|
|
->postJson(route('api.assets.store'), [
|
|
|
|
'asset_tag' => 'random_string',
|
|
|
|
'company_id' => (string) $company->id,
|
|
|
|
'model_id' => AssetModel::factory()->create()->id,
|
|
|
|
'status_id' => Statuslabel::factory()->readyToDeploy()->create()->id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$asset = Asset::withoutGlobalScopes()->findOrFail($response['payload']['id']);
|
|
|
|
|
|
|
|
$assertions($asset);
|
|
|
|
}
|
2024-10-17 14:12:22 -07:00
|
|
|
}
|