diff --git a/tests/Feature/Importing/Api/ImportLicenseTest.php b/tests/Feature/Importing/Api/ImportLicenseTest.php index c57446449c..daf593b474 100644 --- a/tests/Feature/Importing/Api/ImportLicenseTest.php +++ b/tests/Feature/Importing/Api/ImportLicenseTest.php @@ -349,10 +349,15 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe // Re-import with a CSV that only has the identity fields plus one // updated field. All other columns are absent from the CSV, so // their DB values must be preserved. + // A short static order number keeps the assertion within License's + // order_number varchar(50) limit regardless of what the initial row + // faker produced. Prefixing the faker value overflowed on some seeds. + $newOrderNumber = 'UPDATED-ORDER-123'; + $partialRow = [ 'licenseName' => $initialRow['licenseName'], 'serialNumber' => $initialRow['serialNumber'], - 'orderNumber' => 'UPDATED-'.$initialRow['orderNumber'], + 'orderNumber' => $newOrderNumber, ]; $partialFile = new ImportFileBuilder([$partialRow]); $partialImport = Import::factory()->license()->create([ @@ -364,7 +369,7 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe ])->assertOk(); $license->refresh(); - $this->assertEquals('UPDATED-'.$initialRow['orderNumber'], $license->order_number); + $this->assertEquals($newOrderNumber, $license->order_number); $this->assertEquals($originalEmail, $license->license_email); $this->assertEquals($originalNotes, $license->notes); $this->assertEquals($originalExpirationDate, $license->expiration_date?->toDateString()); diff --git a/tests/Feature/Livewire/ImporterTest.php b/tests/Feature/Livewire/ImporterTest.php index e77b2889b2..1068075a09 100644 --- a/tests/Feature/Livewire/ImporterTest.php +++ b/tests/Feature/Livewire/ImporterTest.php @@ -11,6 +11,32 @@ use Tests\TestCase; class ImporterTest extends TestCase { + /** + * Write a minimal CSV file at the imports path an Import record points + * to, so selectFile()'s file-existence guard passes. The guard was added + * to block the wizard when a demo-seeded Import references a file that + * was deleted outside Snipe-IT (e.g. by git clean). Tests that seed + * factory Imports without a real file need to plant one here to exercise + * the code path beyond the guard. + */ + protected function writeFakeImportFile(Import $import, string $csvBody = "a,b,c\n1,2,3\n"): void + { + $path = config('app.private_uploads').'/imports/'.$import->file_path; + file_put_contents($path, $csvBody); + $this->fakeImportPaths[] = $path; + } + + /** @var array */ + protected array $fakeImportPaths = []; + + protected function tearDown(): void + { + foreach ($this->fakeImportPaths as $path) { + @unlink($path); + } + parent::tearDown(); + } + public function test_renders_successfully() { Livewire::actingAs(User::factory()->canImport()->create()) @@ -238,6 +264,7 @@ class ImporterTest extends TestCase 'header_row' => ['my_column'], 'import_type' => 'asset', ]); + $this->writeFakeImportFile($mine, "my_column\nvalue\n"); Livewire::actingAs($me) ->test(Importer::class) @@ -275,6 +302,7 @@ class ImporterTest extends TestCase 'created_by' => $user->id, 'header_row' => ['asset tag'], ]); + $this->writeFakeImportFile($import, "asset tag\nAH-1\n"); Livewire::actingAs($user) ->test(Importer::class) @@ -470,6 +498,7 @@ class ImporterTest extends TestCase 'import_type' => 'user', 'header_row' => ['First Name', 'Username', 'Email'], ]); + $this->writeFakeImportFile($import, "First Name,Username,Email\nAlice,alice,alice@example.com\n"); Livewire::actingAs($user) ->test(Importer::class) @@ -495,6 +524,7 @@ class ImporterTest extends TestCase 'import_type' => 'asset', 'header_row' => ['asset_tag', 'serial_number', 'purchase_cost'], ]); + $this->writeFakeImportFile($import, "asset_tag,serial_number,purchase_cost\nAH-1,ser-1,100\n"); Livewire::actingAs($user) ->test(Importer::class)