|
2 | 2 |
|
3 | 3 | namespace Tests; |
4 | 4 |
|
| 5 | +use Buildcode\LaravelDatabaseEmails\Store; |
5 | 6 | use Carbon\Carbon; |
6 | 7 | use Illuminate\Support\Facades\DB; |
7 | 8 | use Illuminate\Support\Facades\Event; |
@@ -104,4 +105,41 @@ function an_email_should_never_be_sent_before_its_scheduled_date() |
104 | 105 | $this->assertEquals(1, $email->getAttempts()); |
105 | 106 | $this->assertNotNull($email->getSendDate()); |
106 | 107 | } |
| 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 | + } |
107 | 145 | } |
0 commit comments