From 5f8f46b6b83ec023c12935e328da82eca4596a01 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] WIP --- app/Mail/WeeklyReport.php | 18 ++++----- tests/Unit/Mail/WeeklyReportTest.php | 55 ++++++++++++++++++++++++++++ 2 files changed, 62 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..1ef1f698 --- /dev/null +++ b/tests/Unit/Mail/WeeklyReportTest.php @@ -0,0 +1,55 @@ +create([ + 'name' => 'Foo Bar', + ]); + + $mailable = new WeeklyReport( + space: $space, + week: 5, + totalSpent: 10000, + largestSpendingWithTag: [], + ); + + $mailable + ->assertSeeInText('Here\'s your weekly report for Foo Bar') + ->assertSeeInText('This week (#5) you\'ve') + ->assertDontSeeInText('Most of which you\'ve spent on'); + } + + public function testMailableUsingSpaceWithTransactions(): void + { + $space = Space::factory() + ->create([ + '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('Most of which you\'ve spent on Insurance'); + } +}