Skip to content

Commit 6711c93

Browse files
committed
tests
1 parent 83b94c6 commit 6711c93

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/SendEmailsCommandTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tests;
44

5+
use Buildcode\LaravelDatabaseEmails\Store;
56
use Carbon\Carbon;
67
use Illuminate\Support\Facades\DB;
78
use Illuminate\Support\Facades\Event;
@@ -104,4 +105,41 @@ function an_email_should_never_be_sent_before_its_scheduled_date()
104105
$this->assertEquals(1, $email->getAttempts());
105106
$this->assertNotNull($email->getSendDate());
106107
}
108+
109+
/** @test */
110+
function emails_will_be_sent_until_max_try_count_has_been_reached()
111+
{
112+
Event::listen('before.send', function () {
113+
throw new \Exception('Simulating some random error');
114+
});
115+
116+
$this->sendEmail();
117+
$this->assertCount(1, (new Store)->getQueue());
118+
$this->artisan('email:send');
119+
$this->assertCount(1, (new Store)->getQueue());
120+
$this->artisan('email:send');
121+
$this->assertCount(1, (new Store)->getQueue());
122+
$this->artisan('email:send');
123+
$this->assertCount(0, (new Store)->getQueue());
124+
}
125+
126+
/** @test */
127+
function the_failed_status_and_error_is_cleared_if_a_previously_failed_email_is_sent_succesfully()
128+
{
129+
$email = $this->sendEmail();
130+
131+
$email->update([
132+
'failed' => true,
133+
'error' => 'Simulating some random error',
134+
'attempts' => 1,
135+
]);
136+
137+
$this->assertTrue($email->fresh()->hasFailed());
138+
$this->assertEquals('Simulating some random error', $email->fresh()->getError());
139+
140+
$this->artisan('email:send');
141+
142+
$this->assertFalse($email->fresh()->hasFailed());
143+
$this->assertEmpty($email->fresh()->getError());
144+
}
107145
}

0 commit comments

Comments
 (0)