Don't block new post notifications by one paused during sending [MAILPOET-1609]

This commit is contained in:
wxa
2018-11-06 19:14:54 +03:00
parent c13974ad82
commit 2f202f6b3d
2 changed files with 43 additions and 3 deletions

View File

@ -94,6 +94,28 @@ class SchedulerTest extends \MailPoetTest {
expect(SendingQueue::findMany())->count(1);
}
function testItCreatesPostNotificationSendingTaskIfAPausedNotificationExists() {
$newsletter = $this->_createNewsletter();
$newsletter->schedule = '* 5 * * *';
// new queue record should be created
$queue_to_be_paused = Scheduler::createPostNotificationSendingTask($newsletter);
$queue_to_be_paused->task()->pause();
// another queue record should be created because the first one was paused
$newsletter->schedule = '* 10 * * *'; // different time to not clash with the first queue
$queue = Scheduler::createPostNotificationSendingTask($newsletter);
expect(SendingQueue::findMany())->count(2);
expect($queue->newsletter_id)->equals($newsletter->id);
expect($queue->status)->equals(SendingQueue::STATUS_SCHEDULED);
expect($queue->scheduled_at)->equals(Scheduler::getNextRunDate('* 10 * * *'));
expect($queue->priority)->equals(SendingQueue::PRIORITY_MEDIUM);
// duplicate queue record should not be created
Scheduler::createPostNotificationSendingTask($newsletter);
expect(SendingQueue::findMany())->count(2);
}
function testItDoesNotCreateDuplicateWelcomeNotificationSendingTasks() {
$newsletter = (object)array(
'id' => 1,
@ -728,6 +750,11 @@ class SchedulerTest extends \MailPoetTest {
$notification_history->parent_id = $newsletter->id;
$notification_history->save();
$sending_task = SendingTask::create();
$sending_task->newsletter_id = $notification_history->id;
$sending_task->status = SendingQueue::STATUS_SCHEDULED;
$sending_task->save();
$post_data = array(
'post_title' => 'title',
'post_status' => 'publish',