|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Unit\Mail; |
| 4 | + |
| 5 | +use App\Mail\CheckoutAssetMail; |
| 6 | +use App\Models\Asset; |
| 7 | +use App\Models\CheckoutAcceptance; |
| 8 | +use App\Models\User; |
| 9 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 10 | +use Tests\TestCase; |
| 11 | + |
| 12 | +class CheckoutAssetMailTest extends TestCase |
| 13 | +{ |
| 14 | + public static function data() |
| 15 | + { |
| 16 | + yield 'Asset requiring acceptance' => [ |
| 17 | + function () { |
| 18 | + $asset = Asset::factory()->requiresAcceptance()->create(); |
| 19 | + return [ |
| 20 | + 'asset' => $asset, |
| 21 | + 'acceptance' => CheckoutAcceptance::factory()->for($asset, 'checkoutable')->create(), |
| 22 | + 'first_time_sending' => true, |
| 23 | + 'expected_subject' => 'Asset checked out', |
| 24 | + 'expected_opening' => 'A new item has been checked out under your name that requires acceptance, details are below.' |
| 25 | + ]; |
| 26 | + } |
| 27 | + ]; |
| 28 | + |
| 29 | + yield 'Asset not requiring acceptance' => [ |
| 30 | + function () { |
| 31 | + return [ |
| 32 | + 'asset' => Asset::factory()->doesNotRequireAcceptance()->create(), |
| 33 | + 'acceptance' => null, |
| 34 | + 'first_time_sending' => true, |
| 35 | + 'expected_subject' => 'Asset checked out', |
| 36 | + 'expected_opening' => 'A new item has been checked out under your name, details are below.' |
| 37 | + ]; |
| 38 | + } |
| 39 | + ]; |
| 40 | + |
| 41 | + yield 'Reminder' => [ |
| 42 | + function () { |
| 43 | + return [ |
| 44 | + 'asset' => Asset::factory()->requiresAcceptance()->create(), |
| 45 | + 'acceptance' => CheckoutAcceptance::factory()->create(), |
| 46 | + 'first_time_sending' => false, |
| 47 | + 'expected_subject' => 'Reminder: You have Unaccepted Assets.', |
| 48 | + 'expected_opening' => 'An item was recently checked out under your name that requires acceptance, details are below.' |
| 49 | + ]; |
| 50 | + } |
| 51 | + ]; |
| 52 | + } |
| 53 | + |
| 54 | + #[DataProvider('data')] |
| 55 | + public function testSubjectLineAndOpening($data) |
| 56 | + { |
| 57 | + [ |
| 58 | + 'asset' => $asset, |
| 59 | + 'acceptance' => $acceptance, |
| 60 | + 'first_time_sending' => $firstTimeSending, |
| 61 | + 'expected_subject' => $expectedSubject, |
| 62 | + 'expected_opening' => $expectedOpening, |
| 63 | + ] = $data(); |
| 64 | + |
| 65 | + (new CheckoutAssetMail( |
| 66 | + $asset, |
| 67 | + User::factory()->create(), |
| 68 | + User::factory()->create(), |
| 69 | + $acceptance, |
| 70 | + 'A note goes here', |
| 71 | + $firstTimeSending, |
| 72 | + ))->assertHasSubject($expectedSubject) |
| 73 | + ->assertSeeInText($expectedOpening); |
| 74 | + } |
| 75 | +} |
0 commit comments