diff --git a/app/Actions/Discussion/DeleteDiscussionAction.php b/app/Actions/Discussion/DeleteDiscussionAction.php new file mode 100644 index 00000000..69d225cf --- /dev/null +++ b/app/Actions/Discussion/DeleteDiscussionAction.php @@ -0,0 +1,22 @@ +delete(); + + DB::commit(); + } +} diff --git a/app/Actions/Forum/DeleteThreadAction.php b/app/Actions/Forum/DeleteThreadAction.php new file mode 100644 index 00000000..d08c73ff --- /dev/null +++ b/app/Actions/Forum/DeleteThreadAction.php @@ -0,0 +1,22 @@ +delete(); + + DB::commit(); + } +} diff --git a/app/Livewire/Pages/Discussions/SingleDiscussion.php b/app/Livewire/Pages/Discussions/SingleDiscussion.php index 5fbb2a91..2ed1a408 100644 --- a/app/Livewire/Pages/Discussions/SingleDiscussion.php +++ b/app/Livewire/Pages/Discussions/SingleDiscussion.php @@ -5,6 +5,7 @@ namespace App\Livewire\Pages\Discussions; use App\Actions\Discussion\ConvertDiscussionToThreadAction; +use App\Actions\Discussion\DeleteDiscussionAction; use App\Models\Discussion; use Filament\Actions\Action; use Filament\Actions\Concerns\InteractsWithActions; @@ -80,7 +81,12 @@ public function deleteAction(): Action ->authorize('delete', $this->discussion) ->requiresConfirmation() ->successNotificationTitle(__('notifications.discussion.deleted')) - ->successRedirectUrl(route('discussions.index')); + ->action(function (): void { + + app(DeleteDiscussionAction::class)->execute($this->discussion); + + $this->redirectRoute('discussions.index', navigate: true); + }); } public function render(): View diff --git a/app/Livewire/Pages/Forum/DetailThread.php b/app/Livewire/Pages/Forum/DetailThread.php index cd0b2df5..90a82bd0 100644 --- a/app/Livewire/Pages/Forum/DetailThread.php +++ b/app/Livewire/Pages/Forum/DetailThread.php @@ -4,6 +4,7 @@ namespace App\Livewire\Pages\Forum; +use App\Actions\Forum\DeleteThreadAction; use App\Models\Thread; use Filament\Actions\Action; use Filament\Actions\Concerns\InteractsWithActions; @@ -53,7 +54,8 @@ public function deleteAction(): Action ->authorize('delete', $this->thread) ->requiresConfirmation() ->action(function (): void { - $this->thread->delete(); + + app(DeleteThreadAction::class)->execute($this->thread); $this->redirectRoute('forum.index', navigate: true); }); diff --git a/composer.lock b/composer.lock index 106578b2..f21c8fe9 100644 --- a/composer.lock +++ b/composer.lock @@ -4532,16 +4532,16 @@ }, { "name": "laravel/framework", - "version": "v11.35.1", + "version": "v11.36.1", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "dcfa130ede1a6fa4343dc113410963e791ad34fb" + "reference": "df06f5163f4550641fdf349ebc04916a61135a64" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/dcfa130ede1a6fa4343dc113410963e791ad34fb", - "reference": "dcfa130ede1a6fa4343dc113410963e791ad34fb", + "url": "https://api.github.com/repos/laravel/framework/zipball/df06f5163f4550641fdf349ebc04916a61135a64", + "reference": "df06f5163f4550641fdf349ebc04916a61135a64", "shasum": "" }, "require": { @@ -4562,7 +4562,7 @@ "guzzlehttp/uri-template": "^1.0", "laravel/prompts": "^0.1.18|^0.2.0|^0.3.0", "laravel/serializable-closure": "^1.3|^2.0", - "league/commonmark": "^2.2.1", + "league/commonmark": "^2.6", "league/flysystem": "^3.25.1", "league/flysystem-local": "^3.25.1", "league/uri": "^7.5.1", @@ -4577,7 +4577,7 @@ "symfony/console": "^7.0.3", "symfony/error-handler": "^7.0.3", "symfony/finder": "^7.0.3", - "symfony/http-foundation": "^7.0.3", + "symfony/http-foundation": "^7.2.0", "symfony/http-kernel": "^7.0.3", "symfony/mailer": "^7.0.3", "symfony/mime": "^7.0.3", @@ -4743,7 +4743,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-12-12T18:25:58+00:00" + "time": "2024-12-17T22:32:08+00:00" }, { "name": "laravel/prompts", @@ -4806,16 +4806,16 @@ }, { "name": "laravel/sanctum", - "version": "v4.0.6", + "version": "v4.0.7", "source": { "type": "git", "url": "https://github.com/laravel/sanctum.git", - "reference": "9e069e36d90b1e1f41886efa0fe9800a6b354694" + "reference": "698064236a46df016e64a7eb059b1414e0b281df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/sanctum/zipball/9e069e36d90b1e1f41886efa0fe9800a6b354694", - "reference": "9e069e36d90b1e1f41886efa0fe9800a6b354694", + "url": "https://api.github.com/repos/laravel/sanctum/zipball/698064236a46df016e64a7eb059b1414e0b281df", + "reference": "698064236a46df016e64a7eb059b1414e0b281df", "shasum": "" }, "require": { @@ -4866,20 +4866,20 @@ "issues": "https://github.com/laravel/sanctum/issues", "source": "https://github.com/laravel/sanctum" }, - "time": "2024-11-26T21:18:33+00:00" + "time": "2024-12-11T16:40:21+00:00" }, { "name": "laravel/serializable-closure", - "version": "v2.0.0", + "version": "v2.0.1", "source": { "type": "git", "url": "https://github.com/laravel/serializable-closure.git", - "reference": "0d8d3d8086984996df86596a86dea60398093a81" + "reference": "613b2d4998f85564d40497e05e89cb6d9bd1cbe8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/0d8d3d8086984996df86596a86dea60398093a81", - "reference": "0d8d3d8086984996df86596a86dea60398093a81", + "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/613b2d4998f85564d40497e05e89cb6d9bd1cbe8", + "reference": "613b2d4998f85564d40497e05e89cb6d9bd1cbe8", "shasum": "" }, "require": { @@ -4927,20 +4927,20 @@ "issues": "https://github.com/laravel/serializable-closure/issues", "source": "https://github.com/laravel/serializable-closure" }, - "time": "2024-11-19T01:38:44+00:00" + "time": "2024-12-16T15:26:28+00:00" }, { "name": "laravel/socialite", - "version": "v5.16.0", + "version": "v5.16.1", "source": { "type": "git", "url": "https://github.com/laravel/socialite.git", - "reference": "40a2dc98c53d9dc6d55eadb0d490d3d72b73f1bf" + "reference": "4e5be83c0b3ecf81b2ffa47092e917d1f79dce71" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/socialite/zipball/40a2dc98c53d9dc6d55eadb0d490d3d72b73f1bf", - "reference": "40a2dc98c53d9dc6d55eadb0d490d3d72b73f1bf", + "url": "https://api.github.com/repos/laravel/socialite/zipball/4e5be83c0b3ecf81b2ffa47092e917d1f79dce71", + "reference": "4e5be83c0b3ecf81b2ffa47092e917d1f79dce71", "shasum": "" }, "require": { @@ -4950,7 +4950,7 @@ "illuminate/contracts": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", "illuminate/http": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", - "league/oauth1-client": "^1.10.1", + "league/oauth1-client": "^1.11", "php": "^7.2|^8.0", "phpseclib/phpseclib": "^3.0" }, @@ -4999,7 +4999,7 @@ "issues": "https://github.com/laravel/socialite/issues", "source": "https://github.com/laravel/socialite" }, - "time": "2024-09-03T09:46:57+00:00" + "time": "2024-12-11T16:43:51+00:00" }, { "name": "laravel/tinker", @@ -5403,16 +5403,16 @@ }, { "name": "league/csv", - "version": "9.20.0", + "version": "9.20.1", "source": { "type": "git", "url": "https://github.com/thephpleague/csv.git", - "reference": "553579df208641ada6ffb450b3a151e2fcfa4f31" + "reference": "491d1e79e973a7370c7571dc0fe4a7241f4936ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/csv/zipball/553579df208641ada6ffb450b3a151e2fcfa4f31", - "reference": "553579df208641ada6ffb450b3a151e2fcfa4f31", + "url": "https://api.github.com/repos/thephpleague/csv/zipball/491d1e79e973a7370c7571dc0fe4a7241f4936ee", + "reference": "491d1e79e973a7370c7571dc0fe4a7241f4936ee", "shasum": "" }, "require": { @@ -5486,7 +5486,7 @@ "type": "github" } ], - "time": "2024-12-13T15:49:27+00:00" + "time": "2024-12-18T10:11:15+00:00" }, { "name": "league/flysystem", @@ -13946,16 +13946,16 @@ }, { "name": "ysfkaya/filament-phone-input", - "version": "v3.1.3", + "version": "v3.1.4", "source": { "type": "git", "url": "https://github.com/ysfkaya/filament-phone-input.git", - "reference": "32157fb8ae18f9bb47b2db439143aaa1eb2dd04f" + "reference": "f3ec86f521a9dfbb404defd4ff8117c02e275b04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ysfkaya/filament-phone-input/zipball/32157fb8ae18f9bb47b2db439143aaa1eb2dd04f", - "reference": "32157fb8ae18f9bb47b2db439143aaa1eb2dd04f", + "url": "https://api.github.com/repos/ysfkaya/filament-phone-input/zipball/f3ec86f521a9dfbb404defd4ff8117c02e275b04", + "reference": "f3ec86f521a9dfbb404defd4ff8117c02e275b04", "shasum": "" }, "require": { @@ -14004,9 +14004,9 @@ ], "support": { "issues": "https://github.com/ysfkaya/filament-phone-input/issues", - "source": "https://github.com/ysfkaya/filament-phone-input/tree/v3.1.3" + "source": "https://github.com/ysfkaya/filament-phone-input/tree/v3.1.4" }, - "time": "2024-12-14T16:45:59+00:00" + "time": "2024-12-17T16:54:03+00:00" } ], "packages-dev": [ @@ -14444,16 +14444,16 @@ }, { "name": "laravel/breeze", - "version": "v2.2.6", + "version": "v2.3.0", "source": { "type": "git", "url": "https://github.com/laravel/breeze.git", - "reference": "907b12160d1b8b8213e7e2e011987fffb5567edc" + "reference": "d59702967b9ae21879df905d691a50132966c4ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/breeze/zipball/907b12160d1b8b8213e7e2e011987fffb5567edc", - "reference": "907b12160d1b8b8213e7e2e011987fffb5567edc", + "url": "https://api.github.com/repos/laravel/breeze/zipball/d59702967b9ae21879df905d691a50132966c4ff", + "reference": "d59702967b9ae21879df905d691a50132966c4ff", "shasum": "" }, "require": { @@ -14501,7 +14501,7 @@ "issues": "https://github.com/laravel/breeze/issues", "source": "https://github.com/laravel/breeze" }, - "time": "2024-11-20T15:01:15+00:00" + "time": "2024-12-14T21:21:42+00:00" }, { "name": "laravel/pint", @@ -15406,16 +15406,16 @@ }, { "name": "phpstan/phpstan", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "46b4d3529b12178112d9008337beda0cc2a1a6b4" + "reference": "50d276fc3bf1430ec315f2f109bbde2769821524" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/46b4d3529b12178112d9008337beda0cc2a1a6b4", - "reference": "46b4d3529b12178112d9008337beda0cc2a1a6b4", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/50d276fc3bf1430ec315f2f109bbde2769821524", + "reference": "50d276fc3bf1430ec315f2f109bbde2769821524", "shasum": "" }, "require": { @@ -15460,7 +15460,7 @@ "type": "github" } ], - "time": "2024-11-28T22:19:37+00:00" + "time": "2024-12-17T17:14:01+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/tests/Feature/Livewire/Components/Slideovers/DiscussionFormTest.php b/tests/Feature/Livewire/Components/Slideovers/DiscussionFormTest.php index 1bb91a89..8368ac3d 100644 --- a/tests/Feature/Livewire/Components/Slideovers/DiscussionFormTest.php +++ b/tests/Feature/Livewire/Components/Slideovers/DiscussionFormTest.php @@ -22,7 +22,7 @@ ->assertSuccessful(); }); - it('user can create a new thread', function (): void { + it('user can create a new discussion', function (): void { $user = $this->login(); $tags = Tag::factory()->count(3)->create(); @@ -36,10 +36,13 @@ ->assertHasNoFormErrors(); $discussion = Discussion::query()->first(); + $user->refresh(); expect($discussion?->user)->toBeInstanceOf(User::class) ->and($discussion?->user->is($user)) - ->toBeTrue(); + ->toBeTrue() + ->and($user->getPoints()) + ->toBe(20); }); it('validate forms input', function (): void { diff --git a/tests/Feature/Livewire/Components/Slideovers/ThreadFormTest.php b/tests/Feature/Livewire/Components/Slideovers/ThreadFormTest.php index 6d9abcaa..76eb0df7 100644 --- a/tests/Feature/Livewire/Components/Slideovers/ThreadFormTest.php +++ b/tests/Feature/Livewire/Components/Slideovers/ThreadFormTest.php @@ -75,10 +75,13 @@ ->assertHasNoFormErrors(); $thread = Thread::query()->first(); + $user->refresh(); expect($thread?->user)->toBeInstanceOf(User::class) ->and($thread?->user->is($user)) - ->toBeTrue(); + ->toBeTrue() + ->and($user->getPoints()) + ->toBe(55); }); it('user cannot create thread with and unverified email address', function (): void { diff --git a/tests/Feature/Livewire/Pages/Discussion/SingleDiscussionTest.php b/tests/Feature/Livewire/Pages/Discussion/SingleDiscussionTest.php new file mode 100644 index 00000000..f9daaa11 --- /dev/null +++ b/tests/Feature/Livewire/Pages/Discussion/SingleDiscussionTest.php @@ -0,0 +1,34 @@ +login(); + $discussionData = CreateDiscussionData::from([ + 'title' => 'Discussion title', + 'body' => 'Discussion body', + 'tags' => [], + ]); + + $discussion = app(CreateDiscussionAction::class)->execute($discussionData); + + Livewire::test(SingleDiscussion::class, ['discussion' => $discussion]) + ->callAction('deleteAction') + ->assertStatus(200); + + $user->refresh(); + + expect($user->getPoints()) + ->toBe(0); + +}); diff --git a/tests/Feature/Livewire/Pages/Forum/DetailThreadTest.php b/tests/Feature/Livewire/Pages/Forum/DetailThreadTest.php index e6ef6cf1..397bef83 100644 --- a/tests/Feature/Livewire/Pages/Forum/DetailThreadTest.php +++ b/tests/Feature/Livewire/Pages/Forum/DetailThreadTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use App\Gamify\Points\ThreadCreated; use App\Livewire\Components\Forum\ReplyForm; use App\Livewire\Pages\Forum\DetailThread; use App\Models\Thread; @@ -18,11 +19,18 @@ $user = $this->login(); $thread = Thread::factory(['user_id' => $user->id])->create(); + givePoint(new ThreadCreated($thread)); + Livewire::test(DetailThread::class, ['thread' => $thread]) ->callAction('delete') ->assertStatus(200) ->assertRedirect(route('forum.index')); + $user->refresh(); + + expect($user->getPoints()) + ->toBe(0); + $this->assertModelMissing($thread); });