|
5 | 5 | use App\Mail\BulkAssetCheckoutMail; |
6 | 6 | use App\Mail\CheckoutAssetMail; |
7 | 7 | use App\Models\Asset; |
| 8 | +use App\Models\Location; |
8 | 9 | use App\Models\User; |
9 | 10 | use Illuminate\Support\Facades\Mail; |
10 | 11 | use PHPUnit\Framework\Attributes\Group; |
@@ -44,6 +45,44 @@ public function test_email_is_sent_to_user() |
44 | 45 | }); |
45 | 46 | } |
46 | 47 |
|
| 48 | + public function test_email_is_sent_to_location_manager() |
| 49 | + { |
| 50 | + // todo: migrate this into a data provider? |
| 51 | +
|
| 52 | + $manager = User::factory()->create(); |
| 53 | + |
| 54 | + $this->target = Location::factory()->for($manager, 'manager')->create(); |
| 55 | + |
| 56 | + $this->sendRequest(); |
| 57 | + |
| 58 | + Mail::assertNotSent(CheckoutAssetMail::class); |
| 59 | + |
| 60 | + Mail::assertSent(BulkAssetCheckoutMail::class, 1); |
| 61 | + |
| 62 | + Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) use ($manager) { |
| 63 | + return $mail->hasTo($manager->email); |
| 64 | + }); |
| 65 | + } |
| 66 | + |
| 67 | + public function test_email_is_sent_to_user_asset_is_checked_out_to() |
| 68 | + { |
| 69 | + // todo: migrate this into a data provider? |
| 70 | +
|
| 71 | + $user = User::factory()->create(); |
| 72 | + |
| 73 | + $this->target = Asset::factory()->assignedToUser($user)->create(); |
| 74 | + |
| 75 | + $this->sendRequest(); |
| 76 | + |
| 77 | + Mail::assertNotSent(CheckoutAssetMail::class); |
| 78 | + |
| 79 | + Mail::assertSent(BulkAssetCheckoutMail::class, 1); |
| 80 | + |
| 81 | + Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) use ($user) { |
| 82 | + return $mail->hasTo($user->email); |
| 83 | + }); |
| 84 | + } |
| 85 | + |
47 | 86 | public function test_email_is_not_sent_to_user_when_user_does_not_have_email_address() |
48 | 87 | { |
49 | 88 | $this->target = User::factory()->create(['email' => null]); |
@@ -116,11 +155,17 @@ public function test_email_is_sent_to_cc_address_when_assets_do_not_require_acce |
116 | 155 |
|
117 | 156 | private function sendRequest() |
118 | 157 | { |
| 158 | + $types = [ |
| 159 | + User::class => 'user', |
| 160 | + Location::class => 'location', |
| 161 | + Asset::class => 'asset', |
| 162 | + ]; |
| 163 | + |
119 | 164 | $this->actingAs($this->admin) |
120 | 165 | ->followingRedirects() |
121 | 166 | ->post(route('hardware.bulkcheckout.store'), [ |
122 | 167 | 'selected_assets' => $this->assets->pluck('id')->toArray(), |
123 | | - 'checkout_to_type' => 'user', |
| 168 | + 'checkout_to_type' => $types[get_class($this->target)], |
124 | 169 | 'assigned_user' => $this->target->id, |
125 | 170 | 'assigned_asset' => null, |
126 | 171 | 'checkout_at' => now()->subWeek()->format('Y-m-d'), |
|
0 commit comments