Skip to content

Commit 7c1438c

Browse files
authored
Merge pull request #16446 from marcusmoore/feature/improve-checkout-asset-mail-wording
Improved wording in asset checkout emails
2 parents cc8c206 + af88ce5 commit 7c1438c

File tree

7 files changed

+131
-4
lines changed

7 files changed

+131
-4
lines changed

app/Mail/CheckoutAssetMail.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function content(): Content
7474
{
7575
$this->item->load('assetstatus');
7676
$eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : '';
77-
$req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
77+
$req_accept = $this->requiresAcceptance();
7878
$fields = [];
7979

8080
// Check if the item has custom fields associated with it
@@ -98,6 +98,7 @@ public function content(): Content
9898
'accept_url' => $accept_url,
9999
'last_checkout' => $this->last_checkout,
100100
'expected_checkin' => $this->expected_checkin,
101+
'introduction_line' => $this->introductionLine(),
101102
],
102103
);
103104
}
@@ -120,4 +121,27 @@ private function getSubject(): string
120121

121122
return trans('mail.unaccepted_asset_reminder');
122123
}
124+
125+
private function introductionLine(): string
126+
{
127+
if ($this->firstTimeSending && $this->requiresAcceptance()) {
128+
return trans('mail.new_item_checked_with_acceptance');
129+
}
130+
131+
if ($this->firstTimeSending && !$this->requiresAcceptance()) {
132+
return trans('mail.new_item_checked');
133+
}
134+
135+
if (!$this->firstTimeSending && $this->requiresAcceptance()) {
136+
return trans('mail.recent_item_checked');
137+
}
138+
139+
// we shouldn't get here but let's send a default message just in case
140+
return trans('new_item_checked');
141+
}
142+
143+
private function requiresAcceptance(): int|bool
144+
{
145+
return method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
146+
}
123147
}

database/factories/AssetFactory.php

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\Asset;
66
use App\Models\AssetModel;
7+
use App\Models\Category;
78
use App\Models\CustomField;
89
use App\Models\Location;
910
use App\Models\Statuslabel;
@@ -333,6 +334,15 @@ public function requiresAcceptance()
333334
});
334335
}
335336

337+
public function doesNotRequireAcceptance()
338+
{
339+
return $this->state(function () {
340+
return [
341+
'model_id' => AssetModel::factory()->doesNotRequireAcceptance(),
342+
];
343+
});
344+
}
345+
336346
public function deleted()
337347
{
338348
return $this->state(function () {

database/factories/AssetModelFactory.php

+9
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,13 @@ public function hasMultipleCustomFields(array $fields = null)
448448
];
449449
});
450450
}
451+
452+
public function doesNotRequireAcceptance()
453+
{
454+
return $this->state(function () {
455+
return [
456+
'category_id' => Category::factory()->doesNotRequireAcceptance(),
457+
];
458+
});
459+
}
451460
}

database/factories/CategoryFactory.php

+7
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,11 @@ public function forConsumables()
207207
'category_type' => 'consumable',
208208
]);
209209
}
210+
211+
public function doesNotRequireAcceptance()
212+
{
213+
return $this->state([
214+
'require_acceptance' => false,
215+
]);
216+
}
210217
}

resources/lang/en-US/mail.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
'min_QTY' => 'Min QTY',
6767
'name' => 'Name',
6868
'new_item_checked' => 'A new item has been checked out under your name, details are below.',
69+
'new_item_checked_with_acceptance' => 'A new item has been checked out under your name that requires acceptance, details are below.',
70+
'recent_item_checked' => 'An item was recently checked out under your name that requires acceptance, details are below.',
6971
'notes' => 'Notes',
7072
'password' => 'Password',
7173
'password_reset' => 'Password Reset',
@@ -88,7 +90,7 @@
8890
'upcoming-audits' => 'There is :count asset that is coming up for audit within :threshold days.|There are :count assets that are coming up for audit within :threshold days.',
8991
'user' => 'User',
9092
'username' => 'Username',
91-
'unaccepted_asset_reminder' => 'You have Unaccepted Assets.',
93+
'unaccepted_asset_reminder' => 'Reminder: You have Unaccepted Assets.',
9294
'welcome' => 'Welcome :name',
9395
'welcome_to' => 'Welcome to :web!',
9496
'your_assets' => 'View Your Assets',

resources/views/mail/markdown/checkout-asset.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@component('mail::message')
22
# {{ trans('mail.hello') }} {{ $target->present()->fullName() }},
33

4-
{{ trans('mail.new_item_checked') }}
4+
{{ $introduction_line }}
55

66
@if (($snipeSettings->show_images_in_email =='1') && $item->getImageUrl())
77
<center><img src="{{ $item->getImageUrl() }}" alt="Asset" style="max-width: 570px;"></center>
@@ -76,4 +76,4 @@
7676

7777
{{ $snipeSettings->site_name }}
7878

79-
@endcomponent
79+
@endcomponent
+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

Comments
 (0)