@@ -84,7 +84,8 @@ public function test_export_gedcom_does_not_dispatch_without_authenticated_user(
8484 public function test_after_create_dispatches_import_gedcom_for_ged_file (): void
8585 {
8686 Auth::login ($ this ->user );
87- Storage::fake ('private ' );
87+ $ disk = Storage::fake ('private ' );
88+ $ disk ->put ('gedcom-form-imports/test.ged ' , '0 HEAD ' );
8889
8990 $ gedcom = Gedcom::create (['filename ' => 'gedcom-form-imports/test.ged ' ]);
9091
@@ -101,7 +102,8 @@ public function test_after_create_dispatches_import_gedcom_for_ged_file(): void
101102 public function test_after_create_dispatches_gedcom_job_when_filename_is_array (): void
102103 {
103104 Auth::login ($ this ->user );
104- Storage::fake ('private ' );
105+ $ disk = Storage::fake ('private ' );
106+ $ disk ->put ('gedcom-form-imports/test.ged ' , '0 HEAD ' );
105107
106108 // Filament FileUpload may persist as an array even for single-file uploads;
107109 // CreateGedcom::afterCreate must extract the first element safely.
@@ -122,7 +124,8 @@ public function test_after_create_dispatches_gedcom_job_when_filename_is_array()
122124 public function test_after_create_dispatches_import_gramps_xml_for_gramps_file (): void
123125 {
124126 Auth::login ($ this ->user );
125- Storage::fake ('private ' );
127+ $ disk = Storage::fake ('private ' );
128+ $ disk ->put ('gedcom-form-imports/test.gramps ' , '<database/> ' );
126129
127130 $ gedcom = Gedcom::create (['filename ' => 'gedcom-form-imports/test.gramps ' ]);
128131
@@ -153,10 +156,59 @@ public function test_after_create_does_not_dispatch_when_filename_is_empty(): vo
153156 Queue::assertNotPushed (ImportGrampsXml::class);
154157 }
155158
156- public function test_after_create_pre_creates_import_job_before_dispatch (): void
159+ public function test_after_create_does_not_dispatch_when_file_not_found_on_disk (): void
157160 {
158161 Auth::login ($ this ->user );
159162 Storage::fake ('private ' );
163+ // File is NOT placed in the fake disk; afterCreate should abort gracefully.
164+
165+ $ gedcom = Gedcom::create (['filename ' => 'gedcom-form-imports/missing.ged ' ]);
166+
167+ $ page = new CreateGedcom ();
168+ $ page ->record = $ gedcom ;
169+
170+ $ method = new \ReflectionMethod ($ page , 'afterCreate ' );
171+ $ method ->invoke ($ page );
172+
173+ Queue::assertNotPushed (ImportGedcom::class);
174+ Queue::assertNotPushed (ImportGrampsXml::class);
175+ }
176+
177+ public function test_after_create_moves_file_from_livewire_tmp_and_dispatches_job (): void
178+ {
179+ Auth::login ($ this ->user );
180+ $ disk = Storage::fake ('private ' );
181+
182+ // Simulate a file that Livewire stored in its temporary directory instead of
183+ // the final gedcom-form-imports directory (e.g. when Filament's file-move step
184+ // did not run before afterCreate was called).
185+ $ tmpPath = 'livewire-tmp/abcdef-test.ged ' ;
186+ $ disk ->put ($ tmpPath , '0 HEAD ' );
187+
188+ $ gedcom = Gedcom::create (['filename ' => $ tmpPath ]);
189+
190+ $ page = new CreateGedcom ();
191+ $ page ->record = $ gedcom ;
192+
193+ $ method = new \ReflectionMethod ($ page , 'afterCreate ' );
194+ $ method ->invoke ($ page );
195+
196+ // The file should have been moved out of livewire-tmp
197+ $ disk ->assertMissing ($ tmpPath );
198+ $ disk ->assertExists ('gedcom-form-imports/abcdef-test.ged ' );
199+
200+ // The Gedcom record should point to the new location
201+ $ this ->assertEquals ('gedcom-form-imports/abcdef-test.ged ' , $ gedcom ->fresh ()->filename );
202+
203+ // The import job should still be dispatched
204+ Queue::assertPushed (ImportGedcom::class);
205+ }
206+
207+ public function test_after_create_pre_creates_import_job_before_dispatch (): void
208+ {
209+ Auth::login ($ this ->user );
210+ $ disk = Storage::fake ('private ' );
211+ $ disk ->put ('gedcom-form-imports/test.ged ' , '0 HEAD ' );
160212
161213 $ gedcom = Gedcom::create (['filename ' => 'gedcom-form-imports/test.ged ' ]);
162214
@@ -177,7 +229,8 @@ public function test_after_create_pre_creates_import_job_before_dispatch(): void
177229 public function test_after_create_dispatches_gedcom_job_with_slug (): void
178230 {
179231 Auth::login ($ this ->user );
180- Storage::fake ('private ' );
232+ $ disk = Storage::fake ('private ' );
233+ $ disk ->put ('gedcom-form-imports/test.ged ' , '0 HEAD ' );
181234
182235 $ gedcom = Gedcom::create (['filename ' => 'gedcom-form-imports/test.ged ' ]);
183236
@@ -222,3 +275,4 @@ public function test_file_upload_component_accepted_file_types_includes_ged_exte
222275 $ this ->assertContains ('text/plain ' , $ acceptedTypes , 'FileUpload should accept text/plain MIME type ' );
223276 }
224277}
278+
0 commit comments