diff --git a/resources/views/livewire/association/project-support/show.blade.php b/resources/views/livewire/association/project-support/show.blade.php
index 3ca0a33..a9ee1e3 100644
--- a/resources/views/livewire/association/project-support/show.blade.php
+++ b/resources/views/livewire/association/project-support/show.blade.php
@@ -60,30 +60,32 @@ new class extends Component {
public function handleApprove(): void
{
+ if (! $this->currentPleb) {
+ return;
+ }
+
Vote::query()->updateOrCreate([
'project_proposal_id' => $this->projectProposal->id,
'einundzwanzig_pleb_id' => $this->currentPleb->id,
], [
'value' => true,
]);
- $this->ownVoteExists = Vote::query()
- ->where('project_proposal_id', $this->projectProposal->id)
- ->where('einundzwanzig_pleb_id', $this->currentPleb->id)
- ->exists();
+ $this->ownVoteExists = true;
}
public function handleNotApprove(): void
{
+ if (! $this->currentPleb) {
+ return;
+ }
+
Vote::query()->updateOrCreate([
'project_proposal_id' => $this->projectProposal->id,
'einundzwanzig_pleb_id' => $this->currentPleb->id,
], [
'value' => false,
]);
- $this->ownVoteExists = Vote::query()
- ->where('project_proposal_id', $this->projectProposal->id)
- ->where('einundzwanzig_pleb_id', $this->currentPleb->id)
- ->exists();
+ $this->ownVoteExists = true;
}
}
?>
@@ -144,22 +146,24 @@ new class extends Component {
-
- @if(!$ownVoteExists)
-
-
-
- Zustimmen
-
-
-
- Ablehnen
-
-
- @else
-
Du hast bereits abgestimmt.
- @endif
-
+ @if($isAllowed)
+
+ @if(!$ownVoteExists)
+
+
+
+ Zustimmen
+
+
+
+ Ablehnen
+
+
+ @else
+
Du hast bereits abgestimmt.
+ @endif
+
+ @endif
diff --git a/tests/Feature/Livewire/Association/ProjectSupportTest.php b/tests/Feature/Livewire/Association/ProjectSupportTest.php
index 99043bb..6811258 100644
--- a/tests/Feature/Livewire/Association/ProjectSupportTest.php
+++ b/tests/Feature/Livewire/Association/ProjectSupportTest.php
@@ -304,3 +304,31 @@ it('can handle not approve vote', function () {
expect($vote)->not->toBeNull()
->and($vote->value)->toBeFalse();
});
+
+it('does not throw error when unauthenticated user calls handleApprove', function () {
+ $project = ProjectProposal::factory()->create();
+
+ Livewire::test('association.project-support.show', ['projectProposal' => $project->slug])
+ ->call('handleApprove')
+ ->assertHasNoErrors();
+
+ expect(\App\Models\Vote::where('project_proposal_id', $project->id)->exists())->toBeFalse();
+});
+
+it('does not throw error when unauthenticated user calls handleNotApprove', function () {
+ $project = ProjectProposal::factory()->create();
+
+ Livewire::test('association.project-support.show', ['projectProposal' => $project->slug])
+ ->call('handleNotApprove')
+ ->assertHasNoErrors();
+
+ expect(\App\Models\Vote::where('project_proposal_id', $project->id)->exists())->toBeFalse();
+});
+
+it('hides voting buttons from unauthenticated users', function () {
+ $project = ProjectProposal::factory()->create();
+
+ Livewire::test('association.project-support.show', ['projectProposal' => $project->slug])
+ ->assertDontSee('Zustimmen')
+ ->assertDontSee('Ablehnen');
+});