Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

spatie/spatie.be

493 stars
1 code files
View spatie/spatie.be on GitHub

tests/Feature/GitHubAds/RandomizeAdOnGitHubRepositoriesJobTest.php

Open in GitHub
use App\Jobs\RandomizeAdsOnGitHubRepositoriesJob;
use App\Models\Ad;
use App\Models\Repository;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
 
class RandomizeAdOnGitHubRepositoriesJobTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
 
Storage::fake();
}
 
/** @test */
public function it_can_randomize_ads_on_GitHub_repositories()
{
Ad::factory()->count(10)->create();
 
$repositories = Repository::factory()->count(10)->create([
'ad_should_be_randomized' => true,
]);
 
dispatch(new RandomizeAdsOnGitHubRepositoriesJob());
 
$repositories->each(function (Repository $repository) {
$this->assertNotNull($repository->refresh()->ad);
 
Storage::disk('github_ads')->assertExists($repository->gitHubAdImagePath());
});
}
 
/** @test */
public function it_will_not_use_ads_that_are_not_active()
{
Ad::factory()->inactive()->count(10)->create();
 
$activeAd = Ad::factory()->active()->create();
$repositories = Repository::factory()->count(10)->create([
'ad_should_be_randomized' => true,
]);
 
dispatch(new RandomizeAdsOnGitHubRepositoriesJob());
 
$repositories->each(function (Repository $repository) use ($activeAd) {
$this->assertEquals($activeAd->id, $repository->refresh()->ad_id);
});
}
 
/** @test */
public function it_will_not_update_a_repository_whose_ad_should_not_be_randomized()
{
Ad::factory()->count(10)->create();
 
$repositories = Repository::factory()->count(10)->create([
'ad_should_be_randomized' => false,
]);
 
dispatch(new RandomizeAdsOnGitHubRepositoriesJob());
 
$repositories->each(function (Repository $repository) {
$this->assertNull($repository->refresh()->ad_id);
});
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.