release/v1.4.1 #154
1 changed files with 55 additions and 0 deletions
|
|
@ -23,6 +23,7 @@
|
|||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
|
@ -35,6 +36,11 @@ class PublishNextArticleJobTest extends TestCase
|
|||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// The daily cap counts from startOfDay, so tests placing publications a
|
||||
// couple of hours back land on the previous day when run after midnight.
|
||||
Carbon::setTestNow('2026-07-15 12:00:00');
|
||||
|
||||
$this->notificationService = new NotificationService;
|
||||
}
|
||||
|
||||
|
|
@ -319,6 +325,54 @@ public function test_daily_cap_counts_each_channel_publication_separately(): voi
|
|||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function test_daily_cap_counts_from_midnight_not_a_rolling_window(): void
|
||||
{
|
||||
Carbon::setTestNow('2026-07-15 01:00:00');
|
||||
|
||||
$this->createApprovedRouteArticle();
|
||||
|
||||
ArticlePublication::factory()->count(3)->create(['published_at' => Carbon::parse('2026-07-14 23:00:00')]);
|
||||
Setting::setArticlePublishingInterval(0);
|
||||
Setting::setDailyPublishCap(3);
|
||||
|
||||
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||
$articleFetcherMock->shouldReceive('execute')
|
||||
->once()
|
||||
->andReturn(['title' => 'Test Article', 'description' => 'Test description']);
|
||||
|
||||
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
||||
$publishingServiceMock->shouldReceive('publishRouteArticle')
|
||||
->once()
|
||||
->andReturn(PublishOutcome::published($this->makePublication()));
|
||||
|
||||
$job = new PublishNextArticleJob;
|
||||
$job->handle(new PublishRouteArticleAction($articleFetcherMock, $publishingServiceMock, $this->notificationService));
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function test_daily_cap_counts_a_publication_just_after_midnight(): void
|
||||
{
|
||||
Carbon::setTestNow('2026-07-15 01:00:00');
|
||||
|
||||
$this->createApprovedRouteArticle();
|
||||
|
||||
ArticlePublication::factory()->count(3)->create(['published_at' => Carbon::parse('2026-07-15 00:30:00')]);
|
||||
Setting::setArticlePublishingInterval(0);
|
||||
Setting::setDailyPublishCap(3);
|
||||
|
||||
$articleFetcherMock = Mockery::mock(FetchArticleDataAction::class);
|
||||
$publishingServiceMock = Mockery::mock(ArticlePublishingService::class);
|
||||
|
||||
$articleFetcherMock->shouldNotReceive('execute');
|
||||
$publishingServiceMock->shouldNotReceive('publishRouteArticle');
|
||||
|
||||
$job = new PublishNextArticleJob;
|
||||
$job->handle(new PublishRouteArticleAction($articleFetcherMock, $publishingServiceMock, $this->notificationService));
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function test_handle_ignores_publications_from_previous_days(): void
|
||||
{
|
||||
$this->createApprovedRouteArticle();
|
||||
|
|
@ -572,6 +626,7 @@ public function test_job_can_be_serialized(): void
|
|||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Carbon::setTestNow();
|
||||
Mockery::close();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue