Skip to content

Commit 0bca66b

Browse files
committed
Send email if asset has checkin_email set to true
1 parent 24e5cf8 commit 0bca66b

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

app/Listeners/CheckoutablesCheckedOutInBulkListener.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ private function shouldSendCheckoutEmailToUser(?User $user, Collection $assets):
7676
return true;
7777
}
7878

79+
if ($this->hasAssetWithCategorySettingToSendEmail($assets)) {
80+
return true;
81+
}
82+
7983
return $this->requiresAcceptance($assets);
8084
}
8185

@@ -109,6 +113,17 @@ private function hasAssetWithEula(Collection $assets): bool
109113
return false;
110114
}
111115

116+
private function hasAssetWithCategorySettingToSendEmail(Collection $assets): bool
117+
{
118+
foreach ($assets as $asset) {
119+
if ($asset->checkin_email()) {
120+
return true;
121+
}
122+
}
123+
124+
return false;
125+
}
126+
112127
private function requiresAcceptance(Collection $assets): bool
113128
{
114129
return (bool) $assets->reduce(

database/factories/CategoryFactory.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,26 @@ public function doesNotSendCheckinEmail()
222222
]);
223223
}
224224

225+
public function sendsCheckinEmail()
226+
{
227+
return $this->state([
228+
'checkin_email' => true,
229+
]);
230+
}
231+
225232
public function hasLocalEula()
226233
{
227234
return $this->state([
228235
'use_default_eula' => false,
229236
'eula_text' => 'Some EULA text here',
230237
]);
231238
}
239+
240+
public function withNoLocalOrGlobalEula()
241+
{
242+
return $this->state([
243+
'use_default_eula' => false,
244+
'eula_text' => '',
245+
]);
246+
}
232247
}

tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,29 @@ public function test_email_is_sent_when_assets_do_not_require_acceptance_but_hav
132132
});
133133
}
134134

135-
public function test_email_is_sent_when_assets_do_not_require_acceptance_but_category_is_set_to_send_email()
135+
public function test_email_is_sent_when_assets_do_not_require_acceptance_or_have_a_eula_but_category_is_set_to_send_email()
136136
{
137-
$this->markTestIncomplete();
137+
$this->assets = Asset::factory()->count(2)->create();
138+
139+
$category = Category::factory()
140+
->doesNotRequireAcceptance()
141+
->withNoLocalOrGlobalEula()
142+
->sendsCheckinEmail()
143+
->create();
144+
145+
$this->assets->each(fn($asset) => $asset->model->category()->associate($category)->save());
146+
147+
$this->sendRequest();
148+
149+
Mail::assertNotSent(CheckoutAssetMail::class);
150+
151+
Mail::assertSent(BulkAssetCheckoutMail::class, 1);
152+
153+
Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) {
154+
return $mail->hasTo($this->target->email)
155+
&& $mail->assertSeeInText('Assets have been checked out to you')
156+
&& $mail->assertDontSeeInText('review the terms');
157+
});
138158
}
139159

140160
public function test_email_is_sent_to_cc_address()

0 commit comments

Comments
 (0)