From c8a7620d974f2afba51f891442d507adec7f407e Mon Sep 17 00:00:00 2001 From: "Pierluigi Cau (PG)" Date: Tue, 28 Jan 2025 09:08:59 +0800 Subject: [PATCH 1/8] Add notification for deployment completion Add notification for deployment completion status. * Create `DeploymentCompleted` notification class in `app/Notifications/DeploymentCompleted.php` to handle deployment completion notifications. * Update `app/Actions/Site/Deploy.php` to send `DeploymentCompleted` notification using `Notifier` when a deployment completes or fails. * Import `Notifier` and `DeploymentCompleted` classes in `app/Actions/Site/Deploy.php`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/vitodeploy/vito?shareId=XXXX-XXXX-XXXX-XXXX). --- app/Actions/Site/Deploy.php | 6 ++- app/Notifications/DeploymentCompleted.php | 49 +++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/Notifications/DeploymentCompleted.php diff --git a/app/Actions/Site/Deploy.php b/app/Actions/Site/Deploy.php index 1c3faca3..79fdce2c 100644 --- a/app/Actions/Site/Deploy.php +++ b/app/Actions/Site/Deploy.php @@ -5,9 +5,11 @@ use App\Enums\DeploymentStatus; use App\Exceptions\DeploymentScriptIsEmptyException; use App\Exceptions\SSHError; +use App\Facades\Notifier; use App\Models\Deployment; use App\Models\ServerLog; use App\Models\Site; +use App\Notifications\DeploymentCompleted; class Deploy { @@ -53,9 +55,11 @@ public function run(Site $site): Deployment ); $deployment->status = DeploymentStatus::FINISHED; $deployment->save(); - })->catch(function () use ($deployment) { + Notifier::send($site, new DeploymentCompleted($deployment, $site)); + })->catch(function () use ($deployment, $site) { $deployment->status = DeploymentStatus::FAILED; $deployment->save(); + Notifier::send($site, new DeploymentCompleted($deployment, $site)); })->onConnection('ssh'); return $deployment; diff --git a/app/Notifications/DeploymentCompleted.php b/app/Notifications/DeploymentCompleted.php new file mode 100644 index 00000000..90e94849 --- /dev/null +++ b/app/Notifications/DeploymentCompleted.php @@ -0,0 +1,49 @@ +deployment = $deployment; + $this->site = $site; + } + + public function rawText(): string + { + return __("Deployment for site [:site] has completed with status: :status", [ + 'site' => $this->site->domain, + 'status' => $this->deployment->status, + ]); + } + + public function toEmail(object $notifiable): MailMessage + { + return (new MailMessage) + ->subject(__('Deployment Completed')) + ->line("Deployment for site [".$this->site->domain.'] has completed with status: '.$this->deployment->status); + } + + public function toSlack(object $notifiable): string + { + return $this->rawText(); + } + + public function toDiscord(object $notifiable): string + { + return $this->rawText(); + } + + public function toTelegram(object $notifiable): string + { + return $this->rawText(); + } +} From 1335faeb087198284e9a0102ee544cd356015a03 Mon Sep 17 00:00:00 2001 From: Pierlo Date: Tue, 28 Jan 2025 15:46:59 +0800 Subject: [PATCH 2/8] Format with pint --- app/Notifications/DeploymentCompleted.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Notifications/DeploymentCompleted.php b/app/Notifications/DeploymentCompleted.php index 90e94849..20520486 100644 --- a/app/Notifications/DeploymentCompleted.php +++ b/app/Notifications/DeploymentCompleted.php @@ -9,6 +9,7 @@ class DeploymentCompleted extends AbstractNotification { protected Deployment $deployment; + protected Site $site; public function __construct(Deployment $deployment, Site $site) @@ -19,7 +20,7 @@ public function __construct(Deployment $deployment, Site $site) public function rawText(): string { - return __("Deployment for site [:site] has completed with status: :status", [ + return __('Deployment for site [:site] has completed with status: :status', [ 'site' => $this->site->domain, 'status' => $this->deployment->status, ]); @@ -29,7 +30,7 @@ public function toEmail(object $notifiable): MailMessage { return (new MailMessage) ->subject(__('Deployment Completed')) - ->line("Deployment for site [".$this->site->domain.'] has completed with status: '.$this->deployment->status); + ->line('Deployment for site ['.$this->site->domain.'] has completed with status: '.$this->deployment->status); } public function toSlack(object $notifiable): string From 2315fe0d5c5e8d72c38d40ff79222f91b5fed179 Mon Sep 17 00:00:00 2001 From: "Pierluigi Cau (PG)" Date: Wed, 29 Jan 2025 07:53:40 +0800 Subject: [PATCH 3/8] Add tests --- app/Notifications/DeploymentCompleted.php | 5 +- tests/Feature/DeploymentCompletedTest.php | 64 +++++++++++++++++++ .../Notifications/DeploymentCompletedTest.php | 64 +++++++++++++++++++ .../Notifications/DeploymentCompletedTest.php | 64 +++++++++++++++++++ 4 files changed, 194 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/DeploymentCompletedTest.php create mode 100644 tests/Feature/Notifications/DeploymentCompletedTest.php create mode 100644 tests/Unit/Notifications/DeploymentCompletedTest.php diff --git a/app/Notifications/DeploymentCompleted.php b/app/Notifications/DeploymentCompleted.php index 20520486..90e94849 100644 --- a/app/Notifications/DeploymentCompleted.php +++ b/app/Notifications/DeploymentCompleted.php @@ -9,7 +9,6 @@ class DeploymentCompleted extends AbstractNotification { protected Deployment $deployment; - protected Site $site; public function __construct(Deployment $deployment, Site $site) @@ -20,7 +19,7 @@ public function __construct(Deployment $deployment, Site $site) public function rawText(): string { - return __('Deployment for site [:site] has completed with status: :status', [ + return __("Deployment for site [:site] has completed with status: :status", [ 'site' => $this->site->domain, 'status' => $this->deployment->status, ]); @@ -30,7 +29,7 @@ public function toEmail(object $notifiable): MailMessage { return (new MailMessage) ->subject(__('Deployment Completed')) - ->line('Deployment for site ['.$this->site->domain.'] has completed with status: '.$this->deployment->status); + ->line("Deployment for site [".$this->site->domain.'] has completed with status: '.$this->deployment->status); } public function toSlack(object $notifiable): string diff --git a/tests/Feature/DeploymentCompletedTest.php b/tests/Feature/DeploymentCompletedTest.php new file mode 100644 index 00000000..669a9724 --- /dev/null +++ b/tests/Feature/DeploymentCompletedTest.php @@ -0,0 +1,64 @@ + 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->rawText()); + } + + public function testToEmail() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $mailMessage = $notification->toEmail(new \stdClass()); + $this->assertInstanceOf(MailMessage::class, $mailMessage); + $this->assertEquals('Deployment Completed', $mailMessage->subject); + $this->assertStringContainsString('Deployment for site [example.com] has completed with status: finished', $mailMessage->introLines[0]); + } + + public function testToSlack() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->toSlack(new \stdClass())); + } + + public function testToDiscord() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->toDiscord(new \stdClass())); + } + + public function testToTelegram() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->toTelegram(new \stdClass())); + } +} diff --git a/tests/Feature/Notifications/DeploymentCompletedTest.php b/tests/Feature/Notifications/DeploymentCompletedTest.php new file mode 100644 index 00000000..1b8023e2 --- /dev/null +++ b/tests/Feature/Notifications/DeploymentCompletedTest.php @@ -0,0 +1,64 @@ + 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->rawText()); + } + + public function testToEmail() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $mailMessage = $notification->toEmail(new \stdClass()); + $this->assertInstanceOf(MailMessage::class, $mailMessage); + $this->assertEquals('Deployment Completed', $mailMessage->subject); + $this->assertStringContainsString('Deployment for site [example.com] has completed with status: finished', $mailMessage->introLines[0]); + } + + public function testToSlack() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->toSlack(new \stdClass())); + } + + public function testToDiscord() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->toDiscord(new \stdClass())); + } + + public function testToTelegram() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->toTelegram(new \stdClass())); + } +} diff --git a/tests/Unit/Notifications/DeploymentCompletedTest.php b/tests/Unit/Notifications/DeploymentCompletedTest.php new file mode 100644 index 00000000..cff0c030 --- /dev/null +++ b/tests/Unit/Notifications/DeploymentCompletedTest.php @@ -0,0 +1,64 @@ + 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->rawText()); + } + + public function testToEmail() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $mailMessage = $notification->toEmail(new \stdClass()); + $this->assertInstanceOf(MailMessage::class, $mailMessage); + $this->assertEquals('Deployment Completed', $mailMessage->subject); + $this->assertStringContainsString('Deployment for site [example.com] has completed with status: finished', $mailMessage->introLines[0]); + } + + public function testToSlack() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->toSlack(new \stdClass())); + } + + public function testToDiscord() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->toDiscord(new \stdClass())); + } + + public function testToTelegram() + { + $deployment = new Deployment(['status' => 'finished']); + $site = new Site(['domain' => 'example.com']); + $notification = new DeploymentCompleted($deployment, $site); + + $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $this->assertEquals($expectedText, $notification->toTelegram(new \stdClass())); + } +} From 931e994458bdfb8b367af81a3d763c2c0e674cfa Mon Sep 17 00:00:00 2001 From: Pierlo Date: Wed, 29 Jan 2025 08:00:52 +0800 Subject: [PATCH 4/8] Pint format --- app/Notifications/DeploymentCompleted.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Notifications/DeploymentCompleted.php b/app/Notifications/DeploymentCompleted.php index 90e94849..20520486 100644 --- a/app/Notifications/DeploymentCompleted.php +++ b/app/Notifications/DeploymentCompleted.php @@ -9,6 +9,7 @@ class DeploymentCompleted extends AbstractNotification { protected Deployment $deployment; + protected Site $site; public function __construct(Deployment $deployment, Site $site) @@ -19,7 +20,7 @@ public function __construct(Deployment $deployment, Site $site) public function rawText(): string { - return __("Deployment for site [:site] has completed with status: :status", [ + return __('Deployment for site [:site] has completed with status: :status', [ 'site' => $this->site->domain, 'status' => $this->deployment->status, ]); @@ -29,7 +30,7 @@ public function toEmail(object $notifiable): MailMessage { return (new MailMessage) ->subject(__('Deployment Completed')) - ->line("Deployment for site [".$this->site->domain.'] has completed with status: '.$this->deployment->status); + ->line('Deployment for site ['.$this->site->domain.'] has completed with status: '.$this->deployment->status); } public function toSlack(object $notifiable): string From 03393449ff5e42b434fddfc12038074e3c9629aa Mon Sep 17 00:00:00 2001 From: "Pierluigi Cau (PG)" Date: Wed, 29 Jan 2025 08:04:54 +0800 Subject: [PATCH 5/8] Delete tests/Feature/Notifications/DeploymentCompletedTest.php --- .../Notifications/DeploymentCompletedTest.php | 64 ------------------- 1 file changed, 64 deletions(-) delete mode 100644 tests/Feature/Notifications/DeploymentCompletedTest.php diff --git a/tests/Feature/Notifications/DeploymentCompletedTest.php b/tests/Feature/Notifications/DeploymentCompletedTest.php deleted file mode 100644 index 1b8023e2..00000000 --- a/tests/Feature/Notifications/DeploymentCompletedTest.php +++ /dev/null @@ -1,64 +0,0 @@ - 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->rawText()); - } - - public function testToEmail() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $mailMessage = $notification->toEmail(new \stdClass()); - $this->assertInstanceOf(MailMessage::class, $mailMessage); - $this->assertEquals('Deployment Completed', $mailMessage->subject); - $this->assertStringContainsString('Deployment for site [example.com] has completed with status: finished', $mailMessage->introLines[0]); - } - - public function testToSlack() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->toSlack(new \stdClass())); - } - - public function testToDiscord() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->toDiscord(new \stdClass())); - } - - public function testToTelegram() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->toTelegram(new \stdClass())); - } -} From 40e68cf1e8c4c4a0ac61301fcc7392c08022dd08 Mon Sep 17 00:00:00 2001 From: "Pierluigi Cau (PG)" Date: Wed, 29 Jan 2025 08:05:19 +0800 Subject: [PATCH 6/8] Delete tests/Unit/Notifications/DeploymentCompletedTest.php --- .../Notifications/DeploymentCompletedTest.php | 64 ------------------- 1 file changed, 64 deletions(-) delete mode 100644 tests/Unit/Notifications/DeploymentCompletedTest.php diff --git a/tests/Unit/Notifications/DeploymentCompletedTest.php b/tests/Unit/Notifications/DeploymentCompletedTest.php deleted file mode 100644 index cff0c030..00000000 --- a/tests/Unit/Notifications/DeploymentCompletedTest.php +++ /dev/null @@ -1,64 +0,0 @@ - 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->rawText()); - } - - public function testToEmail() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $mailMessage = $notification->toEmail(new \stdClass()); - $this->assertInstanceOf(MailMessage::class, $mailMessage); - $this->assertEquals('Deployment Completed', $mailMessage->subject); - $this->assertStringContainsString('Deployment for site [example.com] has completed with status: finished', $mailMessage->introLines[0]); - } - - public function testToSlack() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->toSlack(new \stdClass())); - } - - public function testToDiscord() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->toDiscord(new \stdClass())); - } - - public function testToTelegram() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->toTelegram(new \stdClass())); - } -} From b62055030303fc3b2b4dde483fdcc6f2e666df79 Mon Sep 17 00:00:00 2001 From: Pierlo Date: Wed, 29 Jan 2025 08:07:40 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=8D=BB=F0=9F=8D=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Feature/DeploymentCompletedTest.php | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/Feature/DeploymentCompletedTest.php b/tests/Feature/DeploymentCompletedTest.php index 669a9724..7e2a5c8a 100644 --- a/tests/Feature/DeploymentCompletedTest.php +++ b/tests/Feature/DeploymentCompletedTest.php @@ -10,55 +10,55 @@ class DeploymentCompletedTest extends TestCase { - public function testRawText() + public function test_raw_text() { $deployment = new Deployment(['status' => 'finished']); $site = new Site(['domain' => 'example.com']); $notification = new DeploymentCompleted($deployment, $site); - $expectedText = "Deployment for site [example.com] has completed with status: finished"; + $expectedText = 'Deployment for site [example.com] has completed with status: finished'; $this->assertEquals($expectedText, $notification->rawText()); } - public function testToEmail() + public function test_to_email() { $deployment = new Deployment(['status' => 'finished']); $site = new Site(['domain' => 'example.com']); $notification = new DeploymentCompleted($deployment, $site); - $mailMessage = $notification->toEmail(new \stdClass()); + $mailMessage = $notification->toEmail(new \stdClass); $this->assertInstanceOf(MailMessage::class, $mailMessage); $this->assertEquals('Deployment Completed', $mailMessage->subject); $this->assertStringContainsString('Deployment for site [example.com] has completed with status: finished', $mailMessage->introLines[0]); } - public function testToSlack() + public function test_to_slack() { $deployment = new Deployment(['status' => 'finished']); $site = new Site(['domain' => 'example.com']); $notification = new DeploymentCompleted($deployment, $site); - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->toSlack(new \stdClass())); + $expectedText = 'Deployment for site [example.com] has completed with status: finished'; + $this->assertEquals($expectedText, $notification->toSlack(new \stdClass)); } - public function testToDiscord() + public function test_to_discord() { $deployment = new Deployment(['status' => 'finished']); $site = new Site(['domain' => 'example.com']); $notification = new DeploymentCompleted($deployment, $site); - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->toDiscord(new \stdClass())); + $expectedText = 'Deployment for site [example.com] has completed with status: finished'; + $this->assertEquals($expectedText, $notification->toDiscord(new \stdClass)); } - public function testToTelegram() + public function test_to_telegram() { $deployment = new Deployment(['status' => 'finished']); $site = new Site(['domain' => 'example.com']); $notification = new DeploymentCompleted($deployment, $site); - $expectedText = "Deployment for site [example.com] has completed with status: finished"; - $this->assertEquals($expectedText, $notification->toTelegram(new \stdClass())); + $expectedText = 'Deployment for site [example.com] has completed with status: finished'; + $this->assertEquals($expectedText, $notification->toTelegram(new \stdClass)); } } From 444779f6edc463566112fcf38c75a03b567d374a Mon Sep 17 00:00:00 2001 From: Saeed Vaziry Date: Wed, 29 Jan 2025 19:25:36 +0100 Subject: [PATCH 8/8] tests --- tests/Feature/ApplicationTest.php | 5 ++ tests/Feature/DeploymentCompletedTest.php | 64 ----------------------- tests/TestCase.php | 8 +-- 3 files changed, 10 insertions(+), 67 deletions(-) delete mode 100644 tests/Feature/DeploymentCompletedTest.php diff --git a/tests/Feature/ApplicationTest.php b/tests/Feature/ApplicationTest.php index 90f96464..3811f906 100644 --- a/tests/Feature/ApplicationTest.php +++ b/tests/Feature/ApplicationTest.php @@ -5,10 +5,12 @@ use App\Enums\DeploymentStatus; use App\Facades\SSH; use App\Models\GitHook; +use App\Notifications\DeploymentCompleted; use App\Web\Pages\Servers\Sites\View; use App\Web\Pages\Servers\Sites\Widgets\DeploymentsList; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Notification; use Livewire\Livewire; use Tests\TestCase; @@ -65,6 +67,7 @@ public function test_deploy(): void ], ]), ]); + Notification::fake(); $this->site->deploymentScript->update([ 'content' => 'git pull', @@ -88,6 +91,8 @@ public function test_deploy(): void SSH::assertExecutedContains('cd /home/vito/'.$this->site->domain); SSH::assertExecutedContains('git pull'); + Notification::assertSentTo($this->notificationChannel, DeploymentCompleted::class); + $this->get( View::getUrl([ 'server' => $this->server, diff --git a/tests/Feature/DeploymentCompletedTest.php b/tests/Feature/DeploymentCompletedTest.php deleted file mode 100644 index 7e2a5c8a..00000000 --- a/tests/Feature/DeploymentCompletedTest.php +++ /dev/null @@ -1,64 +0,0 @@ - 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = 'Deployment for site [example.com] has completed with status: finished'; - $this->assertEquals($expectedText, $notification->rawText()); - } - - public function test_to_email() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $mailMessage = $notification->toEmail(new \stdClass); - $this->assertInstanceOf(MailMessage::class, $mailMessage); - $this->assertEquals('Deployment Completed', $mailMessage->subject); - $this->assertStringContainsString('Deployment for site [example.com] has completed with status: finished', $mailMessage->introLines[0]); - } - - public function test_to_slack() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = 'Deployment for site [example.com] has completed with status: finished'; - $this->assertEquals($expectedText, $notification->toSlack(new \stdClass)); - } - - public function test_to_discord() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = 'Deployment for site [example.com] has completed with status: finished'; - $this->assertEquals($expectedText, $notification->toDiscord(new \stdClass)); - } - - public function test_to_telegram() - { - $deployment = new Deployment(['status' => 'finished']); - $site = new Site(['domain' => 'example.com']); - $notification = new DeploymentCompleted($deployment, $site); - - $expectedText = 'Deployment for site [example.com] has completed with status: finished'; - $this->assertEquals($expectedText, $notification->toTelegram(new \stdClass)); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index 6414f065..4cf85499 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,10 +3,10 @@ namespace Tests; use App\Enums\Database; -use App\Enums\NotificationChannel; use App\Enums\ServiceStatus; use App\Enums\UserRole; use App\Enums\Webserver; +use App\Models\NotificationChannel; use App\Models\Server; use App\Models\Site; use App\Models\SourceControl; @@ -24,6 +24,8 @@ abstract class TestCase extends BaseTestCase protected Site $site; + protected NotificationChannel $notificationChannel; + public const EXPECT_SUCCESS = true; public const EXPECT_FAILURE = false; @@ -40,8 +42,8 @@ protected function setUp(): void ]); $this->user->createDefaultProject(); - \App\Models\NotificationChannel::factory()->create([ - 'provider' => NotificationChannel::EMAIL, + $this->notificationChannel = NotificationChannel::factory()->create([ + 'provider' => \App\Enums\NotificationChannel::EMAIL, 'connected' => true, 'data' => [ 'email' => 'user@example.com',