Adds published_at Data to Factories

This commit is contained in:
Refringe 2024-07-31 20:30:50 -04:00
parent f94204e978
commit 0776ee426f
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k
4 changed files with 13 additions and 8 deletions

View File

@ -5,6 +5,7 @@ namespace Database\Factories;
use App\Models\License;
use App\Models\Mod;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Random\RandomException;
@ -30,8 +31,9 @@ class ModFactory extends Factory
'featured' => fake()->boolean(),
'contains_ai_content' => fake()->boolean(),
'contains_ads' => fake()->boolean(),
'created_at' => now(),
'updated_at' => now(),
'published_at' => Carbon::now()->subDays(rand(0, 365))->subHours(rand(0, 23)),
'created_at' => Carbon::now()->subDays(rand(0, 365))->subHours(rand(0, 23)),
'updated_at' => Carbon::now()->subDays(rand(0, 365))->subHours(rand(0, 23)),
];
}

View File

@ -16,12 +16,13 @@ class ModVersionFactory extends Factory
{
return [
'mod_id' => Mod::factory(),
'version' => fake()->numerify('1.#.#'),
'version' => fake()->numerify('#.#.#'),
'description' => fake()->text(),
'link' => fake()->url(),
'spt_version_id' => SptVersion::factory(),
'virus_total_link' => fake()->url(),
'downloads' => fake()->randomNumber(),
'published_at' => Carbon::now()->subDays(rand(0, 365))->subHours(rand(0, 23)),
'created_at' => Carbon::now()->subDays(rand(0, 365))->subHours(rand(0, 23)),
'updated_at' => Carbon::now()->subDays(rand(0, 365))->subHours(rand(0, 23)),
];

View File

@ -3,6 +3,9 @@
use App\Models\Mod;
use App\Models\ModDependency;
use App\Models\ModVersion;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('resolves mod version dependency when mod version is created', function () {
$modA = Mod::factory()->create(['name' => 'Mod A']);

View File

@ -18,15 +18,14 @@ it('includes only published mod versions', function () {
]);
$all = ModVersion::withoutGlobalScopes()->get();
expect($all)->toHaveCount(3);
$mods = ModVersion::all();
expect($mods)->toHaveCount(1);
expect($mods->contains($publishedMod))->toBeTrue();
expect($mods->contains($unpublishedMod))->toBeFalse();
expect($mods->contains($noPublishedDateMod))->toBeFalse();
expect($mods)->toHaveCount(1)
->and($mods->contains($publishedMod))->toBeTrue()
->and($mods->contains($unpublishedMod))->toBeFalse()
->and($mods->contains($noPublishedDateMod))->toBeFalse();
});
it('handles null published_at as not published', function () {