Skip to content

Commit

Permalink
Test mailable has valid content
Browse files Browse the repository at this point in the history
  • Loading branch information
unclexo committed Jan 6, 2023
1 parent 13e5edd commit 9693f2c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/Mail/PostPublished.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,7 +35,17 @@ public function __construct(Post $post)
public function envelope()
{
return new Envelope(
from: new Address('[email protected]', 'Medium Online Publication'),
to: new Address('[email protected]', 'Abu Jobaer'),
bcc: new Address('[email protected]', 'Ria Jobaer'),
replyTo: [
new Address('[email protected]', 'Taylor Otwell'),
],
subject: 'Post Published',
tags: ['architecture', 'design-patterns'],
metadata: [
'post_id' => $this->post->id,
],
);
}

Expand Down
30 changes: 30 additions & 0 deletions tests/Feature/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]');

$mailable->assertTo('[email protected]');

$mailable->assertHasBcc('[email protected]');

$mailable->assertHasReplyTo('[email protected]');

$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']);
}
}

0 comments on commit 9693f2c

Please sign in to comment.