A free open source IT asset/license management system
Fixed tests for S3 compatibility changes
snipec94a7c111c96
diff --git a/database/factories/ImportFactory.php b/database/factories/ImportFactory.phpindex 1e58f3b938..bbbee885d3 100644--- a/database/factories/ImportFactory.php+++ b/database/factories/ImportFactory.php@@ -2,9 +2,11 @@namespace Database\Factories;+use App\Enums\FileStorage;use App\Models\Import;use App\Models\User;use Illuminate\Database\Eloquent\Factories\Factory;+use Illuminate\Support\Facades\Storage;use Illuminate\Support\Str;use Tests\Support\Importing;@@ -250,4 +252,27 @@ class ImportFactory extends Factoryreturn $attributes;});}++ /**+ * Lay down a trivial CSV at the generated file_path so tests that+ * hit ItemImportRequest::import() don't 500 on the "file missing+ * on disk" guard added for S3-backed private disks. Pre-S3, the+ * importer silently treated a missing path as empty CSV content;+ * the guard now returns an error early, so permission-style tests+ * (which only care that the endpoint doesn't 403) need an actual+ * file behind the Import row. CleansUpImportFiles tears it back+ * down afterApplicationDestroyed.+ */+ public function withStubFile(): static+ {+ return $this->afterCreating(function (Import $import) {+ // Header-only CSV: zero data rows means no per-row+ // importer validation runs, so the request returns 200+ // regardless of import type. Enough to prove the file is+ // reachable - the dedicated per-type tests that assert+ // actual row shape use ImportFileBuilder for real content.+ $storedPath = FileStorage::Imports->privateStorageKey().$import->file_path;+ Storage::put($storedPath, "col\n");+ });+ }}diff --git a/tests/Feature/Importing/Api/ImportAccessoriesTest.php b/tests/Feature/Importing/Api/ImportAccessoriesTest.phpindex 482ec39df3..03e3a36979 100644--- a/tests/Feature/Importing/Api/ImportAccessoriesTest.php+++ b/tests/Feature/Importing/Api/ImportAccessoriesTest.php@@ -42,7 +42,7 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio{$this->actingAsForApi(User::factory()->canImport()->create());- $import = Import::factory()->accessory()->create();+ $import = Import::factory()->accessory()->withStubFile()->create();$this->importFileResponse(['import' => $import->id])->assertOk();}diff --git a/tests/Feature/Importing/Api/ImportAssetsTest.php b/tests/Feature/Importing/Api/ImportAssetsTest.phpindex d03cde41c1..b9b93b8b3c 100644--- a/tests/Feature/Importing/Api/ImportAssetsTest.php+++ b/tests/Feature/Importing/Api/ImportAssetsTest.php@@ -46,7 +46,7 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq{$this->actingAsForApi(User::factory()->canImport()->create());- $import = Import::factory()->asset()->create();+ $import = Import::factory()->asset()->withStubFile()->create();$this->importFileResponse(['import' => $import->id])->assertOk();}@@ -143,8 +143,8 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq#[Test]public function csv_import_rejects_asset_row_without_serial_when_model_requires_serial(): void{- $modelName = 'RequireSerialModel-' . Str::random(6);- $modelNumber = 'MN-' . Str::random(6);+ $modelName = 'RequireSerialModel-'.Str::random(6);+ $modelNumber = 'MN-'.Str::random(6);AssetModel::factory()->create(['name' => $modelName,'model_number' => $modelNumber,@@ -177,8 +177,8 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq#[Test]public function csv_import_accepts_asset_row_without_serial_when_model_does_not_require_serial(): void{- $modelName = 'OptionalSerialModel-' . Str::random(6);- $modelNumber = 'MN-' . Str::random(6);+ $modelName = 'OptionalSerialModel-'.Str::random(6);+ $modelNumber = 'MN-'.Str::random(6);AssetModel::factory()->create(['name' => $modelName,'model_number' => $modelNumber,diff --git a/tests/Feature/Importing/Api/ImportComponentsTest.php b/tests/Feature/Importing/Api/ImportComponentsTest.phpindex b2673bc051..52938c7c86 100644--- a/tests/Feature/Importing/Api/ImportComponentsTest.php+++ b/tests/Feature/Importing/Api/ImportComponentsTest.php@@ -44,7 +44,7 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission{$this->actingAsForApi(User::factory()->canImport()->create());- $import = Import::factory()->component()->create();+ $import = Import::factory()->component()->withStubFile()->create();$this->importFileResponse(['import' => $import->id])->assertOk();}diff --git a/tests/Feature/Importing/Api/ImportConsumablesTest.php b/tests/Feature/Importing/Api/ImportConsumablesTest.phpindex fa5ecee9f4..0cca5fb629 100644--- a/tests/Feature/Importing/Api/ImportConsumablesTest.php+++ b/tests/Feature/Importing/Api/ImportConsumablesTest.php@@ -42,7 +42,7 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio{$this->actingAsForApi(User::factory()->canImport()->create());- $import = Import::factory()->consumable()->create();+ $import = Import::factory()->consumable()->withStubFile()->create();$this->importFileResponse(['import' => $import->id])->assertOk();}diff --git a/tests/Feature/Importing/Api/ImportLicenseTest.php b/tests/Feature/Importing/Api/ImportLicenseTest.phpindex e1a7eb83d7..421850bebe 100644--- a/tests/Feature/Importing/Api/ImportLicenseTest.php+++ b/tests/Feature/Importing/Api/ImportLicenseTest.php@@ -43,7 +43,7 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe{$this->actingAsForApi(User::factory()->canImport()->create());- $import = Import::factory()->license()->create();+ $import = Import::factory()->license()->withStubFile()->create();$this->importFileResponse(['import' => $import->id])->assertOk();}diff --git a/tests/Feature/Importing/Api/ImportUsersTest.php b/tests/Feature/Importing/Api/ImportUsersTest.phpindex 9a52775cf5..b1208a97dc 100644--- a/tests/Feature/Importing/Api/ImportUsersTest.php+++ b/tests/Feature/Importing/Api/ImportUsersTest.php@@ -45,7 +45,7 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ{$this->actingAsForApi(User::factory()->canImport()->create());- $import = Import::factory()->users()->create();+ $import = Import::factory()->users()->withStubFile()->create();$this->importFileResponse(['import' => $import->id])->assertOk();}