From 9693f2c6e2922838b58a4e524342d47008e626f9 Mon Sep 17 00:00:00 2001
From: unclexo <itsunclexo@gmail.com>
Date: Fri, 6 Jan 2023 21:06:04 +0600
Subject: [PATCH] Test mailable has valid content

---
 app/Mail/PostPublished.php | 11 +++++++++++
 tests/Feature/MailTest.php | 30 ++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/app/Mail/PostPublished.php b/app/Mail/PostPublished.php
index a0fd349..38a9618 100644
--- a/app/Mail/PostPublished.php
+++ b/app/Mail/PostPublished.php
@@ -6,6 +6,7 @@
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Mail\Mailable;
+use Illuminate\Mail\Mailables\Address;
 use Illuminate\Mail\Mailables\Content;
 use Illuminate\Mail\Mailables\Envelope;
 use Illuminate\Queue\SerializesModels;
@@ -34,7 +35,17 @@ public function __construct(Post $post)
     public function envelope()
     {
         return new Envelope(
+            from: new Address('medium@example.com', 'Medium Online Publication'),
+            to: new Address('unclexo@example.com', 'Abu Jobaer'),
+            bcc: new Address('ria@example.com', 'Ria Jobaer'),
+            replyTo: [
+                new Address('taylor@example.com', 'Taylor Otwell'),
+            ],
             subject: 'Post Published',
+            tags: ['architecture', 'design-patterns'],
+            metadata: [
+                'post_id' => $this->post->id,
+            ],
         );
     }
 
diff --git a/tests/Feature/MailTest.php b/tests/Feature/MailTest.php
index c80a3f0..ccc07e9 100644
--- a/tests/Feature/MailTest.php
+++ b/tests/Feature/MailTest.php
@@ -39,4 +39,34 @@ public function mailable_can_be_previewed()
         $this->get(route('mailable.preview', $post->id))
             ->assertStatus(200);
     }
+
+    /** @test */
+    public function mailable_has_valid_content()
+    {
+        $this->actingAs($user = User::factory()->create());
+
+        $post = Post::factory()->create(['user_id' => $user->id]);
+
+        $mailable = new PostPublished($post);
+
+        $mailable->assertFrom('medium@example.com');
+
+        $mailable->assertTo('unclexo@example.com');
+
+        $mailable->assertHasBcc('ria@example.com');
+
+        $mailable->assertHasReplyTo('taylor@example.com');
+
+        $mailable->assertHasSubject('Post Published');
+
+        $mailable->assertHasTag('design-patterns');
+
+        $mailable->assertHasMetadata('post_id', $post->id);
+
+        $mailable->assertSeeInHtml('Post Published');
+
+        $mailable->assertSeeInOrderInHtml(['View Post', 'Thanks']);
+
+        $mailable->assertSeeInOrderInText(['View Post', 'Thanks']);
+    }
 }