Add "Reminder" to subject line
This commit is contained in:
parent
d254a40e0a
commit
e2805f4033
3 changed files with 41 additions and 10 deletions
|
@ -1177,10 +1177,9 @@ class ReportsController extends Controller
|
|||
$locale = $assetItem->assignedTo?->locale;
|
||||
// Only send notification if assigned
|
||||
if ($locale && $email) {
|
||||
Mail::to($email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note))->locale($locale));
|
||||
|
||||
Mail::to($email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note, firstTimeSending: false))->locale($locale));
|
||||
} elseif ($email) {
|
||||
Mail::to($email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note)));
|
||||
Mail::to($email)->send((new CheckoutAssetMail($assetItem, $assetItem->assignedTo, $logItem->user, $acceptance, $logItem->note, firstTimeSending: false)));
|
||||
}
|
||||
|
||||
if ($email == ''){
|
||||
|
|
|
@ -20,10 +20,12 @@ class CheckoutAssetMail extends Mailable
|
|||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
private bool $firstTimeSending;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(Asset $asset, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
|
||||
public function __construct(Asset $asset, $checkedOutTo, User $checkedOutBy, $acceptance, $note, bool $firstTimeSending = true)
|
||||
{
|
||||
$this->item = $asset;
|
||||
$this->admin = $checkedOutBy;
|
||||
|
@ -36,6 +38,8 @@ class CheckoutAssetMail extends Mailable
|
|||
$this->last_checkout = '';
|
||||
$this->expected_checkin = '';
|
||||
|
||||
$this->firstTimeSending = $firstTimeSending;
|
||||
|
||||
if ($this->item->last_checkout) {
|
||||
$this->last_checkout = Helper::getFormattedDateObject($this->item->last_checkout, 'date',
|
||||
false);
|
||||
|
@ -54,9 +58,16 @@ class CheckoutAssetMail extends Mailable
|
|||
{
|
||||
$from = new Address(config('mail.from.address'), config('mail.from.name'));
|
||||
|
||||
$subject = trans('mail.Asset_Checkout_Notification');
|
||||
|
||||
if (!$this->firstTimeSending) {
|
||||
// @todo: translate
|
||||
$subject = 'Reminder: ' . $subject;
|
||||
}
|
||||
|
||||
return new Envelope(
|
||||
from: $from,
|
||||
subject: trans('mail.Asset_Checkout_Notification'),
|
||||
subject: $subject,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Mail\CheckoutAssetMail;
|
|||
use App\Models\CheckoutAcceptance;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AssetAcceptanceReminderTest extends TestCase
|
||||
|
@ -67,16 +68,36 @@ class AssetAcceptanceReminderTest extends TestCase
|
|||
Mail::assertNotSent(CheckoutAssetMail::class);
|
||||
}
|
||||
|
||||
public function testReminderIsSentToUser()
|
||||
public static function users()
|
||||
{
|
||||
yield 'User with locale set' => [
|
||||
function () {
|
||||
return CheckoutAcceptance::factory()->pending()->create();
|
||||
}
|
||||
];
|
||||
|
||||
yield 'User without locale set' => [
|
||||
function () {
|
||||
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
|
||||
$checkoutAcceptance->assignedTo->update(['locale' => null]);
|
||||
|
||||
return $checkoutAcceptance;
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('users')]
|
||||
public function testReminderIsSentToUser($data)
|
||||
{
|
||||
$checkoutAcceptance = $data();
|
||||
|
||||
$this->actingAs($this->actor)
|
||||
->post($this->routeFor($this->checkoutAcceptance))
|
||||
->post($this->routeFor($checkoutAcceptance))
|
||||
->assertRedirect(route('reports/unaccepted_assets'));
|
||||
|
||||
Mail::assertSent(CheckoutAssetMail::class, 1);
|
||||
Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
|
||||
return $mail->hasTo($this->checkoutAcceptance->assignedTo->email)
|
||||
// @todo:
|
||||
Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) use ($checkoutAcceptance) {
|
||||
return $mail->hasTo($checkoutAcceptance->assignedTo->email)
|
||||
&& $mail->hasSubject('Reminder: ' . trans('mail.Asset_Checkout_Notification'));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue