From b50fea3b891f827908339cc328018da86dad0d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Drunen?= Date: Fri, 29 Dec 2023 22:24:51 +0100 Subject: [PATCH 1/5] Test WeeklyReport mail --- app/Mail/WeeklyReport.php | 18 ++++------ tests/Unit/Mail/WeeklyReportTest.php | 54 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 tests/Unit/Mail/WeeklyReportTest.php diff --git a/app/Mail/WeeklyReport.php b/app/Mail/WeeklyReport.php index 2f9fe593..c81f5375 100644 --- a/app/Mail/WeeklyReport.php +++ b/app/Mail/WeeklyReport.php @@ -12,17 +12,13 @@ class WeeklyReport extends Mailable use Queueable; use SerializesModels; - protected $space; - protected $week; - protected $totalSpent; - protected $largestSpendingWithTag; - - public function __construct(Space $space, $week, $totalSpent, $largestSpendingWithTag) - { - $this->space = $space; - $this->week = $week; - $this->totalSpent = $totalSpent; - $this->largestSpendingWithTag = $largestSpendingWithTag; + public function __construct( + protected Space $space, + protected $week, + protected $totalSpent, + protected $largestSpendingWithTag + ) { + // } public function build() diff --git a/tests/Unit/Mail/WeeklyReportTest.php b/tests/Unit/Mail/WeeklyReportTest.php new file mode 100644 index 00000000..d5c0f08d --- /dev/null +++ b/tests/Unit/Mail/WeeklyReportTest.php @@ -0,0 +1,54 @@ +create([ + 'currency_id' => 2, // Should be USD + 'name' => 'Foo Bar', + ]); + + $mailable = new WeeklyReport( + space: $space, + week: 5, + totalSpent: 0, + largestSpendingWithTag: [], + ); + + $mailable + ->assertSeeInText('Here\'s your weekly report for Foo Bar') + ->assertSeeInText('This week (#5) you\'ve') + ->assertSeeInText('- Spent $ 0.00') + ->assertDontSeeInText('Most of which you\'ve spent on'); + } + + public function testMailableUsingSpaceWithTransactions(): void + { + $space = Space::factory() + ->create([ + 'currency_id' => 2, // Should be USD + 'name' => 'Foo Bar', + ]); + + $mailable = new WeeklyReport( + space: $space, + week: 5, + totalSpent: 10000, + largestSpendingWithTag: [(object) ['amount' => 7000, 'tag_name' => 'Insurance']], + ); + + $mailable + ->assertSeeInText('Here\'s your weekly report for Foo Bar') + ->assertSeeInText('This week (#5) you\'ve') + ->assertSeeInText('- Spent $ 100.00') + ->assertSeeInText('- Most of which you\'ve spent on Insurance ($ 70.00)'); + } +} From efbdfa3582743e3d90151b30aaa551d5d97d9d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Drunen?= Date: Fri, 29 Dec 2023 23:02:55 +0100 Subject: [PATCH 2/5] Test ResetPassword mail --- app/Mail/ResetPassword.php | 9 ++++----- tests/Unit/Mail/ResetPasswordTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 tests/Unit/Mail/ResetPasswordTest.php diff --git a/app/Mail/ResetPassword.php b/app/Mail/ResetPassword.php index 63c2f704..0cdc91fe 100644 --- a/app/Mail/ResetPassword.php +++ b/app/Mail/ResetPassword.php @@ -11,11 +11,10 @@ class ResetPassword extends Mailable use Queueable; use SerializesModels; - protected $token; - - public function __construct($token) - { - $this->token = $token; + public function __construct( + protected $token + ) { + // } public function build() diff --git a/tests/Unit/Mail/ResetPasswordTest.php b/tests/Unit/Mail/ResetPasswordTest.php new file mode 100644 index 00000000..eeeb0f30 --- /dev/null +++ b/tests/Unit/Mail/ResetPasswordTest.php @@ -0,0 +1,16 @@ +assertSeeInHtml('Click here to change your password', false); // phpcs:ignore + } +} From 4b817da952c411837c497a76ebc87ef92486d960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Drunen?= Date: Fri, 29 Dec 2023 23:11:15 +0100 Subject: [PATCH 3/5] Test VerifyRegistration mail --- app/Mail/ResetPassword.php | 2 +- app/Mail/VerifyRegistration.php | 9 ++++---- tests/Unit/Mail/ResetPasswordTest.php | 2 +- tests/Unit/Mail/VerifyRegistrationTest.php | 27 ++++++++++++++++++++++ tests/Unit/Mail/WeeklyReportTest.php | 2 +- 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 tests/Unit/Mail/VerifyRegistrationTest.php diff --git a/app/Mail/ResetPassword.php b/app/Mail/ResetPassword.php index 0cdc91fe..b0e614b1 100644 --- a/app/Mail/ResetPassword.php +++ b/app/Mail/ResetPassword.php @@ -12,7 +12,7 @@ class ResetPassword extends Mailable use SerializesModels; public function __construct( - protected $token + protected $token, ) { // } diff --git a/app/Mail/VerifyRegistration.php b/app/Mail/VerifyRegistration.php index 0e65557d..b20c7f17 100644 --- a/app/Mail/VerifyRegistration.php +++ b/app/Mail/VerifyRegistration.php @@ -12,11 +12,10 @@ class VerifyRegistration extends Mailable use Queueable; use SerializesModels; - protected $user; - - public function __construct(User $user) - { - $this->user = $user; + public function __construct( + protected User $user, + ) { + // } public function build() diff --git a/tests/Unit/Mail/ResetPasswordTest.php b/tests/Unit/Mail/ResetPasswordTest.php index eeeb0f30..00785135 100644 --- a/tests/Unit/Mail/ResetPasswordTest.php +++ b/tests/Unit/Mail/ResetPasswordTest.php @@ -1,6 +1,6 @@ create([ + 'name' => 'John Doe', + 'verification_token' => 'abc123', + ]); + + $mailable = new VerifyRegistration($user); + + $mailable + ->assertSeeInText('Welcome aboard, John Doe') + ->assertSeeInText('We\'re going to help you get insight into your personal finances.') + ->assertSeeInText('No more dealing with pesky, half-assed spreadsheets.') + ->assertSeeInHtml('Verify', false); + } +} diff --git a/tests/Unit/Mail/WeeklyReportTest.php b/tests/Unit/Mail/WeeklyReportTest.php index d5c0f08d..4b56410f 100644 --- a/tests/Unit/Mail/WeeklyReportTest.php +++ b/tests/Unit/Mail/WeeklyReportTest.php @@ -1,6 +1,6 @@ Date: Fri, 29 Dec 2023 23:16:11 +0100 Subject: [PATCH 4/5] Test PasswordChanged mail --- app/Mail/PasswordChanged.php | 9 ++++----- tests/Unit/Mail/PasswordChangedTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 tests/Unit/Mail/PasswordChangedTest.php diff --git a/app/Mail/PasswordChanged.php b/app/Mail/PasswordChanged.php index 6b9d7f18..a0202ade 100644 --- a/app/Mail/PasswordChanged.php +++ b/app/Mail/PasswordChanged.php @@ -11,11 +11,10 @@ class PasswordChanged extends Mailable use Queueable; use SerializesModels; - protected $updated_at; - - public function __construct($updated_at) - { - $this->updated_at = $updated_at; + public function __construct( + protected $updated_at, + ) { + // } public function build() diff --git a/tests/Unit/Mail/PasswordChangedTest.php b/tests/Unit/Mail/PasswordChangedTest.php new file mode 100644 index 00000000..c557f9b1 --- /dev/null +++ b/tests/Unit/Mail/PasswordChangedTest.php @@ -0,0 +1,16 @@ +assertSeeInText('Heads up! Your password has been changed (2023-12-05 18:00:00 CEST).'); + } +} From bf7b37beb7f05bad08fe91356ca917975839f74d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Drunen?= Date: Fri, 29 Dec 2023 23:32:03 +0100 Subject: [PATCH 5/5] Test InvitedToSpace mail --- app/Mail/InvitedToSpace.php | 9 ++--- .../emails/invited_to_space_plain.blade.php | 2 +- tests/Unit/Mail/InvitedToSpaceTest.php | 37 +++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 tests/Unit/Mail/InvitedToSpaceTest.php diff --git a/app/Mail/InvitedToSpace.php b/app/Mail/InvitedToSpace.php index 51e1b76b..7385a58a 100644 --- a/app/Mail/InvitedToSpace.php +++ b/app/Mail/InvitedToSpace.php @@ -12,11 +12,10 @@ class InvitedToSpace extends Mailable use Queueable; use SerializesModels; - protected $invite; - - public function __construct(SpaceInvite $invite) - { - $this->invite = $invite; + public function __construct( + protected SpaceInvite $invite, + ) { + // } public function build() diff --git a/resources/views/emails/invited_to_space_plain.blade.php b/resources/views/emails/invited_to_space_plain.blade.php index eb0a0490..16cd1cc7 100644 --- a/resources/views/emails/invited_to_space_plain.blade.php +++ b/resources/views/emails/invited_to_space_plain.blade.php @@ -1,4 +1,4 @@ -{{ $invite->inviter->name }} has invited you to "{{ $invite->space->name }}" +{{ $invite->inviter->name }} has invited you to "{{ $invite->space->name }}". Use the link below to check out your invite. diff --git a/tests/Unit/Mail/InvitedToSpaceTest.php b/tests/Unit/Mail/InvitedToSpaceTest.php new file mode 100644 index 00000000..761d3db2 --- /dev/null +++ b/tests/Unit/Mail/InvitedToSpaceTest.php @@ -0,0 +1,37 @@ +create([ + 'name' => 'Foo Bar', + ]); + + $inviterUser = User::factory() + ->create([ + 'name' => 'John Doe', + ]); + + $spaceInvite = SpaceInvite::factory() + ->create([ + 'space_id' => $space->id, + 'inviter_user_id' => $inviterUser->id, + ]); + + $mailable = new InvitedToSpace($spaceInvite); + + $mailable + ->assertSeeInText('John Doe has invited you to "Foo Bar".') + ->assertSeeInHtml('Check out your invite', false); // phpcs:ignore + } +}