Skip to content

A free open source IT asset/license management system

WIP: create mail class

Marcus Moore333501fe55ce
diff --git a/app/Mail/CheckoutAcceptanceResponseMail.php b/app/Mail/CheckoutAcceptanceResponseMail.php
new file mode 100644
index 0000000000..440f63467a
--- /dev/null
+++ b/app/Mail/CheckoutAcceptanceResponseMail.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Mail;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Mail\Mailable;
+use Illuminate\Mail\Mailables\Content;
+use Illuminate\Mail\Mailables\Envelope;
+use Illuminate\Queue\SerializesModels;
+
+class CheckoutAcceptanceResponseMail extends Mailable
+{
+ use Queueable, SerializesModels;
+
+ /**
+ * Create a new message instance.
+ */
+ public function __construct()
+ {
+ //
+ }
+
+ /**
+ * Get the message envelope.
+ */
+ public function envelope(): Envelope
+ {
+ return new Envelope(
+ subject: 'Checkout Acceptance Response Mail',
+ );
+ }
+
+ /**
+ * Get the message content definition.
+ */
+ public function content(): Content
+ {
+ return new Content(
+ markdown: 'mail.markdown.checkout-acceptance-response',
+ );
+ }
+
+ /**
+ * Get the attachments for the message.
+ *
+ * @return array<int, \Illuminate\Mail\Mailables\Attachment>
+ */
+ public function attachments(): array
+ {
+ return [];
+ }
+}
diff --git a/resources/views/mail/markdown/checkout-acceptance-response.blade.php b/resources/views/mail/markdown/checkout-acceptance-response.blade.php
new file mode 100644
index 0000000000..5fe2b643e2
--- /dev/null
+++ b/resources/views/mail/markdown/checkout-acceptance-response.blade.php
@@ -0,0 +1,8 @@
+@component('mail::message')
+# {{ trans('mail.hello') }} {{ $target->present()->fullName() }},
+
+{{ trans('mail.best_regards') }}
+
+{{ $snipeSettings->site_name }}
+
+@endcomponent
diff --git a/tests/Feature/Notifications/Email/CheckoutResponseEmailTest.php b/tests/Feature/Notifications/Email/CheckoutResponseEmailTest.php
index e6627b9225..cd40f55b18 100644
--- a/tests/Feature/Notifications/Email/CheckoutResponseEmailTest.php
+++ b/tests/Feature/Notifications/Email/CheckoutResponseEmailTest.php
@@ -2,20 +2,45 @@
namespace Tests\Feature\Notifications\Email;
+use App\Mail\CheckoutAcceptanceResponseMail;
+use App\Models\CheckoutAcceptance;
+use App\Models\User;
+use Illuminate\Support\Facades\Mail;
use Tests\TestCase;
class CheckoutResponseEmailTest extends TestCase
{
public static function scenarios()
{
- yield 'Accepting checkout acceptance configured to send alert';
- yield 'Declining checkout acceptance configured to send alert';
- yield 'Accepting checkout acceptance not configured to send alert';
- yield 'Declining checkout acceptance not configured to send alert';
+ yield 'Accepting checkout acceptance configured to send alert' => [];
+ yield 'Declining checkout acceptance configured to send alert' => [];
+ yield 'Accepting checkout acceptance not configured to send alert' => [];
+ yield 'Declining checkout acceptance not configured to send alert' => [];
}
public function test_checkout_response_alert()
{
$this->markTestIncomplete();
+
+ Mail::fake();
+
+ $user = User::factory()->create();
+
+ $checkoutAcceptance = CheckoutAcceptance::factory()
+ ->pending()
+ ->create([
+ 'alert_on_response_id' => $user->id,
+ ]);
+
+ $this->actingAs($checkoutAcceptance->assignedTo)
+ ->post(route('account.store-acceptance', $checkoutAcceptance), [
+ 'asset_acceptance' => 'accepted',
+ 'note' => null,
+ ]);
+
+ Mail::assertSent(CheckoutAcceptanceResponseMail::class, function ($mail) use ($user) {
+ // @todo: better assertions? accepted vs declined?
+ return $mail->hasTo($user->email);
+ });
}
}