Save workspace changes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Artwork;
|
||||
use App\Http\Controllers\Web\DiscoverController;
|
||||
use App\Services\ArtworkService;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
@@ -12,6 +13,9 @@ beforeEach(function () {
|
||||
$this->artworksMock->shouldReceive('getLatestArtworks')
|
||||
->andReturn(collect())
|
||||
->byDefault();
|
||||
$this->artworksMock->shouldReceive('getFeaturedArtworkWinner')
|
||||
->andReturn(null)
|
||||
->byDefault();
|
||||
$this->app->instance(ArtworkService::class, $this->artworksMock);
|
||||
});
|
||||
|
||||
@@ -37,6 +41,80 @@ it('GET /discover/trending still returns 200', function () {
|
||||
->assertStatus(200);
|
||||
});
|
||||
|
||||
it('drops stale private artworks during discover search hydration', function () {
|
||||
$visibleArtwork = Artwork::withoutEvents(fn () => Artwork::factory()->create([
|
||||
'title' => 'Visible Trending Artwork',
|
||||
'is_public' => true,
|
||||
'visibility' => Artwork::VISIBILITY_PUBLIC,
|
||||
'is_approved' => true,
|
||||
'published_at' => now()->subHour(),
|
||||
]));
|
||||
|
||||
$privateArtwork = Artwork::withoutEvents(fn () => Artwork::factory()->create([
|
||||
'title' => 'Private Trending Artwork',
|
||||
'is_public' => true,
|
||||
'visibility' => Artwork::VISIBILITY_PRIVATE,
|
||||
'is_approved' => true,
|
||||
'published_at' => now()->subHour(),
|
||||
]));
|
||||
|
||||
$controller = app(DiscoverController::class);
|
||||
$method = new ReflectionMethod($controller, 'hydrateDiscoverSearchResults');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$paginator = new LengthAwarePaginator(
|
||||
collect([
|
||||
(object) ['id' => $visibleArtwork->id, 'title' => $visibleArtwork->title],
|
||||
(object) ['id' => $privateArtwork->id, 'title' => $privateArtwork->title],
|
||||
]),
|
||||
2,
|
||||
24,
|
||||
1
|
||||
);
|
||||
|
||||
$method->invoke($controller, $paginator);
|
||||
|
||||
expect($paginator->getCollection()->pluck('id')->all())->toBe([$visibleArtwork->id]);
|
||||
expect($paginator->getCollection()->pluck('name')->all())->toBe(['Visible Trending Artwork']);
|
||||
});
|
||||
|
||||
it('excludes private and unpublished artworks from trending database fallback', function () {
|
||||
$visibleArtwork = Artwork::withoutEvents(fn () => Artwork::factory()->create([
|
||||
'title' => 'Visible Fallback Artwork',
|
||||
'is_public' => true,
|
||||
'visibility' => Artwork::VISIBILITY_PUBLIC,
|
||||
'is_approved' => true,
|
||||
'published_at' => now()->subHours(2),
|
||||
]));
|
||||
|
||||
$privateArtwork = Artwork::withoutEvents(fn () => Artwork::factory()->create([
|
||||
'title' => 'Private Fallback Artwork',
|
||||
'is_public' => true,
|
||||
'visibility' => Artwork::VISIBILITY_PRIVATE,
|
||||
'is_approved' => true,
|
||||
'published_at' => now()->subHours(2),
|
||||
]));
|
||||
|
||||
$scheduledArtwork = Artwork::withoutEvents(fn () => Artwork::factory()->create([
|
||||
'title' => 'Scheduled Fallback Artwork',
|
||||
'is_public' => true,
|
||||
'visibility' => Artwork::VISIBILITY_PUBLIC,
|
||||
'is_approved' => true,
|
||||
'published_at' => now()->addDay(),
|
||||
]));
|
||||
|
||||
$controller = app(DiscoverController::class);
|
||||
$method = new ReflectionMethod($controller, 'fallbackTrendingFromDatabase');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$paginator = $method->invoke($controller, 24, 30);
|
||||
$ids = $paginator->getCollection()->pluck('id')->all();
|
||||
|
||||
expect($ids)->toContain($visibleArtwork->id);
|
||||
expect($ids)->not->toContain($privateArtwork->id);
|
||||
expect($ids)->not->toContain($scheduledArtwork->id);
|
||||
});
|
||||
|
||||
it('home page still renders with rising section data', function () {
|
||||
$this->get('/')
|
||||
->assertStatus(200);
|
||||
|
||||
Reference in New Issue
Block a user