Skip to content

Commit

Permalink
Avoid exception, add error when unlocking album. (#2264)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Feb 2, 2024
1 parent e57f003 commit df7457e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/Livewire/Components/Forms/Album/UnlockAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Livewire\Components\Forms\Album;

use App\Actions\Album\Unlock;
use App\Exceptions\UnauthorizedException;
use App\Factories\AlbumFactory;
use App\Http\RuleSets\Album\UnlockAlbumRuleSet;
use App\Livewire\Traits\Notify;
Expand Down Expand Up @@ -73,7 +74,11 @@ public function submit(): void
}

$album = $this->albumFactory->findBaseAlbumOrFail($this->albumID);
$this->unlock->do($album, $this->password);
$this->redirect(route('livewire-gallery-album', ['albumId' => $this->albumID]));
try {
$this->unlock->do($album, $this->password);
$this->redirect(route('livewire-gallery-album', ['albumId' => $this->albumID]));
} catch (UnauthorizedException $e) {
$this->addError('password', 'Wrong password');
}
}
}
8 changes: 6 additions & 2 deletions tests/Livewire/Forms/Album/VisibilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public function testUnlocking(): void
Livewire::actingAs($this->userMayUpload2)->test(UnlockAlbum::class, ['albumID' => $this->album1->id, 'back' => 'something'])
->set('password', 'wrongPassword')
->call('submit')
->assertForbidden();
->assertOk()
->assertSee('Wrong password')
->assertNoRedirect();

Livewire::actingAs($this->userMayUpload2)->test(UnlockAlbum::class, ['albumID' => $this->album1->id, 'back' => 'something'])
->set('password', '')
Expand All @@ -118,6 +120,8 @@ public function testUnlockingUnlockedAlbum(): void
Livewire::actingAs($this->userMayUpload2)->test(UnlockAlbum::class, ['albumID' => $this->album1->id, 'back' => 'something'])
->set('password', 'password')
->call('submit')
->assertForbidden();
->assertOk()
->assertSee('Wrong password')
->assertNoRedirect();
}
}

0 comments on commit df7457e

Please sign in to comment.