diff --git a/src/Constraints/AfterConstraint.php b/src/Constraints/AfterConstraint.php index cafcc999fd95..8f02e33b41b4 100644 --- a/src/Constraints/AfterConstraint.php +++ b/src/Constraints/AfterConstraint.php @@ -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; } } diff --git a/tests/Feature/AfterConstraintTest.php b/tests/Feature/AfterConstraintTest.php index e91f42f75e34..9a70237761b3 100644 --- a/tests/Feature/AfterConstraintTest.php +++ b/tests/Feature/AfterConstraintTest.php @@ -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 @@ -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 + ) + ); + + } }