Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions src/Constraints/AfterConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool
: $schedule->timestamp_target->diffInHours(now()->floorSeconds()) > $schedule->toHours();
}

if (now()->floorSeconds()->lte($schedule->timestampTarget()->addMinutes($schedule->delay_minutes))) {
if (now()->floorSeconds()->lt($schedule->timestampTarget()->addMinutes($schedule->delay_minutes))) {
return false;
}

//till ends we should have at least toDays days
return $schedule->isOnce()
? $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->delay_minutes
: $schedule->timestamp_target->diffInHours(now()->floorSeconds()) > $schedule->delay_minutes;
? $schedule->timestamp_target->diffInMinutes(now()->floorSeconds()) >= $schedule->delay_minutes
: $schedule->timestamp_target->diffInMinutes(now()->floorSeconds()) > $schedule->delay_minutes;
}
}
45 changes: 45 additions & 0 deletions tests/Feature/AfterConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Binarcode\LaravelMailator\Models\MailatorSchedule;
use Binarcode\LaravelMailator\Tests\Fixtures\InvoiceReminderMailable;
use Binarcode\LaravelMailator\Tests\TestCase;
use Carbon\Carbon;
use Illuminate\Support\Facades\Mail;

class AfterConstraintTest extends TestCase
Expand Down Expand Up @@ -94,4 +95,48 @@ public function test_past_target_with_after_now_passed_after_constraint_hourly_b
$can
);
}

public function test_past_target_with_after_now_passed_after_constraint_minutes_bases()
{
Mail::fake();
Mail::assertNothingSent();

$scheduler = MailatorSchedule::init('reminder')
->recipients('zoo@bar.com')
->mailable(
(new InvoiceReminderMailable())->to('foo@bar.com')
)
->minutes(10)
->after(now());

$scheduler->save();

$this->travelTo(now()->addMinutes(5));

self::assertTrue(
$scheduler->fresh()->isFutureAction()
);

$this->travelTo(now()->addMinutes(5));

self::assertTrue(
app(AfterConstraint::class)
->canSend(
$scheduler,
$scheduler->logs
)
);

$this->travelTo(now()->addMinutes(5));

//as long as we have passed the "after" minutes target this should return true
self::assertTrue(
app(AfterConstraint::class)
->canSend(
$scheduler,
$scheduler->logs
)
);

}
}