feat: ship creator journey v2 and profile updates
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Models\User;
|
||||
use App\Services\CollectionService;
|
||||
use App\Services\SmartCollectionService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class);
|
||||
@@ -74,6 +75,98 @@ it('keeps artworks_count in sync while attaching and removing artworks', functio
|
||||
expect($collection->artworks()->pluck('artworks.id')->all())->toBe([$artworkB->id]);
|
||||
});
|
||||
|
||||
it('sorts manual collection artworks by stats views for popular mode', function (): void {
|
||||
$user = User::factory()->create();
|
||||
$collection = Collection::factory()->for($user)->create([
|
||||
'sort_mode' => Collection::SORT_POPULAR,
|
||||
]);
|
||||
$lowViews = Artwork::factory()->for($user)->create();
|
||||
$highViews = Artwork::factory()->for($user)->create();
|
||||
$noStats = Artwork::factory()->for($user)->create();
|
||||
$service = app(CollectionService::class);
|
||||
|
||||
$service->attachArtworks($collection, $user, [$lowViews->id, $noStats->id, $highViews->id]);
|
||||
|
||||
DB::table('artwork_stats')->insert([
|
||||
[
|
||||
'artwork_id' => $lowViews->id,
|
||||
'views' => 25,
|
||||
'downloads' => 0,
|
||||
'favorites' => 0,
|
||||
'rating_avg' => 0,
|
||||
'rating_count' => 0,
|
||||
],
|
||||
[
|
||||
'artwork_id' => $highViews->id,
|
||||
'views' => 250,
|
||||
'downloads' => 0,
|
||||
'favorites' => 0,
|
||||
'rating_avg' => 0,
|
||||
'rating_count' => 0,
|
||||
],
|
||||
]);
|
||||
|
||||
$artworks = $service->getCollectionDetailArtworks($collection->fresh(), true, 24);
|
||||
|
||||
expect($artworks->getCollection()->pluck('id')->all())->toBe([
|
||||
$highViews->id,
|
||||
$lowViews->id,
|
||||
$noStats->id,
|
||||
]);
|
||||
});
|
||||
|
||||
it('sorts smart collection artworks by stats views for popular mode', function (): void {
|
||||
$user = User::factory()->create();
|
||||
$collection = Collection::factory()->for($user)->create([
|
||||
'mode' => Collection::MODE_SMART,
|
||||
'smart_rules_json' => [
|
||||
'match' => 'all',
|
||||
'sort' => Collection::SORT_POPULAR,
|
||||
'rules' => [
|
||||
[
|
||||
'field' => 'created_at',
|
||||
'operator' => 'between',
|
||||
'value' => [
|
||||
'from' => now()->subDay()->toDateString(),
|
||||
'to' => now()->addDay()->toDateString(),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
$lowViews = Artwork::factory()->for($user)->create();
|
||||
$highViews = Artwork::factory()->for($user)->create();
|
||||
$noStats = Artwork::factory()->for($user)->create();
|
||||
$service = app(SmartCollectionService::class);
|
||||
|
||||
DB::table('artwork_stats')->insert([
|
||||
[
|
||||
'artwork_id' => $lowViews->id,
|
||||
'views' => 12,
|
||||
'downloads' => 0,
|
||||
'favorites' => 0,
|
||||
'rating_avg' => 0,
|
||||
'rating_count' => 0,
|
||||
],
|
||||
[
|
||||
'artwork_id' => $highViews->id,
|
||||
'views' => 120,
|
||||
'downloads' => 0,
|
||||
'favorites' => 0,
|
||||
'rating_avg' => 0,
|
||||
'rating_count' => 0,
|
||||
],
|
||||
]);
|
||||
|
||||
$artworks = $service->resolveArtworks($collection, true, 24);
|
||||
|
||||
expect($artworks->getCollection()->pluck('id')->all())->toBe([
|
||||
$highViews->id,
|
||||
$lowViews->id,
|
||||
$noStats->id,
|
||||
]);
|
||||
});
|
||||
|
||||
it('builds a human readable smart summary for medium rules', function (): void {
|
||||
$service = app(SmartCollectionService::class);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user