@@ -54,6 +54,51 @@ public function test_single_image_upload(): void
5454 Storage::disk ('uploads ' )->assertExists ($ filename );
5555 }
5656
57+ public function test_single_image_upload_updates_old_image (): void
58+ {
59+ $ s = Storage::fake ('uploads ' );
60+ File::ensureDirectoryExists ($ s ->path ('temp ' ));
61+
62+ $ response = $ this ->post ('/api/images ' , [
63+ 'images ' => [
64+ [
65+ 'image ' => UploadedFile::fake ()->createWithContent ('image.jpg ' , $ this ->getFakeImageContent ('jpg ' )),
66+ 'copyright ' => 'Made with test ' ,
67+ 'sort ' => 1 ,
68+ ]
69+ ],
70+ ]);
71+
72+ $ response ->assertJson (function (AssertableJson $ json ) {
73+ $ json ->has ('data ' , 1 , function ($ json ) {
74+ $ json ->has ('id ' )
75+ ->has ('file_path ' )
76+ ->where ('copyright ' , 'Made with test ' )
77+ ->etc ();
78+ });
79+ });
80+
81+ $ filename = $ response ->json ('data.0.file_path ' );
82+
83+ Storage::disk ('uploads ' )->assertExists ($ filename );
84+
85+ $ oldId = $ response ->json ('data.0.id ' );
86+ $ response = $ this ->post ('/api/images ' , [
87+ 'images ' => [
88+ [
89+ 'id ' => $ oldId ,
90+ 'image ' => UploadedFile::fake ()->createWithContent ('image.jpg ' , $ this ->getFakeImageContent ('jpg ' )),
91+ 'copyright ' => 'New image ' ,
92+ 'sort ' => 2 ,
93+ ]
94+ ],
95+ ]);
96+ $ newFilename = $ response ->json ('data.0.file_path ' );
97+
98+ Storage::disk ('uploads ' )->assertExists ($ newFilename );
99+ Storage::disk ('uploads ' )->assertMissing ($ filename );
100+ }
101+
57102 public function test_multiple_image_upload (): void
58103 {
59104 $ s = Storage::fake ('uploads ' );
0 commit comments