-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #479 from range-of-motion/create-tests-for-mails
Create tests for mails
- Loading branch information
Showing
11 changed files
with
174 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Mail; | ||
|
||
use App\Mail\InvitedToSpace; | ||
use App\Models\Space; | ||
use App\Models\SpaceInvite; | ||
use App\Models\User; | ||
use Tests\TestCase; | ||
|
||
class InvitedToSpaceTest extends TestCase | ||
{ | ||
public function testMailable(): void | ||
{ | ||
$space = Space::factory() | ||
->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('<a href="' . config('app.url') . '/spaces/' . $space->id . '/invites/' . $spaceInvite->id . '">Check out your invite</a>', false); // phpcs:ignore | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Mail; | ||
|
||
use App\Mail\PasswordChanged; | ||
use Tests\TestCase; | ||
|
||
class PasswordChangedTest extends TestCase | ||
{ | ||
public function testMailable(): void | ||
{ | ||
$mailable = new PasswordChanged('2023-12-05 18:00:00'); | ||
|
||
$mailable->assertSeeInText('Heads up! Your password has been changed (2023-12-05 18:00:00 CEST).'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Mail; | ||
|
||
use App\Mail\ResetPassword; | ||
use Tests\TestCase; | ||
|
||
class ResetPasswordTest extends TestCase | ||
{ | ||
public function testMailable(): void | ||
{ | ||
$mailable = new ResetPassword('123456789'); | ||
|
||
$mailable->assertSeeInHtml('<a href="' . config('app.url') . '/reset_password?token=123456789">Click here to change your password</a>', false); // phpcs:ignore | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Mail; | ||
|
||
use App\Mail\VerifyRegistration; | ||
use App\Models\User; | ||
use Tests\TestCase; | ||
|
||
class VerifyRegistrationTest extends TestCase | ||
{ | ||
public function testMailable(): void | ||
{ | ||
$user = User::factory() | ||
->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('<a href="' . config('app.url') . '/verify/abc123">Verify</a>', false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Tests\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([ | ||
'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)'); | ||
} | ||
} |