Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
range-of-motion committed Dec 29, 2023
1 parent 189428e commit 5f8f46b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
18 changes: 7 additions & 11 deletions app/Mail/WeeklyReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
55 changes: 55 additions & 0 deletions tests/Unit/Mail/WeeklyReportTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Unit\Mail;

use App\Mail\WeeklyReport;
use App\Models\Space;
use Tests\TestCase;

class WeeklyReportTest extends TestCase
{
public function testMailableUsingSpaceWithoutTransactions(): void
{
$space = Space::factory()
->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');
}
}

0 comments on commit 5f8f46b

Please sign in to comment.