From 4222b983c18402dd2c38d44f0bdfa7bf64aac3b3 Mon Sep 17 00:00:00 2001 From: Karan Date: Fri, 23 Oct 2026 16:25:56 +0530 Subject: [PATCH] Rename the upload action so Livewire's own upload helper does not catch it wire:submit="upload" ran Livewire's browser-side $wire.upload() instead of the component method, so Upload sent nothing. --- .../customer-card/customer-card.blade.php | 2 +- .../livewire/customer-card/customer-card.php | 2 +- tests/Feature/ActionNamesTest.php | 23 +++++++++++++++++++ tests/Feature/CustomerCardTest.php | 16 ++++++------- 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 tests/Feature/ActionNamesTest.php diff --git a/resources/views/livewire/customer-card/customer-card.blade.php b/resources/views/livewire/customer-card/customer-card.blade.php index ab379b8..37d8c06 100644 --- a/resources/views/livewire/customer-card/customer-card.blade.php +++ b/resources/views/livewire/customer-card/customer-card.blade.php @@ -51,7 +51,7 @@ class="text-red-600 dark:text-red-400" @if ($this->uploadTypes === []) {{ __('No document types yet. Add them on System, then Add-ons.') }} @else -
+ authorize(Abilities::UPLOAD); abort_if($this->account->trashed(), 403); diff --git a/tests/Feature/ActionNamesTest.php b/tests/Feature/ActionNamesTest.php new file mode 100644 index 0000000..e840277 --- /dev/null +++ b/tests/Feature/ActionNamesTest.php @@ -0,0 +1,23 @@ +getPathname()), $matches); + $actions = [...$actions, ...$matches[1]]; + } + + expect($reserved[1])->toContain('upload') + ->and(array_values(array_intersect(array_unique($actions), $reserved[1])))->toBe([]); +}); diff --git a/tests/Feature/CustomerCardTest.php b/tests/Feature/CustomerCardTest.php index 5531b26..c431d97 100644 --- a/tests/Feature/CustomerCardTest.php +++ b/tests/Feature/CustomerCardTest.php @@ -75,9 +75,9 @@ function card(Account $account): Testable card($this->account) ->set('uploadType', (string) $photo->id) - ->set('uploadFile', UploadedFile::fake()->createWithContent('a.png', ''))->call('upload') + ->set('uploadFile', UploadedFile::fake()->createWithContent('a.png', ''))->call('saveDocument') ->assertHasErrors(['uploadFile']) - ->set('uploadFile', pngUpload('me.png'))->call('upload')->assertHasNoErrors() + ->set('uploadFile', pngUpload('me.png'))->call('saveDocument')->assertHasNoErrors() ->assertSet('uploadType', '')->assertSet('uploadFile', null); expect(Document::query()->where('document_type_id', $photo->id)->sole()->original_name)->toBe('me.png'); @@ -86,10 +86,10 @@ function card(Account $account): Testable it('needs the type and the file in the upload box', function () { $this->actingAs($this->admin); - card($this->account)->call('upload') + card($this->account)->call('saveDocument') ->assertHasErrors(['uploadType' => __('Choose the document type.'), 'uploadFile' => __('Choose the file.')]); card($this->account)->set('uploadType', (string) documentType('Old form', ['active' => false])->id)->set('uploadFile', pngUpload()) - ->call('upload')->assertHasErrors(['uploadType']); + ->call('saveDocument')->assertHasErrors(['uploadType']); }); it('edits the type and number, refusing a taken type', function () { @@ -136,7 +136,7 @@ function card(Account $account): Testable $this->account->delete(); card($this->account)->assertOk()->assertSee('xxxx xxxx 4821')->assertDontSee(__('Choose file')) - ->set('uploadType', (string) $photo->id)->set('uploadFile', pngUpload())->call('upload')->assertForbidden(); + ->set('uploadType', (string) $photo->id)->set('uploadFile', pngUpload())->call('saveDocument')->assertForbidden(); }); it('downloads all current documents as one zip and logs it', function () { @@ -165,7 +165,7 @@ function card(Account $account): Testable card($this->account)->assertSee(__(':type (replaces the current file)', ['type' => 'Aadhaar card'])) ->set('uploadType', (string) $this->aadhaar->id) ->assertSeeHtml('wire:confirm="'.e(__('Replace the :type of :customer? The current file can be restored from Deleted documents.', ['type' => 'Aadhaar card', 'customer' => 'Ramesh Kumar'])).'"') - ->set('uploadFile', pngUpload('sharper.png'))->call('upload')->assertHasNoErrors(); + ->set('uploadFile', pngUpload('sharper.png'))->call('saveDocument')->assertHasNoErrors(); expect($this->document->fresh()->trashed())->toBeTrue() ->and(Document::query()->sole()->original_name)->toBe('sharper.png') @@ -204,7 +204,7 @@ function card(Account $account): Testable $this->actingAs($this->admin); $photo = documentType('Customer photo'); - card($this->account)->set('uploadType', (string) $photo->id)->set('uploadFile', 'documents/1/secret')->call('upload')->assertHasErrors(['uploadFile']); + card($this->account)->set('uploadType', (string) $photo->id)->set('uploadFile', 'documents/1/secret')->call('saveDocument')->assertHasErrors(['uploadFile']); }); it('refuses Upload once the customer is deleted while the card is open', function () { @@ -214,7 +214,7 @@ function card(Account $account): Testable $this->account->delete(); - $card->set('uploadType', (string) $photo->id)->set('uploadFile', pngUpload())->call('upload')->assertForbidden(); + $card->set('uploadType', (string) $photo->id)->set('uploadFile', pngUpload())->call('saveDocument')->assertForbidden(); expect(Document::query()->where('document_type_id', $photo->id)->count())->toBe(0); });