First pass at updating wording for asset checkout mail
This commit is contained in:
parent
70de08a211
commit
3db124e709
6 changed files with 142 additions and 4 deletions
|
@ -74,7 +74,7 @@ class CheckoutAssetMail extends Mailable
|
|||
{
|
||||
$this->item->load('assetstatus');
|
||||
$eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : '';
|
||||
$req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
|
||||
$req_accept = $this->requiresAcceptance();
|
||||
$fields = [];
|
||||
|
||||
// Check if the item has custom fields associated with it
|
||||
|
@ -98,6 +98,7 @@ class CheckoutAssetMail extends Mailable
|
|||
'accept_url' => $accept_url,
|
||||
'last_checkout' => $this->last_checkout,
|
||||
'expected_checkin' => $this->expected_checkin,
|
||||
'opening_line' => $this->openingLine(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -118,6 +119,29 @@ class CheckoutAssetMail extends Mailable
|
|||
return trans('mail.Asset_Checkout_Notification');
|
||||
}
|
||||
|
||||
return trans('mail.unaccepted_asset_reminder');
|
||||
return 'Reminder: ' . trans('mail.unaccepted_asset_reminder');
|
||||
}
|
||||
|
||||
private function openingLine(): string
|
||||
{
|
||||
if ($this->firstTimeSending && $this->requiresAcceptance()) {
|
||||
return 'A new item has been checked out under your name that requires acceptance, details are below.';
|
||||
}
|
||||
|
||||
if ($this->firstTimeSending && !$this->requiresAcceptance()) {
|
||||
return 'A new item has been checked out under your name, details are below.';
|
||||
}
|
||||
|
||||
if (!$this->firstTimeSending && $this->requiresAcceptance()) {
|
||||
return 'An item was recently checked out under your name that requires acceptance, details are below.';
|
||||
}
|
||||
|
||||
// we shouldn't get here but let's send a default message just in case
|
||||
return trans('new_item_checked');
|
||||
}
|
||||
|
||||
private function requiresAcceptance(): int|bool
|
||||
{
|
||||
return method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Database\Factories;
|
|||
|
||||
use App\Models\Asset;
|
||||
use App\Models\AssetModel;
|
||||
use App\Models\Category;
|
||||
use App\Models\CustomField;
|
||||
use App\Models\Location;
|
||||
use App\Models\Statuslabel;
|
||||
|
@ -333,6 +334,15 @@ class AssetFactory extends Factory
|
|||
});
|
||||
}
|
||||
|
||||
public function doesNotRequireAcceptance()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'model_id' => AssetModel::factory()->doesNotRequireAcceptance(),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function deleted()
|
||||
{
|
||||
return $this->state(function () {
|
||||
|
|
|
@ -448,4 +448,13 @@ class AssetModelFactory extends Factory
|
|||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function doesNotRequireAcceptance()
|
||||
{
|
||||
return $this->state(function () {
|
||||
return [
|
||||
'category_id' => Category::factory()->doesNotRequireAcceptance(),
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,4 +207,11 @@ class CategoryFactory extends Factory
|
|||
'category_type' => 'consumable',
|
||||
]);
|
||||
}
|
||||
|
||||
public function doesNotRequireAcceptance()
|
||||
{
|
||||
return $this->state([
|
||||
'require_acceptance' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@component('mail::message')
|
||||
# {{ trans('mail.hello') }} {{ $target->present()->fullName() }},
|
||||
|
||||
{{ trans('mail.new_item_checked') }}
|
||||
{{ $opening_line }}
|
||||
|
||||
@if (($snipeSettings->show_images_in_email =='1') && $item->getImageUrl())
|
||||
<center><img src="{{ $item->getImageUrl() }}" alt="Asset" style="max-width: 570px;"></center>
|
||||
|
|
88
tests/Unit/Mail/CheckoutAssetMailTest.php
Normal file
88
tests/Unit/Mail/CheckoutAssetMailTest.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Mail;
|
||||
|
||||
use App\Mail\CheckoutAssetMail;
|
||||
use App\Models\Asset;
|
||||
use App\Models\CheckoutAcceptance;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CheckoutAssetMailTest extends TestCase
|
||||
{
|
||||
public function testSubjectLine()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$actor = User::factory()->create();
|
||||
|
||||
$assetRequiringAcceptance = Asset::factory()->requiresAcceptance()->create();
|
||||
$assetNotRequiringAcceptance = Asset::factory()->doesNotRequireAcceptance()->create();
|
||||
|
||||
$acceptance = CheckoutAcceptance::factory()->for($assetRequiringAcceptance, 'checkoutable')->create();
|
||||
|
||||
(new CheckoutAssetMail(
|
||||
$assetRequiringAcceptance,
|
||||
$user,
|
||||
$actor,
|
||||
$acceptance,
|
||||
'A note goes here',
|
||||
true,
|
||||
))->assertHasSubject('Asset checked out');
|
||||
|
||||
(new CheckoutAssetMail(
|
||||
$assetNotRequiringAcceptance,
|
||||
$user,
|
||||
$actor,
|
||||
null,
|
||||
'A note goes here',
|
||||
true,
|
||||
))->assertHasSubject('Asset checked out');
|
||||
|
||||
(new CheckoutAssetMail(
|
||||
$assetRequiringAcceptance,
|
||||
$user,
|
||||
$actor,
|
||||
$acceptance,
|
||||
'A note goes here',
|
||||
false,
|
||||
))->assertHasSubject('Reminder: You have Unaccepted Assets.');
|
||||
}
|
||||
|
||||
public function testContent()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$actor = User::factory()->create();
|
||||
|
||||
$assetRequiringAcceptance = Asset::factory()->requiresAcceptance()->create();
|
||||
$assetNotRequiringAcceptance = Asset::factory()->doesNotRequireAcceptance()->create();
|
||||
|
||||
$acceptance = CheckoutAcceptance::factory()->for($assetRequiringAcceptance, 'checkoutable')->create();
|
||||
|
||||
(new CheckoutAssetMail(
|
||||
$assetRequiringAcceptance,
|
||||
$user,
|
||||
$actor,
|
||||
$acceptance,
|
||||
'A note goes here',
|
||||
true,
|
||||
))->assertSeeInText('A new item has been checked out under your name that requires acceptance, details are below.');
|
||||
|
||||
(new CheckoutAssetMail(
|
||||
$assetNotRequiringAcceptance,
|
||||
$user,
|
||||
$actor,
|
||||
null,
|
||||
'A note goes here',
|
||||
true,
|
||||
))->assertSeeInText('A new item has been checked out under your name, details are below.');
|
||||
|
||||
(new CheckoutAssetMail(
|
||||
$assetRequiringAcceptance,
|
||||
$user,
|
||||
$actor,
|
||||
$acceptance,
|
||||
'A note goes here',
|
||||
false,
|
||||
))->assertSeeInText('An item was recently checked out under your name that requires acceptance, details are below.');
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue