create(); // Should be refreshed (expires in 1 hour) $expiringSoon = SocialAccount::factory()->create([ 'workspace_id' => $workspace->id, 'platform' => Platform::LinkedIn, 'status' => Status::Connected, 'token_expires_at' => now()->addHour(), ]); // Should NOT be refreshed (expires in 5 hours) SocialAccount::factory()->create([ 'workspace_id' => $workspace->id, 'platform' => Platform::Instagram, 'status' => Status::Connected, 'token_expires_at' => now()->addHours(5), ]); // Should NOT be refreshed (already expired) SocialAccount::factory()->create([ 'workspace_id' => $workspace->id, 'platform' => Platform::TikTok, 'status' => Status::Connected, 'token_expires_at' => now()->subHour(), ]); // Should NOT be refreshed (disconnected) SocialAccount::factory()->create([ 'workspace_id' => $workspace->id, 'platform' => Platform::X, 'status' => Status::Disconnected, 'token_expires_at' => now()->addHour(), ]); $this->artisan('social:refresh-expiring-tokens') ->assertSuccessful(); Queue::assertPushed(RefreshSocialToken::class, 1); Queue::assertPushed(RefreshSocialToken::class, fn ($job) => $job->account->id === $expiringSoon->id); }); test('it dispatches nothing when no tokens are expiring', function () { Queue::fake(); $this->artisan('social:refresh-expiring-tokens') ->assertSuccessful(); Queue::assertNothingPushed(); });