Skip to content

2.0.0 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Dec 14, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tests
  • Loading branch information
marickvantuil committed Dec 11, 2017
commit 6711c93b81ee8d4cbda978ae71c10845606dfe16
38 changes: 38 additions & 0 deletions tests/SendEmailsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests;

use Buildcode\LaravelDatabaseEmails\Store;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
Expand Down Expand Up @@ -104,4 +105,41 @@ function an_email_should_never_be_sent_before_its_scheduled_date()
$this->assertEquals(1, $email->getAttempts());
$this->assertNotNull($email->getSendDate());
}

/** @test */
function emails_will_be_sent_until_max_try_count_has_been_reached()
{
Event::listen('before.send', function () {
throw new \Exception('Simulating some random error');
});

$this->sendEmail();
$this->assertCount(1, (new Store)->getQueue());
$this->artisan('email:send');
$this->assertCount(1, (new Store)->getQueue());
$this->artisan('email:send');
$this->assertCount(1, (new Store)->getQueue());
$this->artisan('email:send');
$this->assertCount(0, (new Store)->getQueue());
}

/** @test */
function the_failed_status_and_error_is_cleared_if_a_previously_failed_email_is_sent_succesfully()
{
$email = $this->sendEmail();

$email->update([
'failed' => true,
'error' => 'Simulating some random error',
'attempts' => 1,
]);

$this->assertTrue($email->fresh()->hasFailed());
$this->assertEquals('Simulating some random error', $email->fresh()->getError());

$this->artisan('email:send');

$this->assertFalse($email->fresh()->hasFailed());
$this->assertEmpty($email->fresh()->getError());
}
}